<?xml version="1.0" encoding="UTF-8"?>
<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>com.github.maximevw</groupId>
    <artifactId>autolog</artifactId>
    <version>1.2.0</version>
    <packaging>pom</packaging>

    <name>Autolog</name>
    <description>Automatic logging for Java applications</description>
    <url>https://github.com/maximevw/autolog</url>
    <inceptionYear>2019</inceptionYear>

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

    <organization>
        <name>Maxime WIEWIORA</name>
    </organization>

    <developers>
        <developer>
            <name>Maxime WIEWIORA</name>
            <id>maximevw</id>
            <url>https://github.com/maximevw</url>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:https://github.com:maximevw/autolog.git</connection>
        <developerConnection>scm:git:git@github.com:maximevw/autolog.git</developerConnection>
        <url>https://github.com/maximevw/autolog</url>
    </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>

    <modules>
        <module>autolog-core</module>
        <module>autolog-aspectj</module>
        <module>autolog-spring</module>
        <module>autolog-coverage-reporting</module>
    </modules>

    <properties>
        <!-- Default encoding -->
        <encoding>UTF-8</encoding>

        <!-- Java version -->
        <java.version>11</java.version>

        <!-- Code coverage thresholds -->
        <jacoco.percentage.instruction>0.70</jacoco.percentage.instruction>
        <badge.jacoco.percentage.instruction>70</badge.jacoco.percentage.instruction>
        <jacoco.percentage.branch>0.80</jacoco.percentage.branch>

        <!-- OWASP scan report output directory -->
        <owasp.outputDirectory>${project.build.directory}/owasp</owasp.outputDirectory>
        <!-- OWASP suppression file -->
        <owasp.suppressionFile>owasp-suppressions.xml</owasp.suppressionFile>

        <!-- Delomboked source code directory -->
        <delombok.outputDirectory>${project.build.directory}/delombok</delombok.outputDirectory>

        <!-- JaCoCo report path -->
        <jacoco.reportPath>${project.basedir}/coverage</jacoco.reportPath>

        <!-- Dependencies and plugins versions management -->
        <apiguardian.version>1.1.0</apiguardian.version>
        <aspectj.version>1.9.5</aspectj.version>
        <checkstyle.version>8.36.2</checkstyle.version>
        <commons-lang.version>3.11</commons-lang.version>
        <commons-text.version>1.9</commons-text.version>
        <compile-testing.version>0.19</compile-testing.version>
        <guava.version>30.0-jre</guava.version>
        <hamcrest.version>2.2</hamcrest.version>
        <jackson-databind.version>2.11.3</jackson-databind.version>
        <jackson-dataformat-xml.version>2.11.3</jackson-dataformat-xml.version>
        <jacoco-maven-plugin.version>0.8.6</jacoco-maven-plugin.version>
        <jakarta-ws-rs.version>2.1.6</jakarta-ws-rs.version>
        <junit-jupiter.version>5.7.0</junit-jupiter.version>
        <junit-platform.version>1.7.0</junit-platform.version>
        <h2.version>1.4.200</h2.version>
        <license-maven-plugin.version>2.0.0</license-maven-plugin.version>
        <log4j2.version>2.13.3</log4j2.version>
        <logback.version>1.2.3</logback.version>
        <logstash-logback-encoder.version>6.4</logstash-logback-encoder.version>
        <lombok.version>1.18.16</lombok.version>
        <lombok-maven-plugin.version>1.18.16.0</lombok-maven-plugin.version>
        <maven-checkstyle-plugin.version>3.1.1</maven-checkstyle-plugin.version>
        <maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
        <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
        <maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
        <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
        <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
        <maven-source-plugin.version>3.2.1</maven-source-plugin.version>
        <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
        <mockito.version>3.5.15</mockito.version>
        <owasp-dependency-check.version>6.0.2</owasp-dependency-check.version>
        <slf4j.version>1.7.30</slf4j.version>
        <slf4j-test.version>1.2.0</slf4j-test.version>
        <spring.version>5.2.9.RELEASE</spring.version>
        <spring-boot.version>2.3.4.RELEASE</spring-boot.version>
        <velocity.version>1.7</velocity.version>
        <velocity-tools.version>2.0</velocity-tools.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons-lang.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-text</artifactId>
                <version>${commons-text.version}</version>
            </dependency>

            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>${aspectj.version}</version>
                <optional>true</optional>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${jackson-databind.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.dataformat</groupId>
                <artifactId>jackson-dataformat-xml</artifactId>
                <version>${jackson-dataformat-xml.version}</version>
            </dependency>

            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
            </dependency>

            <dependency>
                <groupId>jakarta.ws.rs</groupId>
                <artifactId>jakarta.ws.rs-api</artifactId>
                <version>${jakarta-ws-rs.version}</version>
                <optional>true</optional>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.version}</version>
                <optional>true</optional>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <version>${spring-boot.version}</version>
                <optional>true</optional>
            </dependency>

            <dependency>
                <groupId>org.apiguardian</groupId>
                <artifactId>apiguardian-api</artifactId>
                <version>${apiguardian.version}</version>
                <optional>true</optional>
            </dependency>

            <!-- Supported loggers -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-ext</artifactId>
                <version>${slf4j.version}</version>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>${log4j2.version}</version>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>${log4j2.version}</version>
                <optional>true</optional>
            </dependency>

            <!-- Logback and Logstash encoder-->
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>${logback.version}</version>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>net.logstash.logback</groupId>
                <artifactId>logstash-logback-encoder</artifactId>
                <version>${logstash-logback-encoder.version}</version>
                <optional>true</optional>
            </dependency>

            <!-- Velocity -->
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity</artifactId>
                <version>${velocity.version}</version>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity-tools</artifactId>
                <version>${velocity-tools.version}</version>
                <optional>true</optional>
            </dependency>

            <!-- Test dependencies -->
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>${mockito.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-junit-jupiter</artifactId>
                <version>${mockito.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>${junit-jupiter.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>${junit-jupiter.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-params</artifactId>
                <version>${junit-jupiter.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-runner</artifactId>
                <version>${junit-platform.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-commons</artifactId>
                <version>${junit-platform.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest</artifactId>
                <version>${hamcrest.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>uk.org.lidalia</groupId>
                <artifactId>slf4j-test</artifactId>
                <version>${slf4j-test.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${spring-boot.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
                <version>${spring-boot.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>com.google.testing.compile</groupId>
                <artifactId>compile-testing</artifactId>
                <version>${compile-testing.version}</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <artifactId>junit</artifactId>
                        <groupId>junit</groupId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>${h2.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Cleaning -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>${maven-clean-plugin.version}</version>
                </plugin>

                <!-- Delomboking source code (required to generate a correct Javadoc: indeed, Javadoc Maven plugin runs
                generate-sources goal prior to javadoc goal) -->
                <plugin>
                    <groupId>org.projectlombok</groupId>
                    <artifactId>lombok-maven-plugin</artifactId>
                    <version>${lombok-maven-plugin.version}</version>
                    <configuration>
                        <encoding>${encoding}</encoding>
                        <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
                        <outputDirectory>${delombok.outputDirectory}</outputDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <id>delombok</id>
                            <goals>
                                <goal>delombok</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Compilation -->
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <encoding>${encoding}</encoding>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <release>${java.version}</release>
                        <parameters>true</parameters>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                    </configuration>
                </plugin>

                <!-- Resources management -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven-resources-plugin.version}</version>
                    <configuration>
                        <encoding>${encoding}</encoding>
                    </configuration>
                </plugin>

                <!-- Enforcer -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>${maven-enforcer-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>enforce</id>
                            <goals>
                                <goal>enforce</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <banDuplicatePomDependencyVersions/>
                                    <reactorModuleConvergence/>
                                    <requireReleaseDeps/>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Tests running -->
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire-plugin.version}</version>
                </plugin>

                <!-- Licensing management -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>${license-maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>update-file-header</goal>
                            </goals>
                            <phase>process-sources</phase>
                            <configuration>
                                <encoding>${encoding}</encoding>
                                <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
                                <emptyLineAfterHeader>true</emptyLineAfterHeader>
                                <licenseName>apache_v2</licenseName>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Javadoc -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven-javadoc-plugin.version}</version>
                    <configuration>
                        <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                        <doclint>none</doclint>
                    </configuration>
                </plugin>

                <!-- Checkstyle -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>${maven-checkstyle-plugin.version}</version>
                    <dependencies>
                        <!-- Enforce the version of checkstyle used by the plugin. -->
                        <dependency>
                            <groupId>com.puppycrawl.tools</groupId>
                            <artifactId>checkstyle</artifactId>
                            <version>${checkstyle.version}</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <configLocation>checkstyle.xml</configLocation>
                        <consoleOutput>true</consoleOutput>
                        <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
                        <!-- Only apply the check to the original sources and not the generated ones (by delomboking
                        for example). -->
                        <sourceDirectories>${project.build.sourceDirectory}</sourceDirectories>
                        <!-- Also apply rules to test sources. -->
                        <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <id>checkstyle</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Code coverage -->
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco-maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <!-- By default, don't generate report for each module, the module
                                autolog-coverage-reporting will generate a global one. But, if required, the Maven
                                profile 'with-coverage-by-module' allows to generate a report for each module. -->
                                <skip>true</skip>
                            </configuration>
                        </execution>
                        <execution>
                            <id>check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <haltOnFailure>false</haltOnFailure>
                                <rules>
                                    <!-- Minimal percentage of covered branches -->
                                    <rule>
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit>
                                                <counter>BRANCH</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>${jacoco.percentage.branch}</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                    <!-- Minimal percentage of covered instructions -->
                                    <rule>
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit>
                                                <counter>INSTRUCTION</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>${jacoco.percentage.instruction}</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <!-- Building profiles -->
    <profiles>
        <!-- 'release' profile is used for releasing of stable versions only. -->
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <!-- Sources jar -->
                    <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</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Javadoc -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- GPG artifacts signing -->
                    <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>
                        <configuration>
                            <!-- Prevent `gpg` from using pinentry programs -->
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- 'bundle' profile creates jar including dependencies for each module and should be used for bundling of
        stable versions only. -->
        <profile>
            <id>bundle</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>${maven-shade-plugin.version}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <createSourcesJar>false</createSourcesJar>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <finalName>${project.artifactId}-${project.version}-bundle</finalName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- 'dependency-check' profile runs OWASP scan on specified modules when activated. -->
        <profile>
            <id>dependency-check</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.owasp</groupId>
                        <artifactId>dependency-check-maven</artifactId>
                        <version>${owasp-dependency-check.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>aggregate</goal>
                                </goals>
                                <!-- The scan runs globally for all the modules, so don't propagate the aggregation goal
                                 to the children modules. -->
                                <inherited>false</inherited>
                            </execution>
                        </executions>
                        <configuration>
                            <outputDirectory>${owasp.outputDirectory}</outputDirectory>
                            <suppressionFiles>
                                <suppressionFile>${owasp.suppressionFile}</suppressionFile>
                            </suppressionFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- 'with-coverage-by-module' profile activates the generation of a coverage report for each module of the
        project in addition of the aggregated one generated by the module autolog-coverage-reporting. -->
        <profile>
            <id>with-coverage-by-module</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>