<?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.2</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>http://lable.nl</url>
  </organization>

  <developers>
    <developer>
      <id>jdhoek</id>
      <name>Jeroen Hoek</name>
      <email>jeroen.hoek@lable.nl</email>
      <organization>Lable</organization>
      <organizationUrl>http://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.18.1</maven.surefire.plugin.version>
    <maven.failsafe.plugin.version>2.18.1</maven.failsafe.plugin.version>
    <maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
    <maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
    <maven.deploy.plugin.version>2.8.2</maven.deploy.plugin.version>
    <maven.release.plugin.version>2.5.2</maven.release.plugin.version>
    <maven.source.plugin.version>2.4</maven.source.plugin.version>
    <maven.javadoc.plugin.version>2.10.3</maven.javadoc.plugin.version>
    <license.plugin.version>2.11</license.plugin.version>
    <jacoco.plugin.version>0.7.5.201505241946</jacoco.plugin.version>

    <java.language.level>1.7</java.language.level>

    <!-- Dependency versions. -->
    <junit.version>4.12</junit.version>
    <hamcrest.version>1.3</hamcrest.version>
    <mockito.version>1.10.19</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.2</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-library</artifactId>
      <version>${hamcrest.version}</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-all</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>
          <source>${java.language.level}</source>
          <target>${java.language.level}</target>
          <compilerArgs>
            <arg>-Xlint</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>
          <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>
          <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>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <!-- Unit testing. -->
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven.surefire.plugin.version}</version>
        </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>
          <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>
            <excludes>
              <exclude>**/README.md</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>

