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

  <parent>
    <groupId>nz.net.osnz.parent</groupId>
    <artifactId>central-parent</artifactId>
    <version>6.2</version>
  </parent>

  <artifactId>java-parent</artifactId>
  <version>6.2</version>
  <packaging>pom</packaging>

  <name>Open Source New Zealand - Central Java Parent</name>
  <description>This is the central java artifact for all java-based projects.</description>
  <url>https://github.com/OpenSourceNZ/java-parent</url>

  <properties>
    <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
    <compile.plugin.debug>false</compile.plugin.debug>
    <compile.plugin.optimize>true</compile.plugin.optimize>
    <java.version>1.8</java.version>

    <skip.integration.tests>false</skip.integration.tests>
    <unit.test />
    <javadoc.opts>-Xdoclint:none</javadoc.opts>
    <sonar.language>java</sonar.language>

    <maven-source-plugin.version>3.0.1</maven-source-plugin.version>
    <maven-surefire-plugin.version>3.0.0-M3</maven-surefire-plugin.version>
    <maven-failsafe-plugin.version>3.0.0-M3</maven-failsafe-plugin.version>
  </properties>

  <build>
    <plugins>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.3</version>
        <executions>
          <execution>
            <id>prepare-agent</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!--
				Exclude integration and functional tests in the normal test phase.
				Integration tests are run in a separate surefire run in the test
				phase; functional tests are run later via the failsafe plugin.
			  -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
          <useSystemClassLoader>true</useSystemClassLoader>
          <useManifestOnlyJar>false</useManifestOnlyJar>
          <failIfNoTests>false</failIfNoTests>
          <includes>
            <include>**/*Test.java</include>
            <include>**/*Tests.java</include>
          </includes>
          <excludes>
            <exclude>**/*$*</exclude>
            <exclude>**/*IntegrationTest.java</exclude>
            <exclude>**/*IntegrationTests.java</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <id>integration-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <skipTests>${skip.integration.tests}</skipTests>
              <includes>
                <include>**/*IntegrationTest.java</include>
                <include>**/*IntegrationTests.java</include>
              </includes>
              <excludes>
                <exclude>**/*$*</exclude>
              </excludes>
              <test>${unit.test}</test>
              <!-- specify -Dunit.test=testname to run individual test -->
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${maven-failsafe-plugin.version}</version>
        <configuration>
          <argLine>-Xms1024M -Xmx1024M</argLine>
          <failIfNoTests>false</failIfNoTests>
          <encoding>${project.build.sourceEncoding}</encoding>
          <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
          <summaryFile>${project.build.directory}/surefire-reports/failsafe-summary.xml</summaryFile>
          <skipTests>${skip.functional.tests}</skipTests>
          <excludes>
            <exclude>**/*$*</exclude>
          </excludes>
          <includes>
            <include>**/*FunctionalTest.java</include>
            <include>**/*FunctionalTests.java</include>
          </includes>
          <test>${ft.test}</test>
        </configuration>
        <executions>
          <execution>
            <id>functional-test</id>
            <goals>
              <goal>integration-test</goal>
            </goals>
          </execution>
          <execution>
            <id>verify</id>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

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

    </plugins>
  </build>


  <profiles>
    <profile>
      <id>release</id>

      <activation>
        <property>
          <name>performRelease</name>
          <value>false</value>
        </property>
      </activation>

      <build>
        <plugins>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>${maven-source-plugin.version}</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <phase>package</phase>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
                <configuration>
                  <additionalparam>${javadoc.opts}</additionalparam>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>

    </profile>
  </profiles>

  <scm>
    <url>https://github.com/OpenSourceNZ/java-parent</url>
    <connection>scm:git:git@github.com/OpenSourceNZ/java-parent.git</connection>
    <developerConnection>scm:git:git@github.com:OpenSourceNZ/java-parent.git</developerConnection>
    <tag>java-parent-6.2</tag>
  </scm>

</project>
