<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (C) 2022 - 2024, the original author or authors.

    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="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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>io.github.ascopes.jct</groupId>
  <artifactId>java-compiler-testing-parent</artifactId>
  <version>3.0.4</version>
  <packaging>pom</packaging>

  <name>Java Compiler Testing parent project</name>

  <description>
    Parent POM for the java-compiler-testing project. You probably want to be using that instead
    of including this POM into your projects directly.
  </description>

  <modules>
    <module>java-compiler-testing</module>
    <module>acceptance-tests</module>
  </modules>

  <inceptionYear>2022</inceptionYear>
  <url>https://github.com/ascopes/java-compiler-testing</url>

  <developers>
    <developer>
      <id>ascopes</id>
      <name>Ashley Scopes</name>
      <email>73482956+ascopes@users.noreply.github.com</email>
      <url>https://github.com/ascopes</url>
      <organization>Ashley Scopes</organization>
      <organizationUrl>https://github.com/ascopes</organizationUrl>
      <roles>
        <role>Developer</role>
      </roles>
      <timezone>Europe/London</timezone>
    </developer>
  </developers>

  <contributors />

  <issueManagement>
    <system>GitHub Issues</system>
    <url>https://github.com/ascopes/java-compiler-testing/issues</url>
  </issueManagement>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>https://github.com/ascopes/java-compiler-testing/blob/main/LICENSE.txt</url>
    </license>
  </licenses>

  <organization>
    <name>Ashley Scopes (GitHub)</name>
    <url>https://github.com/ascopes</url>
  </organization>

  <scm>
    <url>https://github.com/ascopes/java-compiler-testing</url>
    <connection>scm:git:https://github.com/ascopes/java-compiler-testing</connection>
    <developerConnection>scm:git:https://github.com/ascopes/java-compiler-testing</developerConnection>
    <tag>v3.0.4</tag>
  </scm>

  <properties>
    <!-- Dependencies -->
    <apiguardian.version>1.1.2</apiguardian.version>
    <assertj.version>3.25.2</assertj.version>
    <awaitility.version>4.2.0</awaitility.version>
    <fuzzywuzzy.version>1.4.0</fuzzywuzzy.version>
    <jspecify.version>0.3.0</jspecify.version>
    <junit.version>5.10.1</junit.version>
    <memoryfilesystem.version>2.8.0</memoryfilesystem.version>
    <mockito.version>5.10.0</mockito.version>
    <slf4j.version>2.0.12</slf4j.version>

    <!-- Plugins -->
    <jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
    <license-maven-plugin.version>4.3</license-maven-plugin.version>
    <maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
    <maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
    <maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
    <maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
    <maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
    <maven-install-plugin.version>3.1.1</maven-install-plugin.version>
    <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
    <maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
    <maven-release-plugin.version>3.0.0-M7</maven-release-plugin.version>
    <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
    <maven-source-plugin.version>3.3.0</maven-source-plugin.version>
    <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>

    <!-- Plugin dependencies -->
    <checkstyle.version>10.13.0</checkstyle.version>
    <maven-surefire-junit5-tree-reporter.version>1.2.1</maven-surefire-junit5-tree-reporter.version>

    <!-- Log verbosity -->
    <hide-test-logs-in-console>true</hide-test-logs-in-console>

    <!--
      This argument is pulled in by Failsafe, and JaCoCo will amend it to ensure the
      coverage agent is installed into the forked JVM running the tests. See
      https://www.eclemma.org/jacoco/trunk/doc/prepare-agent-mojo.html for info.

      We also disable code sharing to prevent some other warnings during test runs, and
      force the SLF4J simple logger defaults to use in tests here.

      URL support for the memory filesystem requires enablement by system property.

      Tired compilation is modified to reduce the amount of time the JVM wastes JITing
      code during tests.

      Byte Buddy experimental support enables running ByteBuddy (used by Mockito) in JDK
      experimental builds.
    -->
    <argLine>
      -Dnet.bytebuddy.experimental=true
      -Dorg.slf4j.simpleLogger.log=WARN
      -Dorg.slf4j.simpleLogger.log.io.github.ascopes.jct=INFO
      -Xshare:off
      -XX:+TieredCompilation
      -XX:TieredStopAtLevel=1
    </argLine>

    <!-- Project flags -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java-release>11</java-release>

    <!-- JavaDocs -->
    <current-year>2024</current-year>
    <newest-java-version>21</newest-java-version>
    <highlight-js.version>11.9.0</highlight-js.version>

    <!-- Other configuration -->
    <project-slug>ascopes/java-compiler-testing</project-slug>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <!-- In-memory file system -->
        <groupId>com.github.marschall</groupId>
        <artifactId>memoryfilesystem</artifactId>
        <version>${memoryfilesystem.version}</version>
      </dependency>

      <dependency>
        <!-- Fuzzy string matching -->
        <groupId>me.xdrop</groupId>
        <artifactId>fuzzywuzzy</artifactId>
        <version>${fuzzywuzzy.version}</version>
      </dependency>

      <dependency>
        <!-- API versioning annotations -->
        <groupId>org.apiguardian</groupId>
        <artifactId>apiguardian-api</artifactId>
        <version>${apiguardian.version}</version>
      </dependency>

      <dependency>
        <!-- Fluent assertions -->
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>${assertj.version}</version>
      </dependency>

      <dependency>
        <!-- Awaitable assertions -->
        <groupId>org.awaitility</groupId>
        <artifactId>awaitility</artifactId>
        <version>${awaitility.version}</version>
      </dependency>

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

      <dependency>
        <!-- Unit testing -->
        <groupId>org.junit</groupId>
        <artifactId>junit-bom</artifactId>
        <version>${junit.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>

      <dependency>
        <!-- Mocking -->
        <groupId>org.mockito</groupId>
        <artifactId>mockito-bom</artifactId>
        <version>${mockito.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>

      <dependency>
        <!-- Logging interface -->
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
      </dependency>

      <dependency>
        <!-- Logging implementation for tests -->
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${slf4j.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <!-- Java compiler config -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>${maven-compiler-plugin.version}</version>

          <configuration>
            <failOnWarning>true</failOnWarning>
            <parameters>true</parameters>
            <release>${java-release}</release>
            <showDeprecation>true</showDeprecation>
            <showWarnings>true</showWarnings>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>${maven-deploy-plugin.version}</version>

          <configuration>
            <deployAtEnd>true</deployAtEnd>
          </configuration>
        </plugin>

        <plugin>
          <!-- Integration testing config -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>${maven-failsafe-plugin.version}</version>

          <configuration>
            <includes>
              <include>*IntegrationTest</include>
            </includes>

            <failIfNoTests>true</failIfNoTests>
            <runOrder>random</runOrder>
            <useModulePath>true</useModulePath>

            <!--
              This block is needed to show @DisplayName and @ParameterizedTest
              in reports with the provided names.
            -->
            <statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
              <disable>false</disable>
              <version>3.0</version>
              <usePhrasedFileName>false</usePhrasedFileName>
              <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
              <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
              <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
            </statelessTestsetReporter>
            <consoleOutputReporter>
              <disable>${hide-test-logs-in-console}</disable>
            </consoleOutputReporter>
            <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode">
              <disable>false</disable>
              <printStacktraceOnError>true</printStacktraceOnError>
              <printStacktraceOnFailure>true</printStacktraceOnFailure>
              <usePhrasedFileName>false</usePhrasedFileName>
              <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
              <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
            </statelessTestsetInfoReporter>
          </configuration>

          <dependencies>
            <dependency>
              <groupId>me.fabriciorby</groupId>
              <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
              <version>${maven-surefire-junit5-tree-reporter.version}</version>
            </dependency>
          </dependencies>

          <executions>
            <execution>
              <!-- Enable failsafe to run -->
              <id>integration-test</id>
              <!-- This must not run during the test phase - JaCoCo messes up the reporting! -->
              <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>${maven-gpg-plugin.version}</version>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>${maven-install-plugin.version}</version>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>${maven-jar-plugin.version}</version>

          <configuration>
            <archive>
              <manifest>
                <addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
              </manifest>
              <manifestEntries>
                <Sealed>true</Sealed>
              </manifestEntries>
            </archive>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>${maven-javadoc-plugin.version}</version>

          <configuration>
            <additionalOptions>
              <option>--allow-script-in-comments</option>
              <option>--override-methods=detail</option>
              <option>--show-packages=exported</option>
              <option>-use</option>
              <option>-Xdoclint:all</option>
            </additionalOptions>
            <bottom>© ${project.inceptionYear} - ${current-year}, Ashley Scopes --
              Apache License V2
            </bottom>
            <defaultSince>0.0.1</defaultSince>
            <detectLinks>false</detectLinks>
            <header>
              <![CDATA[
              <!-- Highlight.js -->
              <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlight-js.version}/styles/stackoverflow-light.min.css">
              <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/${highlight-js.version}/highlight.min.js"></script>
              <script>
                "use strict";

                function initSyntaxHighlighting() {
                  hljs.configure({languages: ["java"]});
                  hljs.highlightAll();
                }

                if (document.readyState === "complete" || document.readyState === "interactive") {
                  setTimeout(initSyntaxHighlighting, 1);
                } else {
                  document.addEventListener("DOMContentLoaded", initSyntaxHighlighting);
                }
              </script>
              ]]>
            </header>
            <linksource>true</linksource>
            <links>
              <link>https://docs.oracle.com/en/java/javase/${newest-java-version}/docs/api</link>
              <link>https://javadoc.io/doc/org.assertj/assertj-core/${assertj.version}</link>
              <link>https://javadoc.io/doc/org.jspecify/jspecify/${jspecify.version}</link>
              <link>https://javadoc.io/doc/org.slf4j/slf4j-api/${slf4j.version}</link>
              <link>https://javadoc.io/doc/org.junit.jupiter/junit-jupiter-api/${junit.version}</link>
              <link>https://javadoc.io/doc/org.junit.jupiter/junit-jupiter-params/${junit.version}</link>
            </links>
            <quiet>true</quiet>
            <release>${java-release}</release>
          </configuration>
        </plugin>

        <plugin>
          <!-- Release management -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <configuration>
            <releaseProfiles>releases</releaseProfiles>
          </configuration>
        </plugin>

        <plugin>
          <!-- Resource file handling -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>${maven-resources-plugin.version}</version>
        </plugin>

        <plugin>
          <!-- Bundles source code into a JAR -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>${maven-source-plugin.version}</version>
        </plugin>

        <plugin>
          <!-- Unit testing config -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven-surefire-plugin.version}</version>

          <configuration>
            <excludes>
              <exclude>*IntegrationTest</exclude>
            </excludes>

            <failIfNoTests>true</failIfNoTests>
            <runOrder>random</runOrder>
            <useModulePath>true</useModulePath>

            <!--
              This block is needed to show @DisplayName and @ParameterizedTest
              in reports with the provided names.
            -->
            <statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
              <disable>false</disable>
              <version>3.0</version>
              <usePhrasedFileName>false</usePhrasedFileName>
              <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
              <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
              <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
            </statelessTestsetReporter>
            <consoleOutputReporter>
              <disable>${hide-test-logs-in-console}</disable>
            </consoleOutputReporter>
            <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode">
              <disable>false</disable>
              <printStacktraceOnError>true</printStacktraceOnError>
              <printStacktraceOnFailure>true</printStacktraceOnFailure>
              <usePhrasedFileName>false</usePhrasedFileName>
              <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
              <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
            </statelessTestsetInfoReporter>
          </configuration>

          <dependencies>
            <dependency>
              <groupId>me.fabriciorby</groupId>
              <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
              <version>${maven-surefire-junit5-tree-reporter.version}</version>
            </dependency>
          </dependencies>
        </plugin>

        <plugin>
          <!-- Coverage tracing -->
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${jacoco-maven-plugin.version}</version>

          <executions>
            <execution>
              <id>add-coverage-agent-to-surefire-args</id>
              <phase>initialize</phase>
              <goals>
                <goal>prepare-agent</goal>
              </goals>

              <configuration>
                <destFile>${project.build.directory}/jacoco-unit.bin</destFile>
              </configuration>
            </execution>

            <execution>
              <id>report-unit-test-coverage</id>
              <phase>test</phase>
              <goals>
                <goal>report</goal>
              </goals>
              <configuration>
                <dataFile>${project.build.directory}/jacoco-unit.bin</dataFile>
                <outputDirectory>${project.build.directory}/site/jacoco/unit</outputDirectory>
              </configuration>
            </execution>

            <execution>
              <id>add-coverage-agent-to-failsafe-args</id>
              <phase>pre-integration-test</phase>
              <goals>
                <goal>prepare-agent-integration</goal>
              </goals>
              <configuration>
                <destFile>${project.build.directory}/jacoco-int.bin</destFile>
              </configuration>
            </execution>

            <execution>
              <id>report-integration-test-coverage</id>
              <phase>post-integration-test</phase>
              <goals>
                <goal>report-integration</goal>
              </goals>
              <configuration>
                <dataFile>${project.build.directory}/jacoco-int.bin</dataFile>
                <outputDirectory>${project.build.directory}/site/jacoco/int</outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <!-- Enforces our license header and allows adding it automatically to code. -->
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>${license-maven-plugin.version}</version>

        <configuration>
          <licenseSets>
            <licenseSet>
              <header>.mvn/license/license-header.txt</header>
              <!-- Useful flags: https://mycila.carbou.me/license-maven-plugin/ -->
              <includes>
                <include>**.toml</include>
                <include>**.yml</include>
                <include>**.yaml</include>
                <include>pom.xml</include>
                <include>security-suppressions.xml</include>
                <include>src/**/*.groovy</include>
                <include>src/**/*.java</include>
                <include>scripts/**/*.sh</include>
              </includes>
            </licenseSet>
          </licenseSets>
          <mapping>
            <groovy>SLASHSTAR_STYLE</groovy>
            <java>SLASHSTAR_STYLE</java>
            <toml>SCRIPT_STYLE</toml>
          </mapping>
          <properties>
            <currentYear>${current-year}</currentYear>
            <inceptionYear>${project.inceptionYear}</inceptionYear>
          </properties>
          <strictCheck>true</strictCheck>
        </configuration>

        <executions>
          <execution>
            <id>check-license-headers</id>
            <phase>validate</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <!-- Checking style of code matches the Google code style -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${maven-checkstyle-plugin.version}</version>
        <inherited>false</inherited>

        <executions>
          <execution>
            <id>check-code-style</id>
            <phase>validate</phase>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <configLocation>.mvn/checkstyle/checkstyle.xml</configLocation>
              <consoleOutput>true</consoleOutput>
              <failsOnError>true</failsOnError>
              <includeResources>true</includeResources>
              <sourceDirectories>${project.basedir}/src</sourceDirectories>
              <suppressionsLocation>.mvn/checkstyle/suppressions.xml</suppressionsLocation>
              <violationSeverity>info</violationSeverity>
            </configuration>
          </execution>
        </executions>

        <dependencies>
          <dependency>
            <!-- Force the usage of checkstyle v10 rather than v8.28 -->
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>${checkstyle.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>maven-central</id>

      <distributionManagement>
        <repository>
          <id>ossrh</id>
          <name>Maven Central Releases</name>
          <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
        <snapshotRepository>
          <id>ossrh</id>
          <name>Maven Central Snapshots</name>
          <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
      </distributionManagement>
    </profile>
    
    <profile>
      <id>github</id>

      <distributionManagement>
        <repository>
          <id>github</id>
          <name>GitHub Packages</name>
          <url>https://maven.pkg.github.com/${project-slug}</url>
        </repository>
        <snapshotRepository>
          <id>github</id>
          <name>GitHub Packages Snapshots</name>
          <url>https://maven.pkg.github.com/${project-slug}</url>
        </snapshotRepository>
      </distributionManagement>
    </profile>

    <profile>
      <id>releases</id>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <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>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Enable GPG-signing the release -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
                <configuration>
                  <gpgArguments>
                    <arg>--pinentry-mode</arg>
                    <arg>loopback</arg>
                  </gpgArguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
