<?xml version="1.0" encoding="UTF-8"?>
<!--
~   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>

    <parent>
        <groupId>org.kitei.internal</groupId>
        <artifactId>kitei-build-root</artifactId>
        <version>15</version>
        <relativePath>../kitei-build-root</relativePath>
    </parent>

    <groupId>org.kitei</groupId>
    <artifactId>kitei-root</artifactId>
    <packaging>pom</packaging>

    <name>kitei :: root</name>
    <!--
        <description>Kitei root for external projects</description>
    -->

    <properties>
        <project.build.targetJdk>17</project.build.targetJdk>
        <project.build.systemJdk>[17,)</project.build.systemJdk>

        <dep.kitei-rules.version>15</dep.kitei-rules.version>

        <!-- multi-module projects should deploy at the end -->
        <basepom.at-end.deploy>true</basepom.at-end.deploy>
        <basepom.at-end.install>false</basepom.at-end.install>

        <!-- only level 5 pmd allows the builds to pass. -->
        <basepom.pmd.fail-level>4</basepom.pmd.fail-level>

        <!-- fail on all checkstyle violations -->
        <basepom.check.checkstyle-severity>warning</basepom.check.checkstyle-severity>

        <!-- do not fail on javadoc errors -->
        <basepom.check.fail-javadoc>false</basepom.check.fail-javadoc>

        <dep.plugin.sonar.version>3.10.0.2594</dep.plugin.sonar.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Load the pmd rules from the kitei-rules jar -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>org.kitei</groupId>
                            <artifactId>kitei-rules</artifactId>
                            <version>${dep.kitei-rules.version}</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <rulesets>
                            <ruleset>pmd/kitei.xml</ruleset>
                        </rulesets>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>org.kitei</groupId>
                            <artifactId>kitei-rules</artifactId>
                            <version>${dep.kitei-rules.version}</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <configLocation>checkstyle/kitei.xml</configLocation>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>com.github.spotbugs</groupId>
                    <artifactId>spotbugs-maven-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>org.kitei</groupId>
                            <artifactId>kitei-rules</artifactId>
                            <version>${dep.kitei-rules.version}</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <excludeFilterFile>spotbugs/kitei-exclusions.xml</excludeFilterFile>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <author>false</author>
                    <detectJavaApiLink>true</detectJavaApiLink>
                    <linksource>true</linksource>
                    <nodeprecated>false</nodeprecated>
                    <nohelp>true</nohelp>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

    <profiles>
        <profile>
            <id>kitei.java21</id>
            <activation>
                <jdk>[21,)</jdk>
            </activation>
            <properties>
                <!-- see https://github.com/mockito/mockito/issues/3037 -->
                <basepom.it.arguments>-XX:+EnableDynamicAgentLoading</basepom.it.arguments>
                <basepom.test.arguments>-XX:+EnableDynamicAgentLoading</basepom.test.arguments>
            </properties>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                <!-- see https://inside.java/2023/07/29/quality-heads-up/ -->
                                <proc>full</proc>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>kitei.jpms-main-auto-module</id>
            <activation>
                <property>
                    <name>packaging</name>
                    <value>jar</value>
                </property>
                <file>
                    <missing>src/main/java/module-info.java</missing>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>jdbi.enforce-main-module-name</id>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <requireProperty>
                                            <property>project.moduleName</property>
                                            <message>This module must set a moduleName for the main artifact.</message>
                                        </requireProperty>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-jar</id>
                                <!-- add module name to main artifact -->
                                <configuration>
                                    <archive>
                                        <manifestEntries combine.children="append">
                                            <Automatic-Module-Name>${project.moduleName}</Automatic-Module-Name>
                                        </manifestEntries>
                                    </archive>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>kitei.jpms-test-auto-module</id>
            <activation>
                <property>
                    <name>packaging</name>
                    <value>jar</value>
                </property>
                <file>
                    <missing>src/test/java/module-info.java</missing>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>jdbi.enforce-test-module-name</id>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <requireProperty>
                                            <property>project.moduleName</property>
                                            <message>This module must set a moduleName for the test artifact.</message>
                                        </requireProperty>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>basepom.default</id>
                                <!-- add module name with "test" appended to tests artifact -->
                                <configuration>
                                    <archive>
                                        <manifestEntries combine.children="append">
                                            <Automatic-Module-Name>${project.moduleName}.tests</Automatic-Module-Name>
                                        </manifestEntries>
                                    </archive>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>kitei.sonar</id>
            <properties>
                <sonar.host.url>https://sonarcloud.io</sonar.host.url>
                <sonar.java.checkstyle.reportPaths>target/checkstyle-result.xml</sonar.java.checkstyle.reportPaths>
                <sonar.java.pmd.reportPaths>target/pmd.xml</sonar.java.pmd.reportPaths>
                <sonar.java.spotbugs.reportPaths>target/spotbugsXml.xml</sonar.java.spotbugs.reportPaths>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>sonar</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <phase>verify</phase>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.sonarsource.scanner.maven</groupId>
                        <artifactId>sonar-maven-plugin</artifactId>
                        <version>${dep.plugin.sonar.version}</version>
                        <executions>
                            <execution>
                                <id>sonar</id>
                                <goals>
                                    <goal>sonar</goal>
                                </goals>
                                <phase>verify</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
