<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.choonchernlim</groupId>
    <artifactId>build-reports</artifactId>
    <version>0.2.2</version>
    <packaging>pom</packaging>

    <name>Build Reports</name>
    <description>Parent POM for generating build reports for CI servers, pushing artifacts to Sonatype OSSRH and site
        documentation to GitHub
    </description>
    <url>https://github.com/choonchernlim/build-reports</url>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>http://www.opensource.org/licenses/mit-license.php</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>choonchernlim</id>
            <name>Choon-Chern Lim</name>
            <email>choonchernlim@gmail.com</email>
            <url>https://github.com/choonchernlim</url>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git@github.com:choonchernlim/build-reports.git</connection>
        <developerConnection>scm:git:git@github.com:choonchernlim/build-reports.git</developerConnection>
        <url>git@github.com:choonchernlim/build-reports.git</url>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <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-site-plugin.version>3.4</maven-site-plugin.version>
        <jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version>
        <maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
        <maven-project-info-reports-plugin.version>2.8</maven-project-info-reports-plugin.version>
        <maven-surefire-report-plugin.version>2.18.1</maven-surefire-report-plugin.version>
        <maven-jxr-plugin.version>2.5</maven-jxr-plugin.version>
        <jdepend-maven-plugin.version>2.0</jdepend-maven-plugin.version>
        <maven-pmd-plugin.version>3.5</maven-pmd-plugin.version>
        <!-- 3.x targets Java 7 -->
        <findbugs-maven-plugin.version>2.5.5</findbugs-maven-plugin.version>
        <taglist-maven-plugin.version>2.4</taglist-maven-plugin.version>
        <nexus-staging-maven-plugin.version>1.6.5</nexus-staging-maven-plugin.version>
        <maven-source-plugin.version>2.4</maven-source-plugin.version>
        <site-maven-plugin.version>0.12</site-maven-plugin.version>
        <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>

        <jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.reportPath>
        <jacoco.itReportPath>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.itReportPath>

        <!--
        Instructs Sonar to reuse reports and configure the report paths for unit tests and code coverage.
        -->
        <sonar.language>java</sonar.language>
        <sonar.exclusions>**/generated/**,**/scratch/**</sonar.exclusions>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.junit.reportsPath>${project.build.directory}/surefire-reports</sonar.junit.reportsPath>
        <sonar.jacoco.reportPath>${jacoco.reportPath}</sonar.jacoco.reportPath>
        <sonar.jacoco.itReportPath>${jacoco.itReportPath}</sonar.jacoco.itReportPath>
    </properties>

    <build>
        <plugins>
            <!--
            Surefire Maven Plugin - Runs unit tests.
            http://maven.apache.org/surefire/maven-surefire-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <!-- Sets JaCoCo's VM argument line when unit tests run. -->
                    <!--suppress MavenModelInspection -->
                    <argLine>${surefireArgLine}</argLine>

                    <!-- Redirect JBoss logging to SLF4J -->
                    <systemPropertyVariables>
                        <org.jboss.logging.provider>slf4j</org.jboss.logging.provider>
                    </systemPropertyVariables>

                    <!-- The first 3 patterns are SureFire's default. Adding Spock's `*Spec` default pattern. -->
                    <includes>
                        <include>**/Test*.class</include>
                        <include>**/*Test.class</include>
                        <include>**/*TestCase.class</include>
                        <include>**/*Spec.class</include>
                    </includes>
                </configuration>
            </plugin>

            <!--
            Maven Failsafe Plugin - Runs integration tests.
            http://maven.apache.org/surefire/maven-failsafe-plugin/
            -->
            <plugin>
                <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>
                        <configuration>
                            <!-- Sets JaCoCo's VM argument line when integration tests run. -->
                            <!--suppress MavenModelInspection -->
                            <argLine>${failsafeArgLine}</argLine>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
            Maven Site Plugin - Generates site.
            http://maven.apache.org/plugins/maven-site-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>${maven-site-plugin.version}</version>
                <configuration>
                    <relativizeDecorationLinks>false</relativizeDecorationLinks>
                </configuration>
                <executions>
                    <!--
                    In Maven 3, site:attach-descriptor has been removed from the built-in lifecycle bindings,
                    so need to explicitly define `attach-descriptor` goal to pick up src/site/site.xml.
                    -->
                    <execution>
                        <id>attach-descriptor</id>
                        <goals>
                            <goal>attach-descriptor</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--
            JaCoCo Maven Plugin - Code coverage report for JVM languages.
            http://www.eclemma.org/jacoco/
            -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <configuration>
                    <excludes>
                        <exclude>**/generated/**</exclude>
                        <exclude>**/scratch/**</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <!--
                    Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument
                    when Maven the Surefire plugin is executed.
                    -->
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${jacoco.reportPath}</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <!--
                    Ensures that the code coverage report for unit tests is created after unit tests have been run.
                    -->
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${jacoco.reportPath}</dataFile>
                        </configuration>
                    </execution>
                    <!--
                    Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument when
                    Maven the Failsafe plugin is executed.
                    -->
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${jacoco.itReportPath}</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
                            <propertyName>failsafeArgLine</propertyName>
                        </configuration>
                    </execution>
                    <!--
                    Ensures that the code coverage report for integration tests after integration tests have been run.
                    -->
                    <execution>
                        <id>post-integration-test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${jacoco.itReportPath}</dataFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <!--
            Maven Project Info Reports Plugin - Generates reports information about the project.
            https://maven.apache.org/plugins/maven-project-info-reports-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>${maven-project-info-reports-plugin.version}</version>
                <configuration>
                    <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
                    <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                </configuration>
            </plugin>

            <!--
            Maven Surefire Reports Plugin - Parses generated test results from both unit tests and integration tests.
            http://maven.apache.org/surefire/maven-surefire-report-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>${maven-surefire-report-plugin.version}</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>failsafe-report-only</report>
                            <report>report-only</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>

            <!--
            JaCoCo Maven Plugin - Code coverage report for JVM languages.
            http://www.eclemma.org/jacoco/
            -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <configuration>
                    <dataFile>${jacoco.reportPath}</dataFile>
                </configuration>
            </plugin>

            <!--
            Maven Javadoc Plugin - Generates Javadoc.
            https://maven.apache.org/plugins/maven-javadoc-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>${maven-javadoc-plugin.version}</version>
            </plugin>

            <!--
            Maven JXR Plugin - Generates a cross-reference of the project's sources.
            http://maven.apache.org/plugins/maven-jxr-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>${maven-jxr-plugin.version}</version>
            </plugin>

            <!--
            JDepend Maven Plugin - Generates design quality metrics for each Java package.
            http://www.mojohaus.org/jdepend-maven-plugin/
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jdepend-maven-plugin</artifactId>
                <version>${jdepend-maven-plugin.version}</version>
            </plugin>

            <!--
            Maven PMD Plugin - Generates PMD and CPD reports.
            http://maven.apache.org/plugins/maven-pmd-plugin/
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${maven-pmd-plugin.version}</version>
                <configuration>
                    <!--suppress MavenModelInspection -->
                    <targetJdk>${jdk.version}</targetJdk>
                    <excludes>
                        <exclude>**/generated/**</exclude>
                        <exclude>**/scratch/**</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <!--
            FindBugs Maven Plugin - Inspects Java bytecode for occurrences of bug patterns.
            http://www.mojohaus.org/findbugs-maven-plugin/
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>${findbugs-maven-plugin.version}</version>
                <configuration>
                    <xmlOutput>true</xmlOutput>
                </configuration>
            </plugin>

            <!--
            TagList Maven Plugin - Generates a report on various tags found in the code.
            http://www.mojohaus.org/taglist-maven-plugin/
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>taglist-maven-plugin</artifactId>
                <version>${taglist-maven-plugin.version}</version>
                <configuration>
                    <tagListOptions>
                        <tagClasses>
                            <tagClass>
                                <displayName>Todo</displayName>
                                <tags>
                                    <tag>
                                        <matchString>todo</matchString>
                                        <matchType>ignoreCase</matchType>
                                    </tag>
                                    <tag>
                                        <matchString>FIXME</matchString>
                                        <matchType>exact</matchType>
                                    </tag>
                                </tags>
                            </tagClass>
                            <tagClass>
                                <displayName>Cleanup</displayName>
                                <tags>
                                    <tag>
                                        <matchString>@deprecated</matchString>
                                        <matchType>exact</matchType>
                                    </tag>
                                </tags>
                            </tagClass>
                        </tagClasses>
                    </tagListOptions>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

    <profiles>
        <!--
        `external-release` profile pushes binary, source code and javadoc to Sonatype OSSRH and generated site to GitHub.
        -->
        <profile>
            <id>external-release</id>
            <build>
                <plugins>
                    <!--
                    Nexus Staging Maven Plugin - Deploys to Sonatype OSSRH.
                    https://github.com/sonatype/nexus-maven-plugins/tree/master/staging/maven-plugin
                    -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>${nexus-staging-maven-plugin.version}</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>

                    <!--
                    Maven Source Plugin - Generates source code.
                    https://maven.apache.org/plugins/maven-source-plugin/
                    -->
                    <plugin>
                        <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>
                    </plugin>

                    <!--
                    GitHub Site Plugin - Generates Maven site in project GitHub page.
                    https://github.com/github/maven-plugins
                    -->
                    <plugin>
                        <groupId>com.github.github</groupId>
                        <artifactId>site-maven-plugin</artifactId>
                        <version>${site-maven-plugin.version}</version>
                        <configuration>
                            <message>Creating site for ${project.version}</message>
                            <server>github</server>
                            <!--
                            Need to disable Jekyll because JaCoCo static files are stored in `.resources` directory.
                            -->
                            <noJekyll>true</noJekyll>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>site</goal>
                                </goals>
                                <phase>site</phase>
                            </execution>
                        </executions>
                    </plugin>

                    <!--
                    Maven Javadoc Plugin - Generates Javadoc.
                    https://maven.apache.org/plugins/maven-javadoc-plugin/
                    -->
                    <plugin>
                        <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>

                    <!--
                    Maven GPG Plugin - Signs all of the project's attached artifacts with GnuPG..
                    http://maven.apache.org/plugins/maven-gpg-plugin/
                    -->
                    <plugin>
                        <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>
                </plugins>
            </build>

            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
            </distributionManagement>
        </profile>
    </profiles>
</project>