<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright 2023 Rahmi Ege Karaosmanoglu

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>io.camelbee</groupId>
        <artifactId>camelbee</artifactId>
        <version>3.0.2</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>parent</artifactId>
    <packaging>pom</packaging>

    <name>CamelBee :: Parent</name>
    <description>CamelBee Root Pom</description>

    <properties>
        <argLine>-Duser.language=en</argLine>
        <build-helper-maven-plugin.version>3.6.1</build-helper-maven-plugin.version>
        <camel-maven-plugin.version>4.16.0</camel-maven-plugin.version>
        <checkstyle.version>13.0.0</checkstyle.version>
        <commons-io.version>2.21.0</commons-io.version>
        <commons-lang3.version>3.20.0</commons-lang3.version>
        <cxf-core.version>4.1.4</cxf-core.version>
        <cxf-codegen-plugin.version>4.0.5</cxf-codegen-plugin.version>
        <cxf-xjc-plugin.version>4.0.2</cxf-xjc-plugin.version>
        <cxf-xjc-dv.version>4.0.2</cxf-xjc-dv.version>
        <dependency-lock-maven-plugin.version>1.0.2</dependency-lock-maven-plugin.version>
        <formatter-maven-plugin.version>2.29.0</formatter-maven-plugin.version>
        <impsort-maven-plugin.version>1.13.0</impsort-maven-plugin.version>
        <jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>
        <jackson-databind-nullable.version>0.2.8</jackson-databind-nullable.version>
        <java.version>21</java.version>
        <lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
        <lombok.version>1.18.42</lombok.version>
        <mapstruct.version>1.6.3</mapstruct.version>
        <maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
        <maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
        <maven-dependency-plugin.version>3.9.0</maven-dependency-plugin.version>
        <maven-failsafe-plugin.version>3.5.4</maven-failsafe-plugin.version>
        <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
        <maven-jxr-plugin.version>3.6.0</maven-jxr-plugin.version>
      
        <maven-pmd-plugin.version>3.28.0</maven-pmd-plugin.version>
        <maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
        <maven-surefire-report-plugin.version>3.5.4</maven-surefire-report-plugin.version>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>

        <maven.compiler.testSource>${maven.compiler.source}</maven.compiler.testSource>
        <maven.compiler.testTarget>${maven.compiler.target}</maven.compiler.testTarget>

        <openapi-generator-maven-plugin.version>7.1.0</openapi-generator-maven-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <skipSurefireReport>true</skipSurefireReport>
        <sonar-maven-plugin.version>5.5.0.6356</sonar-maven-plugin.version>
        <sonar.coverage.exclusions>**/*Test*.*, **/*Config*.*</sonar.coverage.exclusions>
        <sonar.projectKey>camelbee.${project.name}</sonar.projectKey>
        <sonar.qualitygate.wait>true</sonar.qualitygate.wait>
        <spotbugs-annotations.version>4.9.8</spotbugs-annotations.version>
        <spotbugs-maven-plugin.version>4.9.8.2</spotbugs-maven-plugin.version>
        <spotbugs.version>4.9.8</spotbugs.version>

        <testcontainers-bom.version>2.0.3</testcontainers-bom.version>
        <junit-jupiter.version>1.21.4</junit-jupiter.version>
        <snakeyaml.version>2.5</snakeyaml.version>
        <wiremock.version>3.13.2</wiremock.version>
        <nimbus-jose-jwt.version>10.7</nimbus-jose-jwt.version>
        <os-maven-plugin.version>1.7.1</os-maven-plugin.version>
        <cxf-xjc-runtime.version>4.1.2</cxf-xjc-runtime.version>
        <cxf-xjc-ts.version>4.1.2</cxf-xjc-ts.version>
        <saaj-impl.version>3.0.4</saaj-impl.version>
        <avro-maven-plugin.version>1.12.0</avro-maven-plugin.version>
        <maven-replacer-plugin.version>1.5.3</maven-replacer-plugin.version>
        <jakarta.xml.ws-api.version>4.0.2</jakarta.xml.ws-api.version>
        <swagger-annotations-jakarta.version>2.2.42</swagger-annotations-jakarta.version>
        <javax.annotation-api.version>1.3.2</javax.annotation-api.version>

        <!-- ================================================================ -->
        <!-- Protocol Buffers & gRPC Version Alignment - CRITICAL             -->
        <!-- ================================================================ -->
        <!--
          WARNING: When upgrading Quarkus/Spring Boot/Camel, verify protobuf/gRPC
          version alignment to avoid native compilation failures.

          REQUIREMENTS:
          - protoc compiler version MUST match protobuf-java runtime exactly
          - All protobuf-java* artifacts MUST use the same version
          - proto-google-common-protos MUST be compatible with protobuf runtime

          BEFORE UPGRADING: mvn dependency:tree | grep -E "protobuf|grpc"

          CURRENT WORKING VERSIONS:
          - protobuf: 4.32.1 ↔ proto-google-common-protos: 2.63.2 ↔ grpc: 1.76.0 ✓

          Common native-mode failures if misaligned:
          - "Generated message class missing method getCtype()"
          - "Detected incompatible Protobuf Gencode/Runtime versions"

          Dependencies that may conflict: tink, camel-grpc, quarkus-grpc, Google Cloud libs
          → Use <dependencyManagement> to enforce versions
        -->
        <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
        <proto-google-common-protos.version>2.63.2</proto-google-common-protos.version>
        <protoc.version>3.25.8</protoc.version>
        <protoc-gen-grpc-java.version>1.78.0</protoc-gen-grpc-java.version>
        <!-- ================================================================ -->
    </properties>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.testcontainers</groupId>
                <artifactId>testcontainers-bom</artifactId>
                <version>${testcontainers-bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
              <groupId>org.testcontainers</groupId>
              <artifactId>junit-jupiter</artifactId>
              <version>${junit-jupiter.version}</version>
            </dependency>

            <dependency>
                <groupId>org.wiremock</groupId>
                <artifactId>wiremock</artifactId>
                <version>${wiremock.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf.xjc-utils</groupId>
                <artifactId>cxf-xjc-runtime</artifactId>
                <version>${cxf-xjc-runtime.version}</version>
            </dependency>

            <dependency>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>${os-maven-plugin.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf.xjcplugins</groupId>
                <artifactId>cxf-xjc-ts</artifactId>
                <version>${cxf-xjc-ts.version}</version>
            </dependency>

            <dependency>
                <groupId>com.sun.xml.messaging.saaj</groupId>
                <artifactId>saaj-impl</artifactId>
                <version>${saaj-impl.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-maven-plugin</artifactId>
                <version>${avro-maven-plugin.version}</version>
            </dependency>

            <dependency>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>${maven-replacer-plugin.version}</version>
            </dependency>

            <!--
              Using the org.xolstice protobuf-maven-plugin as it is the de-facto standard,
              widely adopted, and battle-tested in production builds.
              Chosen over io.github.ascopes as it has broader ecosystem adoption.
            -->
            <dependency>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>${protobuf-maven-plugin.version}</version>
            </dependency>

            <dependency>
                <groupId>jakarta.xml.ws</groupId>
                <artifactId>jakarta.xml.ws-api</artifactId>
                <version>${jakarta.xml.ws-api.version}</version>
            </dependency>

            <dependency>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-annotations-jakarta</artifactId>
                <version>${swagger-annotations-jakarta.version}</version>
            </dependency>

            <dependency>
              <groupId>javax.annotation</groupId>
              <artifactId>javax.annotation-api</artifactId>
              <version>${javax.annotation-api.version}</version>
            </dependency>

            <dependency>
              <groupId>com.google.api.grpc</groupId>
              <artifactId>proto-google-common-protos</artifactId>
              <version>${proto-google-common-protos.version}</version>
            </dependency>


        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-core</artifactId>
            <version>${cxf-core.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-annotations</artifactId>
            <version>${spotbugs-annotations.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${mapstruct.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>jackson-databind-nullable</artifactId>
            <version>${jackson-databind-nullable.version}</version>
        </dependency>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>${snakeyaml.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${maven-dependency-plugin.version}</version>
                <executions>
                    <execution>
                        <id>unpack-common-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>io.camelbee</groupId>
                                    <artifactId>common</artifactId>
                                    <version>3.0.2</version>
                                    <type>jar</type>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <includes>config/**, formatter/**</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>dependency-list</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>list</goal>
                        </goals>
                        <configuration>
                            <outputFile>dependencies.list</outputFile>
                            <sort>true</sort>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>net.revelc.code</groupId>
                <artifactId>impsort-maven-plugin</artifactId>
                <version>${impsort-maven-plugin.version}</version>
                <configuration>
                    <removeUnused>true</removeUnused>
                    <compliance>21</compliance>
                    <directories>src</directories>
                    <includes>**/*.java</includes>
                </configuration>
                <executions>
                    <execution>
                        <id>sort-imports</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>sort</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>net.revelc.code.formatter</groupId>
                <artifactId>formatter-maven-plugin</artifactId>
                <version>${formatter-maven-plugin.version}</version>
                <configuration>
                    <configFile>${project.build.directory}/formatter/eclipse-java-google-style.xml</configFile>
                    <directories>src</directories>
                    <includes>**/*.java</includes>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <id>formatter</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>format</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>${camel-maven-plugin.version}</version>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <annotationProcessorPaths>
                        <!-- mapstruct annotation processor -->
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                        <!-- lombok annotation processor -->
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <!-- lombok mapstruct binding -->
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>${lombok-mapstruct-binding.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <showDeprecation>false</showDeprecation>
                    <showWarnings>false</showWarnings>
                    <compilerArgs>
                        <arg>-Xlint:unchecked</arg>
                    </compilerArgs>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>${build-helper-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/openapi/src/main/java</source>
                                <source>${project.build.directory}/generated-sources/cxf</source>
                                <source>${project.build.directory}/generated-sources/proto</source>
                                <source>${project.build.directory}/generated-sources/xml</source>
                                <source>${project.build.directory}/generated-sources/avro</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-integration-test-source</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/integration-test/java</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-integration-test-resource</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>add-test-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>src/integration-test/resources</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <excludes>
                        <exclude>**/*IntegrationTest.java</exclude>
                    </excludes>
                    <systemPropertyVariables>
                        <CamelTestRouteCoverage>true</CamelTestRouteCoverage>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven-failsafe-plugin.version}</version>
                <configuration>
                    <includes>
                        <include>**/*IntegrationTest.java</include>
                    </includes>
                    <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <configuration>
                    <excludes>
                        <exclude>**/exception/*</exclude>
                        <exclude>**/*Config.*</exclude>
                        <exclude>**/*Test.*</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report-vsts</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <phase>test</phase>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>${maven-jxr-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>${maven-surefire-report-plugin.version}</version>
                <configuration>
                    <skipSurefireReport>${skipSurefireReport}</skipSurefireReport>
                    <reportsDirectories>
                        <reportsDirectory>${project.build.directory}/failsafe-reports</reportsDirectory>
                    </reportsDirectories>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

    <profiles>
        <profile>
            <id>quality</id>
            <build>
                <plugins>

                    <!-- ✅ Checkstyle -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>${maven-checkstyle-plugin.version}</version>
                        <dependencies>
                            <dependency>
                                <groupId>com.puppycrawl.tools</groupId>
                                <artifactId>checkstyle</artifactId>
                                <version>${checkstyle.version}</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <excludeGeneratedSources>true</excludeGeneratedSources>
                            <excludes>${project.build.directory}/generated-sources/**/*</excludes>
                            <configLocation>${project.build.directory}/config/checkstyle/google-checks.xml</configLocation>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>true</failsOnError>
                            <linkXRef>false</linkXRef>
                        </configuration>
                        <executions>
                            <execution>
                                <id>checkstyle</id>
                                <phase>verify</phase> <!-- Back to verify phase -->
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- ✅ PMD -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>${maven-pmd-plugin.version}</version>
                        <configuration>
                            <targetJdk>21</targetJdk>
                            <linkXRef>false</linkXRef>
                            <printFailingErrors>true</printFailingErrors>
                            <excludeRoots>
                                <excludeRoot>${project.build.directory}/generated-sources</excludeRoot>
                            </excludeRoots>
                        </configuration>
                        <executions>
                            <execution>
                                <id>pmd-verify</id>
                                <phase>verify</phase> <!-- Back to verify phase -->
                                <goals>
                                    <goal>check</goal>
                                    <goal>cpd-check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- ✅ SpotBugs -->
                    <plugin>
                        <groupId>com.github.spotbugs</groupId>
                        <artifactId>spotbugs-maven-plugin</artifactId>
                        <version>${spotbugs-maven-plugin.version}</version>
                        <configuration>
                            <excludeFilterFile>${project.build.directory}/config/spotbugs/exclude.xml</excludeFilterFile>
                            <effort>Max</effort>
                            <threshold>Medium</threshold>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>com.github.spotbugs</groupId>
                                <artifactId>spotbugs</artifactId>
                                <version>${spotbugs.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>spotbugs-verify</id>
                                <phase>verify</phase> <!-- Back to verify phase -->
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- ✅ SonarQube -->
                    <plugin>
                      <groupId>org.sonarsource.scanner.maven</groupId>
                      <artifactId>sonar-maven-plugin</artifactId>
                      <version>${sonar-maven-plugin.version}</version>
                    </plugin>

                </plugins>
            </build>
        </profile>
    </profiles>

</project>
