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

  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>org.lable.oss</groupId>
  <artifactId>parent</artifactId>
  <version>1.14</version>
  <packaging>pom</packaging>

  <name>Maven parent for Lable projects</name>
  <description>
    Common configuration for Lable Maven projects.

    This POM configures code-coverage, unit and integration testing, and a number of common Maven plugins.
  </description>
  <url>https://github.com/LableOrg/maven-parent</url>

  <organization>
    <name>Lable</name>
    <url>https://lable.nl</url>
  </organization>

  <developers>
    <developer>
      <id>jdhoek</id>
      <name>Jeroen Hoek</name>
      <email>jeroen.hoek@lable.nl</email>
      <organization>Lable</organization>
      <organizationUrl>https://lable.nl</organizationUrl>
    </developer>
  </developers>

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

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.build.outputEncoding>UTF-8</project.build.outputEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Plugin versions. -->
    <maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
    <maven.failsafe.plugin.version>2.22.2</maven.failsafe.plugin.version>
    <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
    <maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
    <maven.deploy.plugin.version>3.0.0-M1</maven.deploy.plugin.version>
    <maven.release.plugin.version>3.0.0-M1</maven.release.plugin.version>
    <maven.source.plugin.version>3.2.1</maven.source.plugin.version>
    <maven.javadoc.plugin.version>3.2.0</maven.javadoc.plugin.version>
    <maven.versions.version>2.8.1</maven.versions.version>
    <license.plugin.version>3.0</license.plugin.version>
    <jacoco.plugin.version>0.8.5</jacoco.plugin.version>

    <java.language.level>11</java.language.level>

    <!-- Dependency versions. -->
    <junit.version>4.13</junit.version>
    <hamcrest.version>2.2</hamcrest.version>
    <hamcrest.optional>2.0.0</hamcrest.optional>
    <mockito.version>3.4.6</mockito.version>
  </properties>

  <scm>
    <connection>scm:git:git@github.com:LableOrg/maven-parent.git</connection>
    <developerConnection>scm:git:git@github.com:LableOrg/maven-parent.git</developerConnection>
    <url>https://github.com/LableOrg/maven-parent.git</url>
    <tag>v1.14</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>

  <dependencies>
    <!-- Testing dependencies. -->
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <version>${hamcrest.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.github.npathai</groupId>
      <artifactId>hamcrest-optional</artifactId>
      <version>${hamcrest.optional}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>${mockito.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <!-- Configure the compiler. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven.compiler.plugin.version}</version>
        <configuration>
          <release>${java.language.level}</release>
          <compilerArgs>
            <arg>-Xlint</arg>
            <arg>-Xdoclint</arg>
            <arg>-parameters</arg>
          </compilerArgs>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>${maven.release.plugin.version}</version>
        <configuration>
          <!-- Disable the site-deploy target, because we don't deploy the generated site contents anywhere. -->
          <goals>deploy</goals>
          <!-- Pass the integration test argument. Any project that uses this to activate integration
               testing profiles normally disabled due to the time it takes to execute them will have
               their integration testing profiles actived. -->
          <arguments>-Dit</arguments>
          <tagNameFormat>v@{project.version}</tagNameFormat>
          <!-- All child modules follow the parent version. -->
          <autoVersionSubmodules>true</autoVersionSubmodules>
          <!-- A local checkout is a *lot* faster than cloning the complete repository. -->
          <localCheckout>true</localCheckout>
          <useReleaseProfile>false</useReleaseProfile>
          <!-- Enable the release profile (code signing). -->
          <releaseProfiles>release</releaseProfiles>
        </configuration>
      </plugin>

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

      <plugin>
        <!-- Build source jars. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>${maven.source.plugin.version}</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <attach>true</attach>
        </configuration>
      </plugin>

      <plugin>
        <!-- Manage dependency versions. -->
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>${maven.versions.version}</version>
        <configuration>
          <generateBackupPoms>false</generateBackupPoms>
        </configuration>
      </plugin>

    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <!-- Unit testing. -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven.surefire.plugin.version}</version>
          <configuration>
            <systemPropertyVariables>
              <buildDirectory>${project.build.directory}</buildDirectory>
            </systemPropertyVariables>
          </configuration>
        </plugin>

        <plugin>
          <!-- Integration tests are run by failsafe. -->
          <!-- Classes under src/test/java called *IT are included automatically. -->
          <!-- Integration tests are run during the verify phase. -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>${maven.failsafe.plugin.version}</version>
          <configuration>
            <systemPropertyVariables>
              <buildDirectory>${project.build.directory}</buildDirectory>
            </systemPropertyVariables>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <plugin>
          <!-- Code coverage plugin. -->
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${jacoco.plugin.version}</version>
          <executions>
            <execution>
              <id>jacoco-prepare-agent</id>
              <goals>
                <goal>prepare-agent</goal>
              </goals>
              <configuration>
                <destFile>${project.build.directory}/jacoco-unit.exec</destFile>
              </configuration>
            </execution>
            <execution>
              <id>jacoco-prepare-agent-integration</id>
              <goals>
                <goal>prepare-agent-integration</goal>
              </goals>
            </execution>
            <execution>
              <id>jacoco-report</id>
              <goals>
                <goal>report</goal>
              </goals>
              <configuration>
                <dataFile>${project.build.directory}/jacoco-unit.exec</dataFile>
                <outputDirectory>${project.reporting.outputDirectory}/jacoco-unit</outputDirectory>
              </configuration>
            </execution>
            <execution>
              <id>jacoco-check</id>
              <goals>
                <goal>check</goal>
              </goals>
              <configuration>
                <dataFile>${project.build.directory}/jacoco-unit.exec</dataFile>
                <rules />
              </configuration>
            </execution>
            <execution>
              <!-- Combine the code coverage statistics generated for the unit and the integration tests. -->
              <id>jacoco-merge</id>
              <goals>
                <goal>merge</goal>
              </goals>
              <phase>verify</phase>
              <configuration>
                <fileSets>
                  <fileSet>
                    <directory>${project.build.directory}</directory>
                    <includes>
                      <include>*.exec</include>
                    </includes>
                  </fileSet>
                </fileSets>
                <destFile>${project.build.directory}/jacoco-both.exec</destFile>
              </configuration>
            </execution>
            <execution>
              <id>jacoco-integration</id>
              <goals>
                <goal>report-integration</goal>
              </goals>
            </execution>
            <execution>
              <id>jacoco-reportboth</id>
              <goals>
                <goal>report</goal>
              </goals>
              <configuration>
                <dataFile>${project.build.directory}/jacoco-both.exec</dataFile>
                <outputDirectory>${project.reporting.outputDirectory}/jacoco-both</outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>

        <plugin>
          <!-- Help with license headers. This will stop the build if required headers are missing.
               `mvn license:format` inserts the Apache 2 license headers automatically. -->
          <groupId>com.mycila</groupId>
          <artifactId>license-maven-plugin</artifactId>
          <version>${license.plugin.version}</version>
          <configuration>
            <header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
            <properties>
              <owner>Lable</owner>
              <email>info@lable.nl</email>
            </properties>
            <mapping>
              <!-- Instead of the default JAVADOC_STYLE, because Javadoc comments
                   are not allowed at the start of file. -->
              <java>SLASHSTAR_STYLE</java>
            </mapping>
            <excludes>
              <exclude>**/README.md</exclude>
              <exclude>LICENSE</exclude>
              <exclude>src/test/resources/**</exclude>
              <exclude>src/main/resources/**</exclude>
            </excludes>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>check</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <profile>
      <!-- Release profile. These plugins only need to be run when artifacts are released. -->
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <!-- Sign our artifacts. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>${maven.gpg.plugin.version}</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <!-- Generate javadoc and create javadocs jars. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>${maven.javadoc.plugin.version}</version>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

