<?xml version="1.0"?>
<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>com.contrastsecurity</groupId>
  <artifactId>contrast-maven-plugin</artifactId>
  <version>2.13.2</version>
  <packaging>maven-plugin</packaging>

  <name>Contrast Maven Plugin</name>
  <description>
    Maven plugin for including Contrast security analysis in Java web applications
  </description>
  <url>https://docs.contrastsecurity.com/en/maven.html</url>

  <organization>
    <name>Contrast Security, Inc.</name>
    <url>https://contrastsecurity.com</url>
  </organization>

  <developers>
    <developer>
      <name>Contrast Security</name>
      <email>support@contrastsecurity.com</email>
    </developer>
  </developers>

  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
      <comments>A business-friendly OSS license</comments>
    </license>
  </licenses>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
    <site>
      <id>github</id>
      <url>scm:git:https://github.com/Contrast-Security-OSS/contrast-maven-plugin.git</url>
    </site>
  </distributionManagement>

  <scm>
    <connection>scm:git:https://github.com/Contrast-Security-OSS/contrast-maven-plugin.git
    </connection>
    <url>scm:git:https://github.com/Contrast-Security-OSS/contrast-maven-plugin.git</url>
    <developerConnection>
      scm:git:https://github.com/Contrast-Security-OSS/contrast-maven-plugin.git
    </developerConnection>
    <tag>contrast-maven-plugin-2.13.2</tag>
  </scm>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <contrast.test-repository>${project.build.directory}/test-repository</contrast.test-repository>
    <junit-jupiter.version>5.7.2</junit-jupiter.version>
    <junit-vintage-engine.version>5.7.2</junit-vintage-engine.version>
    <auto-value.version>1.6.3</auto-value.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>3.5.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.6.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.contrastsecurity</groupId>
      <artifactId>contrast-sdk-java</artifactId>
      <version>3.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-project</artifactId>
      <version>2.2.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-settings</artifactId>
      <version>2.2.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-model</artifactId>
      <version>3.5.3</version>
    </dependency>
    <dependency>
      <groupId>com.google.auto.value</groupId>
      <artifactId>auto-value-annotations</artifactId>
      <version>${auto-value.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- TEST DEPENDENCIES -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>3.11.2</version>
      <scope>test</scope>
    </dependency>
    <!-- TODO[JG] Migrate from JUnit 4 -->
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <version>${junit-vintage-engine.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.github.stefanbirkner</groupId>
      <artifactId>system-rules</artifactId>
      <version>1.17.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.shared</groupId>
      <artifactId>maven-verifier</artifactId>
      <version>1.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>3.20.2</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>

    <resources>
      <!-- filter poms in integration test directory to replace plugin version -->
      <resource>
        <directory>src/test/resources/it</directory>
        <filtering>true</filtering>
        <targetPath>${project.build.directory}/test-classes/it</targetPath>
        <includes>
          <include>**/pom.xml</include>
        </includes>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <release>8</release>
          <annotationProcessorPaths>
            <path>
              <groupId>com.google.auto.value</groupId>
              <artifactId>auto-value</artifactId>
              <version>${auto-value.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <executions>
          <execution>
            <!-- Always automatically add license file to generated sources -->
            <id>update-generated-sources</id>
            <goals>
              <goal>update-file-header</goal>
            </goals>
            <phase>process-test-sources</phase>
            <configuration>
              <roots>${project.build.directory}/generated-sources</roots>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-plugin-plugin</artifactId>
        <configuration>
          <goalPrefix>contrast</goalPrefix>
          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>package</phase>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <source>11</source>
          <detectJavaApiLink>false</detectJavaApiLink>
        </configuration>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
          <releaseProfiles>release</releaseProfiles>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <executions>
          <execution>
            <id>deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <configuration>
          <!-- disable default deployment because we use maven-scm-publish-plugin for deploying the site to GitHub Pages since the site plugin is incapable of doing this -->
          <skipDeploy>true</skipDeploy>
        </configuration>
        <executions>
          <execution>
            <id>stage-site</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>stage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>templating-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>filtering-java-templates</id>
            <goals>
              <goal>filter-sources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-scm-publish-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <scmBranch>gh-pages</scmBranch>
          <username>${env.GITHUB_ACTOR}</username>
          <password>${env.GITHUB_TOKEN}</password>
        </configuration>
        <executions>
          <execution>
            <id>site-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>publish-scm</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-source-plugin</artifactId>
          <version>3.2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>2.22.2</version>
          <configuration>
            <!-- never use legacy JUnit tests for new integration tests -->
            <classpathDependencyExcludes>
              <classpathDependencyExclude>junit:junit</classpathDependencyExclude>
              <classpathDependencyExclude>org.junit.vintage:junit-vintage-engine
              </classpathDependencyExclude>
            </classpathDependencyExcludes>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-plugin-plugin</artifactId>
          <version>3.6.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>3.3.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.9.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>3.0.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.1.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-scm-plugin</artifactId>
          <version>1.11.2</version>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>templating-maven-plugin</artifactId>
          <version>1.0.0</version>
        </plugin>
        <plugin>
          <groupId>com.diffplug.spotless</groupId>
          <artifactId>spotless-maven-plugin</artifactId>
          <version>2.12.0</version>
          <configuration>
            <formats>
              <format>
                <includes>
                  <include>pom.xml</include>
                  <include>README.md</include>
                  <include>.github/workflows/**/*.yml</include>
                  <include>src/**/*.java</include>
                  <include>src/**/*.xml</include>
                  <include>src/**/*.properties</include>
                </includes>
                <trimTrailingWhitespace />
                <endWithNewline />
              </format>
            </formats>
            <java>
              <googleJavaFormat>
                <version>1.9</version>
              </googleJavaFormat>
              <removeUnusedImports />
            </java>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>license-maven-plugin</artifactId>
          <version>2.0.0</version>
          <configuration>
            <licenseName>apache_v2</licenseName>
            <inceptionYear>2021</inceptionYear>
            <excludes>
              <exclude>**/*.json</exclude>
            </excludes>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.sonatype.plugins</groupId>
          <artifactId>nexus-staging-maven-plugin</artifactId>
          <version>1.6.8</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <artifactId>maven-plugin-plugin</artifactId>
      </plugin>
    </plugins>
  </reporting>
  <profiles>
    <profile>
      <id>developer</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>update-file-header</goal>
                </goals>
                <phase>process-test-sources</phase>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.diffplug.spotless</groupId>
            <artifactId>spotless-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>apply</goal>
                </goals>
                <phase>process-test-sources</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>ci</id>
      <activation>
        <property>
          <name>env.CI</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>check-file-header</goal>
                </goals>
                <phase>process-test-sources</phase>
                <configuration>
                  <failOnMissingHeader>true</failOnMissingHeader>
                  <failOnNotUptodateHeader>true</failOnNotUptodateHeader>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.diffplug.spotless</groupId>
            <artifactId>spotless-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>check</goal>
                </goals>
                <phase>process-test-sources</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>end-to-end-test</id>
      <activation>
        <!-- active in CI by default -->
        <property>
          <name>${env.CI}</name>
          <value>true</value>
        </property>
      </activation>
      <!--
      This profile runs the integration tests with an external Contrast system.
      Developers configure the connection to the external system using Contrast environment
      variables for connecting to Contrast.
      -->
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>install-to-test-repository</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>${project.artifactId}</artifactId>
                      <version>${project.version}</version>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>${project.artifactId}</artifactId>
                      <version>${project.version}</version>
                      <type>pom</type>
                    </artifactItem>
                  </artifactItems>
                  <outputDirectory>
                    ${contrast.test-repository}/com/contrastsecurity/${project.artifactId}/${project.version}
                  </outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>retrieve-agent-for-testing</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>com.contrastsecurity</groupId>
                      <artifactId>contrast-agent</artifactId>
                      <!-- practically any version will satisfy the needs of the test -->
                      <version>3.8.5.20387</version>
                    </artifactItem>
                  </artifactItems>
                  <stripVersion>true</stripVersion>
                  <outputDirectory>
                    ${project.build.testOutputDirectory}
                  </outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>analyze-dependencies</id>
                <phase>test</phase>
                <goals>
                  <goal>analyze-only</goal>
                </goals>
                <configuration>
                  <failOnWarning>true</failOnWarning>
                  <!-- https://stackoverflow.com/a/27729783/501368 -->
                  <ignoreNonCompile>true</ignoreNonCompile>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <systemProperties>
                <contrast.test-repository>${contrast.test-repository}</contrast.test-repository>
                <contrast.api.url>${env.CONTRAST__API__URL}</contrast.api.url>
                <contrast.api.user_name>${env.CONTRAST__API__USER_NAME}</contrast.api.user_name>
                <contrast.api.api_key>${env.CONTRAST__API__API_KEY}</contrast.api.api_key>
                <contrast.api.service_key>${env.CONTRAST__API__SERVICE_KEY}
                </contrast.api.service_key>
                <contrast.api.organization_id>${env.CONTRAST__API__ORGANIZATION_ID}
                </contrast.api.organization_id>
              </systemProperties>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
              <serverId>ossrh</serverId>
              <nexusUrl>https://oss.sonatype.org/</nexusUrl>
              <autoReleaseAfterClose>true</autoReleaseAfterClose>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-gpg-plugin</artifactId>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
