<?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>dev.sympho</groupId>
    <artifactId>bot-utils</artifactId>
    <version>0.2.1</version>

    <name>bot-utils</name>
    <description>Utilities for Discord bots that use Discord4J</description>
    <url>https://bot-utils.sympho.dev</url>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/licenses/MIT</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>tmarback</id>
            <name>Thiago Marback</name>
            <email>tmarback@sympho.dev</email>
            <url>https://www.github.com/tmarback</url>
            <roles>
                <role>architect</role>
                <role>developer</role>
            </roles>
            <timezone>America/Los_Angeles</timezone>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/tmarback/bot-utils.git</connection>
        <developerConnection>scm:git:ssh://git@github.com/tmarback/bot-utils.git</developerConnection>
        <tag>v0.2.1</tag>
        <url>https://github.com/tmarback/bot-utils/tree/main</url>
    </scm>

    <issueManagement>
        <system>GitHub</system>
        <url>https://github.com/tmarback/bot-utils/issues</url>
    </issueManagement>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>17</maven.compiler.release>
        <checker.version>3.39.0</checker.version> <!-- Version of the Checker framework used -->
        <d4j.version>3.2.6</d4j.version> <!-- Version of Discord4J used -->
        <reporter.version>1.2.1</reporter.version> <!-- Version of the tree reporter used -->
        <!-- Settings for generated helper jars -->
        <helpers.source>${project.basedir}/helpers</helpers.source>
        <helpers.build>${project.build.directory}/helpers/jars</helpers.build>
        <helpers.repository>${project.build.directory}/helpers/repository</helpers.repository>
        <helpers.jar.checker>checker</helpers.jar.checker>
    </properties>

    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.10.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-bom</artifactId>
                <version>5.6.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>dev.sympho</groupId>
            <artifactId>reactor-utils</artifactId>
            <version>0.2.1</version>
        </dependency>

        <dependency>
            <groupId>dev.sympho</groupId>
            <artifactId>d4j-encoding-extra</artifactId>
            <version>0.1.1</version>
        </dependency>

        <dependency>
            <groupId>com.discord4j</groupId>
            <artifactId>discord4j-core</artifactId>
            <version>${d4j.version}</version>
            <exclusions>

                <exclusion>
                    <groupId>com.austinv11.servicer</groupId>
                    <artifactId>Servicer</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.discord4j</groupId>
            <artifactId>discord-json-encoding</artifactId>
            <version>1.7.7</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.13.0</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.15.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.9</version>
        </dependency>

        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <version>${checker.version}</version>
        </dependency>

        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-util</artifactId>
            <version>${checker.version}</version>
        </dependency>

        <dependency>
            <!-- the annotation processor, compile only -->
            <groupId>org.immutables</groupId>
            <artifactId>value</artifactId>
            <version>2.10.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Testing dependencies -->

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.24.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- Make the compiler shut up about JSR305 tags -->

        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>3.0.2</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <!-- Plugin versions and global configs -->
        <pluginManagement>
            <plugins>

                <!-- tools -->
                <plugin>
                    <artifactId>maven-help-plugin</artifactId>
                    <version>3.4.0</version>
                </plugin>

                <plugin>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>3.0.1</version>
                </plugin>
            
                <!-- clean lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.3.2</version>
                </plugin>
                
                <!-- default lifecycle -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.3.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.11.0</version>
                    <configuration>
                        <!-- Without showWarnings and verbose, maven-compiler-plugin may not show output. -->
                        <showWarnings>true</showWarnings>
                        <!-- <verbose>true</verbose> -->
                    </configuration>
                </plugin>

                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>

                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.3.0</version>
                </plugin>

                <plugin>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.6.0</version>
                    <configuration>
                        <tags>
                            <!-- Enable unofficial specification tags -->
                            <tag>
                                <name>apiNote</name>
                                <placement>a</placement>
                                <head>API Note:</head>
                            </tag>

                            <tag>
                                <name>implSpec</name>
                                <placement>a</placement>
                                <head>Implementation Requirements:</head>
                            </tag>

                            <tag>
                                <name>implNote</name>
                                <placement>a</placement>
                                <head>Implementation Note:</head>
                            </tag>

                        </tags>
                        <links>
                            <link>https://checkerframework.org/api/</link>
                            <link>https://projectreactor.io/docs/core/release/api/</link>
                            <link>https://javadoc.io/doc/com.discord4j/discord4j-core/${d4j.version}/</link>
                            <link>https://javadoc.io/doc/com.discord4j/discord4j-common/${d4j.version}/</link>
                        </links>
                    </configuration>
                </plugin>

                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>

                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>3.1.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>3.1.1</version>
                </plugin>

                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.6.13</version>
                </plugin>
                
                <!-- site lifecycle -->
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.12.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.4.5</version>
                </plugin>

                <plugin>
                    <artifactId>maven-surefire-report-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-jxr-plugin</artifactId>
                    <version>3.3.1</version>
                </plugin>
                
                <!-- none or multiple lifecycles -->
                <plugin>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>3.3.1</version>
                    <configuration>
                        <configLocation>checkstyle.xml</configLocation>
                        <cacheFile>${project.build.directory}/checkstyle-cachefile</cacheFile>
                        <headerLocation>LICENSE</headerLocation>
                        <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    </configuration>
                    <dependencies>

                        <dependency>
                            <groupId>com.puppycrawl.tools</groupId>
                            <artifactId>checkstyle</artifactId>
                            <version>10.12.4</version>
                        </dependency>

                    </dependencies>
                </plugin>

            </plugins>
        </pluginManagement>
        <plugins>

            <!-- Release management -->
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                </configuration>
            </plugin>

            <!-- Unit tests -->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <dependencies>
                
                    <dependency>
                        <groupId>me.fabriciorby</groupId>
                        <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
                        <version>${reporter.version}</version>
                    </dependency>

                </dependencies>
                <configuration>
                    <!-- Tree output for tests -->
                    <reportFormat>plain</reportFormat>
                    <consoleOutputReporter>
                        <disable>true</disable>
                    </consoleOutputReporter>
                    <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter" />
                </configuration>
            </plugin>
            
            <!-- Integration tests -->
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <dependencies>

                    <dependency>
                        <groupId>me.fabriciorby</groupId>
                        <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
                        <version>${reporter.version}</version>
                    </dependency>

                </dependencies>
                <configuration>
                    <!-- Tree output for tests -->
                    <reportFormat>plain</reportFormat>
                    <consoleOutputReporter>
                        <disable>true</disable>
                    </consoleOutputReporter>
                    <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter" />
                </configuration>
                <executions>

                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>

        </plugins>
    </build>

    <reporting>
        <plugins>
    
            <!-- Test report generation -->
            <plugin>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <reportSets>
                    <reportSet>
                        <id>unit-tests</id>
                        <reports>
                            <report>report-only</report>
                        </reports>
                    </reportSet>
                    <reportSet>
                        <id>integration-tests</id>
                        <reports>
                            <report>failsafe-report-only</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
            
            <!-- Style report generation -->
            <plugin>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>checkstyle</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
            
            <!-- Generate cross-references -->
            <plugin>
                <artifactId>maven-jxr-plugin</artifactId>
            </plugin>

        </plugins>
    </reporting>

    <profiles>
    
        <!-- Deployment profile (required so these plugins are only used when deploying) -->
        <profile>
            <id>deploy</id>
            <build>
                <plugins>
                
                    <!-- Source plugin -->
                    <plugin>
                        <artifactId>maven-source-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Javadoc plugin -->
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- GPG plugin -->
                    <plugin>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <!-- GPG key used for signing -->
                                    <keyname>5D78F1920D7866C9D45ADEDCD41D85135C89131A</keyname>
                                    <!-- Prevent `gpg` from using pinentry programs -->
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>
        </profile>
        
        <!-- Deployment to OSSRH -->
        <profile>
            <id>ossrh</id>
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <name>OSSRH Snapshots</name>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
                <repository>
                    <id>ossrh</id>
                    <name>OSSRH Staging</name>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
            <build>
                <plugins>
        
                    <!-- Nexus Staging Plugin -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>
        
        <!-- Deployment to GitHub Packages -->
        <profile>
            <id>github</id>
            <distributionManagement>
                <snapshotRepository>
                    <id>github</id>
                    <name>GitHub Packages</name>
                    <url>https://maven.pkg.github.com/tmarback/bot-utils</url>
                </snapshotRepository>
                <repository>
                    <id>github</id>
                    <name>GitHub Packages</name>
                    <url>https://maven.pkg.github.com/tmarback/bot-utils</url>
                </repository>
            </distributionManagement>
        </profile>
        
        <!-- Stricter compiler checking -->
        <profile>
            <id>lint</id>
            <repositories>

                <repository>
                    <id>helpers</id>
                    <url>file:///${helpers.repository}</url>
                    <releases>
                        <checksumPolicy>ignore</checksumPolicy> <!-- Locally generated helper files, no checksum necessary -->
                    </releases>
                </repository>

            </repositories>
            <build>
                <plugins>

                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <executions>
                            
                            <!-- Remove compiled classes to ensure recompilation -->
                            <execution>
                                <id>clean-classes</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>clean</goal>
                                </goals>
                            </execution>

                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <executions>

                            <execution>
                                <id>generate-checker-config</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <classesDirectory>${helpers.source}/${helpers.jar.checker}</classesDirectory>
                                    <outputDirectory>${helpers.build}</outputDirectory>
                                    <classifier>${helpers.jar.checker}</classifier>
                                </configuration>
                            </execution>

                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <executions>

                            <execution>
                                <id>install-checker-config</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>install-file</goal>
                                </goals>
                                <configuration>
                                    <file>${helpers.build}/${project.build.finalName}-${helpers.jar.checker}.jar</file>
                                    <artifactId>checker</artifactId>
                                    <groupId>dev.sympho.helpers</groupId>
                                    <version>GENERATED</version>
                                    <packaging>jar</packaging>
                                    <generatePom>true</generatePom>
                                    <localRepositoryPath>${helpers.repository}</localRepositoryPath>
                                </configuration>
                            </execution>

                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>

                            <execution>
                                <id>pre-compile</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <showWarnings>false</showWarnings>
                                    <failOnWarning>false</failOnWarning>
                                </configuration>
                            </execution>

                            <execution>
                                <id>default-compile</id>
                                <configuration>
                                    <fork>true</fork> <!-- Must fork or else JVM arguments are ignored. -->
                                    <annotationProcessorPaths>
        
                                        <path>
                                            <groupId>org.checkerframework</groupId>
                                            <artifactId>checker</artifactId>
                                            <version>${checker.version}</version>
                                        </path>

                                        <!-- Include Checker configuration jar -->
                                        <path>
                                            <groupId>dev.sympho.helpers</groupId>
                                            <artifactId>checker</artifactId>
                                            <version>GENERATED</version>
                                        </path>
                                        
                                        <!-- Add previously compiled classes for extra checker functionality -->
                                        <path>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                        </path>

                                        <!-- To make SLF4J not complain about no providers -->
                                        <path>
                                            <groupId>org.slf4j</groupId>
                                            <artifactId>slf4j-simple</artifactId>
                                            <version>2.0.9</version>
                                        </path>
        
                                    </annotationProcessorPaths>
                                    <implicit>class</implicit>
                                    <compilerArgs>
                                        <!-- Increase maximum errors/warnings -->
                                        <arg>-Xmaxerrs</arg>
                                        <arg>10000</arg>
                                        <arg>-Xmaxwarns</arg>
                                        <arg>10000</arg>
                                        <!-- Configure linting and Checker -->
                                        <arg>-Xlint:all,-processing,-requires-transitive-automatic,-requires-automatic</arg>
                                        <!-- <arg>-AreportEvalWarns</arg> --> <!-- TODO: Too many issues for the time being -->
                                        <arg>-Astubs=./stubs</arg>
                                        <arg>-AstubWarnIfNotFoundIgnoresClasses</arg>
                                        <!-- Say which checker threw the error or warning -->
                                        <arg>-AshowPrefixInWarningMessages</arg>
                                        <!-- Manually open JDK packages until checker supports modules -->
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
                                        <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
                                        <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
                                    </compilerArgs>
                                </configuration>
                            </execution>

                        </executions>
                    </plugin>

                </plugins>
            </build>
        </profile>
        
        <!-- Style checking -->
        <profile>
            <id>style</id>
            <build>
                <plugins>

                    <plugin>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <configuration>
                            <consoleOutput>true</consoleOutput>
                            <linkXRef>false</linkXRef>
                        </configuration>
                        <executions>
                            <execution>
                                <id>validate</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>
        </profile>
        
        <!-- Do not allow warnings (compiler or style) -->
        <profile>
            <id>strict</id>
            <build>
                <plugins>

                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <failOnWarning>true</failOnWarning>
                        </configuration>
                    </plugin>

                    <plugin>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <configuration>
                            <violationSeverity>warning</violationSeverity>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>

    </profiles>

</project>
