<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>dev.openfeature.contrib</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0</version> <!--x-release-please-version -->
    <packaging>pom</packaging>

    <name>java-sdk-contrib</name>
    <description>Contrib parent</description>
    <url>https://openfeature.dev</url>

    <developers>
        <developer>
            <id>toddbaert</id>
            <name>Todd Baert</name>
            <organization>OpenFeature</organization>
            <url>https://openfeature.dev/</url>
        </developer>
    </developers>
    <licenses>
        <license>
            <name>Apache License 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0</url>
        </license>
    </licenses>

    <modules>
        <module>hooks/open-telemetry</module>
        <module>tools/junit-openfeature</module>
        <module>providers/flagd</module>
        <module>providers/flagsmith</module>
        <module>providers/go-feature-flag</module>
        <module>providers/jsonlogic-eval-provider</module>
        <module>providers/env-var</module>
        <module>providers/unleash</module>
        <module>providers/flipt</module>
        <module>providers/configcat</module>
        <module>providers/statsig</module>
        <module>providers/multiprovider</module>
        <module>tools/flagd-http-connector</module>
    </modules>

    <scm>
        <connection>scm:git:https://github.com/open-feature/java-sdk-contrib.git</connection>
        <developerConnection>scm:git:https://github.com/open-feature/java-sdk-contrib.git</developerConnection>
        <url>https://github.com/open-feature/java-sdk-contrib</url>
    </scm>

    <properties>
        <toolchain.jdk.version>[21,)</toolchain.jdk.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <module-name>${groupId}.${artifactId}</module-name>
        <javadoc.failOnWarnings>true</javadoc.failOnWarnings>
        <!--  This is required for later correct replacement of surefireArgLine -->
        <!-- see surefire-java8 and surefire-java9+ profiles -->
        <surefireArgLine>
            --add-opens java.base/java.util=ALL-UNNAMED
            --add-opens java.base/java.lang=ALL-UNNAMED
        </surefireArgLine>
        <skip.tests>false</skip.tests>
        <!-- this will throw an error if we use APIs not available in the specified version -->
        <maven.compiler.release>11</maven.compiler.release>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.13.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-bom</artifactId>
                <version>7.23.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-bom</artifactId>
                <version>5.18.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <!-- provided -->
            <!-- this can be overriden in child POMs to support specific SDK requirements -->
            <groupId>dev.openfeature</groupId>
            <artifactId>sdk</artifactId>
            <!-- 1.16.0 <= v < 2.0 (excluding 2.0 pre-releases)-->
            <version>[1.16.0,1.99999)</version>
            <!-- use the version provided at runtime -->
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.38</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <!-- used so that lombok can generate suppressions for spotbugs. It needs to find it on the relevant classpath -->
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs</artifactId>
            <version>4.8.6</version>
            <scope>provided</scope>
        </dependency>

        <!-- end provided -->

        <!-- test -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.27.3</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit-pioneer</groupId>
            <artifactId>junit-pioneer</artifactId>
            <version>2.3.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>
        <!-- end test -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-toolchains-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>select-jdk-toolchain</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.14.0</version>
            </plugin>

            <!-- automatically derive a module name from the groupId and artifactId -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.4.2</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Automatic-Module-Name>${module-name}</Automatic-Module-Name>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <excludes>
                        <!-- tests to exclude -->
                        <exclude>${testExclusions}</exclude>
                    </excludes>
                    <argLine>
                        @{surefireArgLine}
                    </argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>deploy</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.proc>full</maven.compiler.proc>
            </properties>
            <build>
                <plugins>

                    <!-- skips deployment of submodule artifact if already in repo -->
                    <plugin>
                        <groupId>org.honton.chas</groupId>
                        <artifactId>exists-maven-plugin</artifactId>
                        <version>0.15.0</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>remote</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <skip>${maven.deploy.skip}</skip>
                            <repository>https://repo1.maven.org/maven2</repository>
                            <snapshotRepository>https://central.sonatype.com/repository/maven-snapshots</snapshotRepository>
                            <snapshotServerId>central</snapshotServerId>
                        </configuration>
                    </plugin>

                    <!-- Begin source & javadocs being generated -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.11.2</version>
                        <configuration>
                            <failOnWarnings>${javadoc.failOnWarnings}</failOnWarnings>
                            <sourceFileExcludes>
                                <sourceFileExclude>**/GoFeatureFlagProviderOptions.java</sourceFileExclude>
                            </sourceFileExcludes>
                            <excludePackageNames>
                                dev.openfeature.flagd.grpc,dev.openfeature.contrib.providers.gofeatureflag.exception,dev.openfeature.contrib.providers.gofeatureflag.bean
                            </excludePackageNames>
                            <doclint>all,-missing
                            </doclint>  <!-- ignore missing javadoc, these are enforced with more customizability in the checkstyle plugin -->
                            <legacyMode>true</legacyMode>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- end source & javadoc -->

                    <!-- SBOM generation -->
                    <plugin>
                        <groupId>org.cyclonedx</groupId>
                        <artifactId>cyclonedx-maven-plugin</artifactId>
                        <version>2.9.1</version>
                        <configuration>
                            <projectType>library</projectType>
                            <schemaVersion>1.3</schemaVersion>
                            <includeBomSerialNumber>true</includeBomSerialNumber>
                            <includeCompileScope>true</includeCompileScope>
                            <includeProvidedScope>true</includeProvidedScope>
                            <includeRuntimeScope>true</includeRuntimeScope>
                            <includeSystemScope>true</includeSystemScope>
                            <includeTestScope>false</includeTestScope>
                            <includeLicenseText>false</includeLicenseText>
                            <outputFormat>all</outputFormat>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <!-- "makeAggregateBom" pollutes each module with the deps of other modules, so we use "makeBom" -->
                                    <goal>makeBom</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- sign the jars -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.8</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- end sign -->

                    <!-- Begin publish to maven central -->
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.8.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>central</publishingServerId>
                            <autoPublish>true</autoPublish>
                            <skipPublishing>${maven.deploy.skip}</skipPublishing>
                        </configuration>
                    </plugin>
                    <!-- End publish to maven central -->
                </plugins>
            </build>
        </profile>
        <profile>
            <id>codequality</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.proc>full</maven.compiler.proc>
            </properties>
            <build>
                <plugins>
                    <!-- CODE QUALITY TOOLS -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>3.6.0</version>
                        <configuration>
                            <configLocation>checkstyle.xml</configLocation>
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>true</failsOnError>
                            <linkXRef>false</linkXRef>
                            <excludeGeneratedSources>true</excludeGeneratedSources>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>com.puppycrawl.tools</groupId>
                                <artifactId>checkstyle</artifactId>
                                <version>10.26.1</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>validate</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>3.27.0</version>
                        <configuration>
                            <excludeRoots>${basedir}/target/generated-sources/</excludeRoots>
                        </configuration>
                        <executions>
                            <execution>
                                <id>run-pmd</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- SpotBugs -->
                    <plugin>
                        <groupId>com.github.spotbugs</groupId>
                        <artifactId>spotbugs-maven-plugin</artifactId>
                        <version>4.9.3.2</version>
                        <configuration>
                            <excludeFilterFile>spotbugs-exclusions.xml</excludeFilterFile>
                            <plugins>
                                <plugin>
                                    <groupId>com.h3xstream.findsecbugs</groupId>
                                    <artifactId>findsecbugs-plugin</artifactId>
                                    <version>1.14.0</version>
                                </plugin>
                            </plugins>
                        </configuration>
                        <dependencies>
                            <!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
                            <dependency>
                                <groupId>com.github.spotbugs</groupId>
                                <artifactId>spotbugs</artifactId>
                                <version>4.9.0</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>run-spotbugs</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Spotless -->
                    <plugin>
                        <groupId>com.diffplug.spotless</groupId>
                        <artifactId>spotless-maven-plugin</artifactId>
                        <version>2.44.5</version>
                        <configuration>
                            <!-- optional: limit format enforcement to just the files changed by this feature branch -->
                            <!--                <ratchetFrom>origin/main</ratchetFrom>-->
                            <formats>
                                <!-- you can define as many formats as you want, each is independent -->
                                <format>
                                    <!-- define the files to apply to -->
                                    <includes>
                                        <include>.gitattributes</include>
                                        <include>.gitignore</include>
                                    </includes>
                                    <!-- define the steps to apply to those files -->
                                    <trimTrailingWhitespace/>
                                    <endWithNewline/>
                                    <indent>
                                        <spaces>true</spaces>
                                        <spacesPerTab>4</spacesPerTab>
                                    </indent>
                                </format>
                            </formats>
                            <!-- define a language-specific format -->
                            <java>
                                <palantirJavaFormat/>

                                <indent>
                                    <spaces>true</spaces>
                                    <spacesPerTab>4</spacesPerTab>
                                </indent>
                                <importOrder/>

                                <removeUnusedImports/>
                                <formatAnnotations/>

                            </java>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- profile for running tests under java 11 (used mostly in CI) -->
        <!-- selected automatically by JDK activeation (see https://maven.apache.org/guides/introduction/introduction-to-profiles.html#implicit-profile-activation) -->
        <profile>
            <id>java11</id>
            <!-- with the next block we can define a set of artifacts which still support java 11, if any of the artifacts is not supporting java 11 anymore -->
            <!--<modules><module></module></modules>-->
            <properties>
                <toolchain.jdk.version>[11,)</toolchain.jdk.version>
                <skip.tests>true</skip.tests>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-toolchains-plugin</artifactId>
                        <version>3.2.0</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>select-jdk-toolchain</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.5.3</version>
                        <configuration>
                            <skipTests>${skip.tests}</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.14.0</version>
                        <executions>
                            <execution>
                                <id>default-testCompile</id>
                                <phase>test-compile</phase>
                                <goals>
                                    <goal>testCompile</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <distributionManagement>
        <snapshotRepository>
            <id>central</id>
            <url>https://central.sonatype.com/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2/</url>
        </repository>
    </distributionManagement>
</project>
