<?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>65.1</version>
        <relativePath>../kitei-build-root</relativePath>
    </parent>

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

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

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

        <dep.kitei-rules.version>65.1</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>

        <kitei.check.skip-sbom>${basepom.check.skip-extended}</kitei.check.skip-sbom>

        <dep.plugin.cyclonedx.version>2.9.1</dep.plugin.cyclonedx.version>
        <dep.plugin.sonar.version>5.2.0.4988</dep.plugin.sonar.version>
        <dep.plugin.njord.version>0.8.4</dep.plugin.njord.version>
    </properties>

    <!-- for njord deployment -->
    <distributionManagement>
        <snapshotRepository>
            <name>Central Snapshots</name>
            <id>${basepom.deploy.snapshot.repo-id}</id>
            <url>${basepom.deploy.snapshot.url}</url>
        </snapshotRepository>
        <repository>
            <name>Central Releases</name>
            <id>${basepom.central-publishing.repo-id}</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </distributionManagement>

    <build>
        <extensions>
            <extension>
                <groupId>eu.maveniverse.maven.njord</groupId>
                <artifactId>extension3</artifactId>
                <version>${dep.plugin.njord.version}</version>
            </extension>
        </extensions>
        <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>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <configuration>
                        <rules>
                            <!-- releases must be built with Java 21 or better -->
                            <requireJavaVersion>
                                <version>[21,)</version>
                            </requireJavaVersion>
                        </rules>
                    </configuration>
                </plugin>

                <!-- 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>

                <plugin>
                    <groupId>org.cyclonedx</groupId>
                    <artifactId>cyclonedx-maven-plugin</artifactId>
                    <version>${dep.plugin.cyclonedx.version}</version>
                    <configuration>
                        <skip>${kitei.check.skip-sbom}</skip>
                        <skipNotDeployed>false</skipNotDeployed>
                        <includeTestScope>false</includeTestScope>
                        <includeLicenseText>false</includeLicenseText>
                        <outputReactorProjects>true</outputReactorProjects>
                        <outputFormat>all</outputFormat>
                        <outputName>bom</outputName>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>eu.maveniverse.maven.plugins</groupId>
                    <artifactId>njord</artifactId>
                    <version>${dep.plugin.njord.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>kitei.enforce-java21</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </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.release</id>
            <properties>
                <basepom.check.skip-all>true</basepom.check.skip-all>
                <basepom.check.skip-enforcer>false</basepom.check.skip-enforcer>
                <kitei.check.skip-sbom>false</kitei.check.skip-sbom>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.cyclonedx</groupId>
                        <artifactId>cyclonedx-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>cyclonedx</id>
                                <goals>
                                    <goal>makeBom</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <!-- Profile to skip time-consuming steps. -->
            <id>kitei.fast</id>
            <properties>
                <basepom.check.skip-all>true</basepom.check.skip-all>
                <skipITs>true</skipITs>
                <skipTests>true</skipTests>
            </properties>
        </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>
