<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>de.cuioss</groupId>
        <artifactId>cui-java-bom</artifactId>
        <version>1.2.2</version>
    </parent>

    <artifactId>cui-java-parent</artifactId>
    <packaging>pom</packaging>
    <name>cui java parent</name>
    <description>Parent pom for simple java-projects</description>

    <properties>
        <maven.jar.plugin.version>3.4.2</maven.jar.plugin.version>
        <maven.javadoc.plugin.version>3.11.3</maven.javadoc.plugin.version>
        <maven.javadoc.plugin.failOnError>true</maven.javadoc.plugin.failOnError>
        <!-- See https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet-->
        <maven.javadoc.plugin.doclint>html</maven.javadoc.plugin.doclint>
        <!-- See https://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html#legacymode -->
        <maven.javadoc.plugin.legacyMode>false</maven.javadoc.plugin.legacyMode>
        <!-- The automatic module name to be set. Must be corresponding to
            the one defined at module.info -->
        <maven.jar.plugin.automatic.module.name>
            ${project.groupId}.${project.artifactId}
        </maven.jar.plugin.automatic.module.name>
        <license-maven-plugin.version>5.0.0</license-maven-plugin.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven.javadoc.plugin.version}</version>
                    <configuration>
                        <sourcepath>src/main/java</sourcepath>
                        <release>${maven.compiler-plugin.release}</release>
                        <linksource>true</linksource>
                        <quiet>true</quiet>
                        <notimestamp>true</notimestamp>
                        <splitindex>true</splitindex>
                        <doctitle>${project.name}</doctitle>
                        <!--https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html#BEJEFABE -->
                        <doclint>${maven.javadoc.plugin.doclint}</doclint>
                    </configuration>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven.jar.plugin.version}</version>
                    <configuration>
                        <excludes>
                            <exclude>**/log4j2.xml</exclude>
                            <!-- Exclude eclipse workspace files -->
                            <exclude>**/*.jsfdia</exclude>
                        </excludes>
                        <archive>
                            <index>true</index>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Automatic-Module-Name>
                                    ${maven.jar.plugin.automatic.module.name}
                                </Automatic-Module-Name>
                                <Build-Time>${project.build.outputTimestamp}</Build-Time>
                                <Build-User>${user.name}</Build-User>
                                <!--suppress UnresolvedMavenProperty -->
                                <Build-Maven>Maven ${maven.version}</Build-Maven>
                                <Build-Java>${java.version}</Build-Java>
                                <Build-OS>${os.name}</Build-OS>
                                <!--suppress UnresolvedMavenProperty -->
                                <Build-Number>${buildNumber}</Build-Number>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

    </build>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>buildnumber-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>io.smallrye</groupId>
                        <artifactId>jandex-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-release-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-site-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release-snapshot</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>buildnumber-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>io.smallrye</groupId>
                        <artifactId>jandex-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>javadoc</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>buildnumber-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>io.smallrye</groupId>
                        <artifactId>jandex-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                    </plugin>

                </plugins>
            </build>
        </profile>
        <profile>
            <id>sonar</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>@{argLine} -Xms64m -Xmx1024m</argLine>
                            <redirectTestOutputToFile>true</redirectTestOutputToFile>
                            <printSummary>true</printSummary>
                            <trimStackTrace>false</trimStackTrace>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.sonarsource.scanner.maven</groupId>
                        <artifactId>sonar-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- Usage: ./mvnw -Ppre-commit -->
            <!-- Combined profile that handles license headers, code formatting with OpenRewrite recipes, and javadoc creation -->
            <id>pre-commit</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.mycila</groupId>
                        <artifactId>license-maven-plugin</artifactId>
                        <version>${license-maven-plugin.version}</version>
                        <configuration>
                            <properties>
                                <year>2025</year>
                                <owner>CUI-OpenSource-Software</owner>
                                <email>info@cuioss.de</email>
                            </properties>
                            <mapping>
                                <java>SLASHSTAR_STYLE</java>
                            </mapping>
                            <licenseSets>
                                <licenseSet>
                                    <header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
                                    <includes>
                                        <include>src/main/java/**</include>
                                        <include>src/test/java/**</include>
                                    </includes>
                                </licenseSet>
                            </licenseSets>
                        </configuration>
                        <executions>
                            <execution>
                                <id>format-license-headers</id>
                                <phase>process-sources</phase>
                                <goals>
                                    <goal>format</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.openrewrite.maven</groupId>
                        <artifactId>rewrite-maven-plugin</artifactId>
                        <configuration>
                            <activeRecipes>
                                <!-- CUI-specific formatting and standards -->
                                <recipe>de.cuioss.rewrite.format.AnnotationNewlineFormat</recipe>
                                <recipe>de.cuioss.rewrite.logging.CuiLoggerStandardsRecipe</recipe>
                                <recipe>de.cuioss.rewrite.logging.CuiLogRecordPatternRecipe</recipe>
                                <recipe>de.cuioss.rewrite.logging.InvalidExceptionUsageRecipe</recipe>

                                <!-- Code formatting -->
                                <recipe>org.openrewrite.java.format.AutoFormat</recipe>
                                <recipe>org.openrewrite.java.format.NormalizeLineBreaks</recipe>
                                <recipe>org.openrewrite.java.format.RemoveTrailingWhitespace</recipe>

                                <!-- Java 21 migration and modernization -->
                                <recipe>org.openrewrite.java.migrate.UpgradeToJava21</recipe>

                                <!-- Modern Java language features -->
                                <recipe>org.openrewrite.java.migrate.lang.UseTextBlocks</recipe>
                                <recipe>org.openrewrite.java.migrate.lang.StringFormatted</recipe>
                                <recipe>org.openrewrite.staticanalysis.InstanceOfPatternMatch</recipe>

                                <!-- Utility method modernization -->
                                <recipe>org.openrewrite.java.migrate.util.JavaUtilAPIs</recipe>
                                <recipe>org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent</recipe>
                                <recipe>org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty</recipe>
                                <recipe>org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList</recipe>
                                <recipe>org.openrewrite.java.migrate.util.UseLocaleOf</recipe>
                                <recipe>org.openrewrite.java.migrate.util.UseMapOf</recipe>

                                <!-- Code organization -->
                                <recipe>org.openrewrite.java.OrderImports</recipe>
                                <recipe>org.openrewrite.java.RemoveUnusedImports</recipe>
                                <recipe>org.openrewrite.java.ShortenFullyQualifiedTypeReferences</recipe>

                                <!-- Testing improvements -->
                                <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
                                <recipe>org.openrewrite.java.testing.junit5.RemoveTryCatchFailBlocks</recipe>

                                <!-- Static analysis improvements -->
                                <recipe>org.openrewrite.staticanalysis.EqualsAvoidsNull</recipe>
                                <recipe>org.openrewrite.staticanalysis.NoPrimitiveWrappersForToStringOrCompareTo</recipe>
                                <recipe>org.openrewrite.staticanalysis.SimplifyBooleanExpression</recipe>
                                <recipe>org.openrewrite.staticanalysis.UnnecessaryParentheses</recipe>
                            </activeRecipes>
                            <!-- Exclude generated files from being processed -->
                            <exclusions>
                                <exclusion>target/**</exclusion>
                            </exclusions>
                            <runPerSubmodule>true</runPerSubmodule>
                        </configuration>
                        <executions>
                            <execution>
                                <id>rewrite</id>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>${maven.javadoc.plugin.version}</version>
                        <configuration>
                            <sourcepath>src/main/java</sourcepath>
                            <release>${maven.compiler-plugin.release}</release>
                            <linksource>true</linksource>
                            <quiet>true</quiet>
                            <notimestamp>true</notimestamp>
                            <splitindex>true</splitindex>
                            <doctitle>${project.name}</doctitle>
                            <doclint>${maven.javadoc.plugin.doclint}</doclint>
                        </configuration>
                        <executions>
                            <execution>
                                <id>check-javadocs-pre-commit</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>javadoc</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- Used for local coverage tests. An addition not replacement for the sonar build -->
            <id>coverage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <phase>test</phase>
                                <configuration>
                                    <formats>
                                        <format>XML</format>
                                        <format>HTML</format>
                                    </formats>
                                </configuration>
                            </execution>
                            <execution>
                                <id>check</id>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                                <phase>verify</phase>
                                <configuration>
                                    <rules>
                                        <rule>
                                            <element>BUNDLE</element>
                                            <limits>
                                                <limit>
                                                    <counter>INSTRUCTION</counter>
                                                    <value>COVEREDRATIO</value>
                                                    <minimum>0.80</minimum>
                                                </limit>
                                                <limit>
                                                    <counter>BRANCH</counter>
                                                    <value>COVEREDRATIO</value>
                                                    <minimum>0.80</minimum>
                                                </limit>
                                            </limits>
                                        </rule>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>${argLine}</argLine>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- TODO: Remove this profile in version 1.2.0 -->
            <!-- Temporary profile to clean up existing javadoc-style license headers -->
            <!-- Usage: ./mvnw -Plicense-cleanup -->
            <id>license-cleanup</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.mycila</groupId>
                        <artifactId>license-maven-plugin</artifactId>
                        <version>${license-maven-plugin.version}</version>
                        <configuration>
                            <properties>
                                <year>2025</year>
                                <owner>CUI-OpenSource-Software</owner>
                                <email>info@cuioss.de</email>
                            </properties>
                            <mapping>
                                <java>SLASHSTAR_STYLE</java>
                            </mapping>
                            <licenseSets>
                                <licenseSet>
                                    <header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
                                    <includes>
                                        <include>src/main/java/**</include>
                                        <include>src/test/java/**</include>
                                    </includes>
                                </licenseSet>
                            </licenseSets>
                        </configuration>
                        <executions>
                            <execution>
                                <id>remove-old-headers</id>
                                <phase>process-sources</phase>
                                <goals>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>format-new-headers</id>
                                <phase>process-sources</phase>
                                <goals>
                                    <goal>format</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
