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

    Copyright (C) 2022 Ashley Scopes

    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>

  <parent>
    <groupId>io.github.ascopes.jct</groupId>
    <artifactId>java-compiler-testing-parent</artifactId>
    <version>6.0.1</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>java-compiler-testing</artifactId>

  <name>Java Compiler Testing</name>
  <!-- Need to override this as Maven injects the wrong URL otherwise -->
  <url>https://github.com/${project-slug}</url>

  <description>
    Library to help developers write declarative integration tests that call
    the Java Compiler toolchain.
  </description>

  <dependencies>
    <dependency>
      <groupId>com.github.marschall</groupId>
      <artifactId>memoryfilesystem</artifactId>
    </dependency>

    <dependency>
      <groupId>me.xdrop</groupId>
      <artifactId>fuzzywuzzy</artifactId>
    </dependency>

    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
    </dependency>

    <dependency>
      <groupId>org.jspecify</groupId>
      <artifactId>jspecify</artifactId>
      <optional>true</optional>
    </dependency>

    <dependency>
      <!-- Used to provide convenience annotations -->
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <optional>true</optional>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
      <scope>test</scope>
    </dependency>

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

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

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

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

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <annotationProcessorPaths combine.children="append" />
          <compilerArgs combine.children="append">
            <!--
              Disable warnings about modules. We cannot do much about some of these due to how Maven
              works with modules with Surefire.
            -->
            <arg>-Xlint:-module</arg>
          </compilerArgs>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
      </plugin>

      <plugin>
        <!-- Runs integration tests. -->
        <!-- See documentation at https://maven.apache.org/plugins/maven-invoker-plugin/integration-test-mojo.html -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>${maven-invoker-plugin.version}</version>

        <configuration>
          <addTestClassPath>true</addTestClassPath>
          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
          <failIfNoProjects>true</failIfNoProjects>
          <extraArtifacts>
            <extraArtifact>${project.groupId}:${project.parent.artifactId}:${project.version}:pom</extraArtifact>
          </extraArtifacts>
          <postBuildHookScript>test</postBuildHookScript>
          <settingsFile>src/it/settings.xml</settingsFile>
          <showErrors>true</showErrors>
          <showVersion>true</showVersion>
          <streamLogs>true</streamLogs>
          <writeJunitReport>true</writeJunitReport>
        </configuration>

        <executions>
          <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
              <goal>install</goal>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>

        <configuration>
          <excludePackageNames>
            io.github.ascopes.jct.**.impl;
            io.github.ascopes.jct.utils;
          </excludePackageNames>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>

        <configuration>
          <excludes>
            <!-- LoomPolyFill contains JDK-specific code, so 100% coverage isn't possible on a
                single platform. -->
            <exclude>io/github/ascopes/jct/utils/LoomPolyfill.class</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>invoker-debug</id>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-invoker-plugin</artifactId>
              <version>${maven-invoker-plugin.version}</version>
              <configuration>
                <invokerPropertiesFile>invoker-debug.properties</invokerPropertiesFile>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>

    <profile>
      <!-- ErrorProne only works with Java 21 and newer. If we're on Java 17, we cannot
           enable it within the compiler. This is somewhat unfortunate but should be okay
           as a workaround for now since we build on multiple JDKs on GitHub. -->
      <id>errorprone</id>
      <activation>
        <jdk>[21,)</jdk>
      </activation>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>

            <configuration>
              <annotationProcessorPaths>
                <annotationProcessorPath>
                  <groupId>com.google.errorprone</groupId>
                  <artifactId>error_prone_core</artifactId>
                  <version>${errorprone.version}</version>
                </annotationProcessorPath>
                <annotationProcessorPath>
                  <!-- Override what Maven is pulling in. This is fine during compilation as our
                       code doesn't use Guava at all. This is needed for ErrorProne to not crash
                       on startup. -->
                  <groupId>com.google.guava</groupId>
                  <artifactId>guava</artifactId>
                  <version>[33,)</version>
                </annotationProcessorPath>
                <annotationProcessorPath>
                  <groupId>com.uber.nullaway</groupId>
                  <artifactId>nullaway</artifactId>
                  <version>${nullaway.version}</version>
                </annotationProcessorPath>
              </annotationProcessorPaths>

              <compilerArgs>
                <!--
                  Disable warnings about modules. We cannot do much about some of these due to how Maven
                  works with modules with Surefire.
                -->
                <arg>-Xlint:-module</arg>
                <!-- ErrorProne configuration -->
                <compilerArg>--should-stop=ifError=FLOW</compilerArg>
                <compilerArg>
                  -Xplugin:ErrorProne
                  -XepDisableWarningsInGeneratedCode
                  -XepExcludedPaths:.*/target/generated.*?/.*
                  -XepOpt:NullAway:AnnotatedPackages=io.github.ascopes.jct
                  <!-- See https://github.com/uber/NullAway/issues/1319 -->
                  -XepOpt:NullAway:ExcludedFieldAnnotations=org.junit.jupiter.*,org.mockito.*
                  -XepOpt:NullAway:KnownInitializers=io.github.ascopes.jct.annotations.Initializer,io.github.ascopes.jct.junit.Managed
                </compilerArg>
                <!-- Needed for ErrorProne to be able to run -->
                <compilerArg>-XDaddTypeAnnotationsToSymbol=true</compilerArg>
                <compilerArg>-XDcompilePolicy=simple</compilerArg>
              </compilerArgs>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
