<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2015-2016 HandcraftedBits

  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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <artifactId>handcraftedbits-parent-java</artifactId>
  <packaging>pom</packaging>
  <name>HandcraftedBits Parent POM for Java Projects</name>
  <description>A parent POM used by HandcraftedBits Java projects</description>
  <url>https://github.com/handcraftedbits/handcraftedbits-parent</url>
  <inceptionYear>2015</inceptionYear>

  <parent>
    <groupId>com.handcraftedbits</groupId>
    <artifactId>handcraftedbits-parent</artifactId>
    <version>1.2.2</version>
  </parent>

  <scm>
    <url>https://github.com/handcraftedbits/handcraftedbits-parent</url>
    <connection>scm:git:git://github.com/handcraftedbits/handcraftedbits-parent.git</connection>
    <developerConnection>scm:git:git@github.com:handcraftedbits/handcraftedbits-parent.git</developerConnection>
  </scm>
  <issueManagement>
    <url>https://github.com/handcraftedbits/handcraftedbits-parent/issues</url>
    <system>GitHub Issues</system>
  </issueManagement>

  <properties>
    <coverage.minimum>0.00</coverage.minimum>
    <coverage.skip>false</coverage.skip>
    <javadoc.excludedPackages>*.internal.*</javadoc.excludedPackages>
    <javadoc.skip>false</javadoc.skip>
    <version.java>1.8</version.java>

    <version.dep.codequality>1.0.4</version.dep.codequality>
    <version.dep.findbugs>3.0.1</version.dep.findbugs>
    <version.dep.testng>6.9.9</version.dep.testng>

    <version.plugin.checkstyle>2.17</version.plugin.checkstyle>
    <version.plugin.compiler>3.3</version.plugin.compiler>
    <version.plugin.findbugs>3.0.3</version.plugin.findbugs>
    <version.plugin.jacoco>0.7.5.201505241946</version.plugin.jacoco>
    <version.plugin.javadoc>2.10.3</version.plugin.javadoc>
    <version.plugin.source>2.4</version.plugin.source>
    <version.plugin.surefire>2.19</version.plugin.surefire>
  </properties>

  <profiles>
    <!-- Basic settings for Java projects -->
    <profile>
      <id>java-project</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <file>
          <exists>${basedir}/src/main/java</exists>
        </file>
      </activation>

      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>${version.plugin.compiler}</version>
              <configuration>
                <source>${version.java}</source>
                <target>${version.java}</target>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>

        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>${version.plugin.findbugs}</version>
            <executions>
              <execution>
                <id>check-findbugs</id>
                <phase>verify</phase>
                <goals>
                  <goal>check</goal>
                </goals>
                <configuration>
                  <maxRank>20</maxRank>
                  <threshold>Low</threshold>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${version.plugin.checkstyle}</version>
            <dependencies>
              <dependency>
                <groupId>com.handcraftedbits</groupId>
                <artifactId>handcraftedbits-codequality</artifactId>
                <version>${version.dep.codequality}</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <id>check-style</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>check</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <configLocation>checkstyle_handcraftedbits.xml</configLocation>
              <logViolationsToConsole>true</logViolationsToConsole>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <!-- Additional plugins executed on release -->
    <profile>
      <id>release</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>${version.plugin.javadoc}</version>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>jar</goal>
                </goals>
                <configuration>
                  <skip>${javadoc.skip}</skip>
                  <additionalparam>-Xdoclint:none</additionalparam>
                  <excludePackageNames>${javadoc.excludedPackages}</excludePackageNames>
                  <links>
                    <link>https://docs.oracle.com/javaee/7/api/</link>
                  </links>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>${version.plugin.source}</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <!-- Unit test and code coverage support -->
    <profile>
      <id>unit-test</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <file>
          <exists>${basedir}/src/test/java</exists>
        </file>
      </activation>
      
      <dependencies>
        <dependency>
          <groupId>com.google.code.findbugs</groupId>
          <artifactId>findbugs</artifactId>
          <version>${version.dep.findbugs}</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>${version.dep.testng}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${version.plugin.surefire}</version>
            <configuration>
              <argLine>${coverage.surefire.args}</argLine>
              <parallel>classes</parallel>
              <threadCount>4</threadCount>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${version.plugin.jacoco}</version>
            <executions>
              <execution>
                <id>jacoco-unit-test-prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
                <configuration>
                  <skip>${coverage.skip}</skip>
                  <destFile>${project.build.directory}/coverage/jacoco-unit.exec</destFile>
                  <propertyName>coverage.surefire.args</propertyName>
                </configuration>
              </execution>
              <execution>
                <id>jacoco-unit-test-report</id>
                <goals>
                  <goal>report</goal>
                </goals>
                <configuration>
                  <skip>${coverage.skip}</skip>
                  <dataFile>${project.build.directory}/coverage/jacoco-unit.exec</dataFile>
                  <outputDirectory>${project.build.directory}/coverage/unit</outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>jacoco-unit-test-check</id>
                <goals>
                  <goal>check</goal>
                </goals>
                <configuration>
                  <skip>${coverage.skip}</skip>
                  <dataFile>${project.build.directory}/coverage/jacoco-unit.exec</dataFile>
                  <rules>
                    <rule>
                      <element>CLASS</element>
                      <excludes>
                        <exclude>*IT</exclude>
                        <exclude>*Test</exclude>
                      </excludes>
                      <limits>
                        <limit>
                          <counter>INSTRUCTION</counter>
                          <value>COVEREDRATIO</value>
                          <minimum>${coverage.minimum}</minimum>
                        </limit>
                      </limits>
                    </rule>
                  </rules>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
