<!--
Copyright 2016 Google Inc. All Rights Reserved.

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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <javac.version>9+181-r4173-1</javac.version>

    <maven-release-plugin>2.5.3</maven-release-plugin><!-- could be 3.0.0-M1 -->
    <maven-compiler-plugin>3.8.1</maven-compiler-plugin>
    <nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
    <versions-maven-plugin>2.7</versions-maven-plugin>
    <maven-gpg-plugin>1.6</maven-gpg-plugin>
    <pmdVersion>6.28.0</pmdVersion>
    <skipTests>false</skipTests>
  </properties>

  <groupId>com.google.cloud.samples</groupId>
  <artifactId>shared-configuration</artifactId>
  <version>1.0.21</version>
  <packaging>pom</packaging>

  <name>${project.groupId}:${project.artifactId}</name>
  <description>
    A shared configuration for Google Cloud samples. This defines
    common plugins and their configurations for testing, maintenance, and style
    checks.
  </description>
  <url>https://github.com/GoogleCloudPlatform/java-repo-tools</url>

  <licenses>
    <license>
      <name>The Apache License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>

  <developers>
    <developer>
      <name>Les Vogel</name>
      <email>lesv@google.com</email>
      <organization>Google Inc.</organization>
      <organizationUrl>https://cloud.google.com</organizationUrl>
    </developer>
    <developer>
      <name>Kurtis Van Gent</name>
      <email>kvg@google.com</email>
      <organization>Google Inc.</organization>
      <organizationUrl>https://cloud.google.com</organizationUrl>
    </developer>
    <developer>
      <name>Averi Kitsch‎</name>
      <email>akitsch@google.com</email>
      <organization>Google Inc.</organization>
      <organizationUrl>https://cloud.google.com</organizationUrl>
    </developer>
    <developer>
      <name>Dane Zeke Liergaard</name>
      <email>dzlier@google.com</email>
      <organization>Google Inc.</organization>
      <organizationUrl>https://cloud.google.com</organizationUrl>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:git@github.com:GoogleCloudPlatform/java-repo-tools.git</connection>
    <developerConnection>scm:git:git@github.com:GoogleCloudPlatform/java-repo-tools.git
    </developerConnection>
    <url>git@github.com:GoogleCloudPlatform/java-repo-tools.git</url>
    <tag>v${project.version}</tag>
  </scm>

  <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>
  </distributionManagement>

  <profiles>
    <!-- Code signing for release: http://stackoverflow.com/a/14869692/101923 -->
    <profile>
      <id>release</id>
      <build>
        <plugins>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.2.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-gpg-plugin</artifactId>
            <version>${maven-gpg-plugin}</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
                <configuration><!-- extra -->
                  <keyname>${gpg.keyname}</keyname>
                  <passphraseServerId>${gpg.keyname}</passphraseServerId>
                </configuration>
              </execution>
            </executions>
          </plugin>

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

    <!-- using github.com/google/error-prone-javac is required when running on JDK 8 -->
    <profile>
      <id>jdk8</id>
      <activation>
        <jdk>1.8</jdk>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin}</version>
            <configuration>
              <fork>true</fork>
              <compilerArgs combine.children="append">
                <arg>
                  -J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar
                </arg>
              </compilerArgs>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- only lint when we ask -->
    <profile>
      <id>lint</id>
      <build>
        <plugins>

          <!-- Compile w/ ErrorProne (see https://errorprone.info) -->
          <!-- ie runs on: mvn compile -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin}</version>
            <configuration>
              <compilerArgs>
                <arg>-XDcompilePolicy=simple</arg>
                <arg>-Xplugin:ErrorProne</arg>
              </compilerArgs>
              <annotationProcessorPaths>
                <path>
                  <groupId>com.google.errorprone</groupId>
                  <artifactId>error_prone_core</artifactId>
                  <version>2.4.0</version>
                </path>
              </annotationProcessorPaths>
            </configuration>
          </plugin>

          <plugin><!-- SPOTBUGS -->
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>4.1.3</version>
            <executions>
              <execution>
                <id>analyze-compile</id>
                <phase>compile</phase>
                <goals>
                  <goal>check</goal>
                </goals>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs</artifactId>
                <version>4.1.3</version>
              </dependency>
              <dependency>
                <groupId>com.google.cloud.samples</groupId>
                <artifactId>checkstyle-configuration</artifactId>
                <version>1.0.21</version>
              </dependency>
            </dependencies>
            <configuration>
              <failOnError>true</failOnError>
              <effort>Max</effort>
              <threshold>Low</threshold>
              <includeTests>true</includeTests>
              <fork>false</fork>
              <excludeFilterFile>c.g.c.s/spotBugsExcludeFilter.xml</excludeFilterFile>
              <plugins>
                <plugin>
                  <groupId>com.h3xstream.findsecbugs</groupId>
                  <artifactId>findsecbugs-plugin</artifactId>
                  <version>1.10.1</version>
                </plugin>
                <plugin>
                  <groupId>com.mebigfatguy.sb-contrib</groupId>
                  <artifactId>sb-contrib</artifactId>
                  <version>7.4.7</version>
                </plugin>
                <!-- Great idea, but we need to have a single logging story before we do this -->
                <!--            <plugin> https://github.com/KengoTODA/findbugs-slf4j -->
                <!--              <groupId>jp.skypencil.findbugs.slf4j</groupId>-->
                <!--              <artifactId>findbugs-slf4j</artifactId>-->
                <!--              <version>1.5.0</version>-->
                <!--            </plugin>-->
              </plugins>
            </configuration>
          </plugin>

          <plugin><!-- PMD -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.13.0</version>
            <dependencies>
              <dependency>
                <groupId>net.sourceforge.pmd</groupId>
                <artifactId>pmd-core</artifactId>
                <version>${pmdVersion}</version>
              </dependency>
              <dependency>
                <groupId>net.sourceforge.pmd</groupId>
                <artifactId>pmd-java</artifactId>
                <version>${pmdVersion}</version>
              </dependency>
              <dependency>
                <groupId>net.sourceforge.pmd</groupId>
                <artifactId>pmd-java8</artifactId>
                <version>${pmdVersion}</version>
              </dependency>
            </dependencies>
            <configuration>
              <failOnViolation>true</failOnViolation>
              <printFailingErrors>true</printFailingErrors>
              <skipEmptyReport>false</skipEmptyReport>
              <linkXRef>false</linkXRef>
              <targetJdk>${maven.compiler.source}</targetJdk>
            </configuration>
            <executions>
              <execution>
                <phase>compile</phase>
                <goals>
                  <goal>check</goal>
                  <goal>cpd-check</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin> <!-- Checkstyle -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
              <configLocation>google-checks.xml</configLocation>
              <suppressionsLocation>suppressions.xml</suppressionsLocation>
              <headerLocation>LICENSE.txt</headerLocation>

              <includeTestSourceDirectory>true</includeTestSourceDirectory>
              <consoleOutput>true</consoleOutput>
              <logViolationsToConsole>true</logViolationsToConsole>
              <failOnViolation>true</failOnViolation>
            </configuration>
            <dependencies>
              <!-- Add a dependency to use bundled resources.
                   See: http://stackoverflow.com/a/19690484/101923 -->
              <dependency>
                <groupId>com.google.cloud.samples</groupId>
                <artifactId>checkstyle-configuration</artifactId>
                <version>1.0.21</version>
              </dependency>
              <dependency>
                <groupId>com.puppycrawl.tools</groupId>
                <artifactId>checkstyle</artifactId>
                <version>8.36.2</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <phase>verify</phase>
                <goals>
                  <goal>check</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

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

  <dependencies>
    <dependency>
      <groupId>com.github.spotbugs</groupId>
      <artifactId>spotbugs-annotations</artifactId>
      <version>4.1.3</version>
      <optional>true</optional>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin> <!-- Unit Tests -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <skipTests>${skipTests}</skipTests>
          <reportNameSuffix>sponge_log</reportNameSuffix>
          <trimStackTrace>false</trimStackTrace>
        </configuration>
      </plugin>

      <plugin> <!-- FAILSAFE -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0-M5</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <reportNameSuffix>sponge_log</reportNameSuffix>
        </configuration>
      </plugin>

      <plugin> <!-- Versions -->
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.8.1</version>
      </plugin>

      <plugin> <!-- JACOCO - reporting -->
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.6</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>report</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>
