<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2024 Craig Motlin
  ~
  ~ 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>io.liftwizard</groupId>
        <artifactId>liftwizard-profile-parent</artifactId>
        <version>2.1.14</version>
        <relativePath>../liftwizard-profile-parent</relativePath>
    </parent>

    <artifactId>liftwizard-grandparent-build</artifactId>
    <packaging>pom</packaging>
    <name>Liftwizard Grandparent Build</name>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <maven.compiler.release>17</maven.compiler.release>
    </properties>

    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>io.liftwizard</groupId>
                <artifactId>liftwizard-dependencies</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>

        <pluginManagement>
            <plugins>

                <!--region Phase 3: generate-sources-->
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!--endregion-->

                <!--region Phase 3: generate-sources-->
                <plugin>
                    <groupId>org.antlr</groupId>
                    <artifactId>antlr4-maven-plugin</artifactId>
                    <version>4.9.3</version>
                    <configuration>
                        <listener>true</listener>
                        <visitor>true</visitor>
                        <treatWarningsAsErrors>true</treatWarningsAsErrors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>antlr</id>
                            <goals>
                                <goal>antlr4</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!--endregion-->

                <!--region Phase 3: generate-sources through Phase 17: package-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-plugin-plugin</artifactId>
                    <version>3.13.1</version>
                    <executions>
                        <execution>
                            <id>mojo-descriptor</id>
                            <goals>
                                <goal>descriptor</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>help-goal</id>
                            <goals>
                                <goal>helpmojo</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!--endregion-->

                <!--region Phase 4: process-sources-->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>3.6.0</version>
                </plugin>
                <!--endregion-->

                <!--region Phase 7: compile-->
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>com.google.auto.service</groupId>
                                <artifactId>auto-service</artifactId>
                                <version>1.0.1</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
                <!--endregion-->

            </plugins>
        </pluginManagement>

        <plugins>

            <!--region No phase-->

            <!--mvn rewrite:run-->
            <!--mvn rewrite:dryRun-->
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>5.35.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-static-analysis</artifactId>
                        <version>1.11.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-migrate-java</artifactId>
                        <version>2.19.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-testing-frameworks</artifactId>
                        <version>2.13.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-logging-frameworks</artifactId>
                        <version>2.10.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.openrewrite.recipe</groupId>
                        <artifactId>rewrite-apache</artifactId>
                        <version>1.4.2</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!--endregion-->

            <!--region Phase 1: validate-->
            <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>
            <!--endregion-->

        </plugins>
    </build>

    <profiles>

        <!--region No phase-->
        <profile>
            <!--Rules that are meant to always pass. They can run in CI with dryRun, or one-off for rewrites.-->
            <id>rewrite-maven-plugin</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.openrewrite.maven</groupId>
                            <artifactId>rewrite-maven-plugin</artifactId>
                            <configuration>
                                <activeRecipes>
                                    <recipe>org.openrewrite.java.logging.slf4j.LoggersNamedForEnclosingClass</recipe>
                                    <recipe>org.openrewrite.java.logging.slf4j.Slf4jLogShouldBeConstant</recipe>

                                    <recipe>org.openrewrite.apache.commons.codec.ApacheBase64ToJavaBase64</recipe>
                                    <recipe>org.openrewrite.apache.commons.io.ApacheCommonsFileUtilsRecipes</recipe>
                                    <recipe>org.openrewrite.apache.commons.lang.ApacheCommonsStringUtilsRecipes</recipe>
                                </activeRecipes>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>

        <profile>
            <!--Rules that don't reliably pass. They can't run in CI with dryRun, only one-off for rewrites.-->
            <id>rewrite-maven-plugin-one-off</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.openrewrite.maven</groupId>
                            <artifactId>rewrite-maven-plugin</artifactId>
                            <configuration>
                                <activeRecipes>
                                    <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
                                    <recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
                                </activeRecipes>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>

        <profile>
            <id>rewrite-maven-plugin-dryRun</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.openrewrite.maven</groupId>
                            <artifactId>rewrite-maven-plugin</artifactId>
                            <configuration>
                                <failOnDryRunResults>true</failOnDryRunResults>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>OpenRewrite dry run</id>
                                    <goals>
                                        <goal>dryRunNoFork</goal>
                                    </goals>
                                    <phase>verify</phase>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <!--endregion-->

        <!--region Phase 1: validate-->
        <profile>
            <id>maven-enforcer-plugin</id>

            <build>
                <plugins>

                    <plugin>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <configuration>
                            <rules>
                                <requireJavaVersion>
                                    <version>17</version>
                                </requireJavaVersion>
                                <enforceBytecodeVersion>
                                    <maxJdkVersion>17</maxJdkVersion>
                                </enforceBytecodeVersion>
                                <requireMavenVersion>
                                    <version>3.8.6</version>
                                </requireMavenVersion>
                                <requirePluginVersions>
                                    <!--Ban snapshots later, for now it's too common to depend on klass snapshots-->
                                    <banSnapshots>false</banSnapshots>
                                    <!--region spotless:off -->
                                    <unCheckedPluginList>
                                        org.apache.maven.plugins:maven-site-plugin,
                                        org.apache.maven.plugins:maven-deploy-plugin,
                                        io.liftwizard:liftwizard-generator-reladomo-code-plugin,
                                        io.liftwizard:liftwizard-generator-reladomo-database-plugin,
                                        io.liftwizard:liftwizard-generator-xsd2bean-plugin
                                    </unCheckedPluginList>
                                    <!--endregion spotless:on -->
                                </requirePluginVersions>
                                <bannedDependencies>
                                    <excludes>
                                        <exclude>log4j:log4j</exclude>
                                        <exclude>commons-logging-api</exclude>
                                        <exclude>commons-logging</exclude>
                                        <exclude>org.apache.logging.log4j:log4j</exclude>
                                        <exclude>org.slf4j:slf4j-simple</exclude>
                                        <exclude>org.slf4j:slf4j-log4j12</exclude>
                                        <exclude>org.slf4j:slf4j-jdk14</exclude>
                                        <exclude>org.slf4j:nop</exclude>
                                        <exclude>org.slf4j:jcl</exclude>
                                    </excludes>
                                </bannedDependencies>
                            </rules>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>
        <!--endregion-->

        <!--region Phase 15: test-->
        <profile>
            <id>rerecord</id>

            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <environmentVariables>
                                    <LIFTWIZARD_FILE_MATCH_RULE_RERECORD>true</LIFTWIZARD_FILE_MATCH_RULE_RERECORD>
                                </environmentVariables>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <!--endregion-->

        <!--region Phase 16: prepare-package-->
        <profile>
            <id>znai-maven-plugin</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.testingisdocumenting.znai</groupId>
                        <artifactId>znai-maven-plugin</artifactId>
                        <version>1.70</version>
                        <configuration>
                            <docId>docs</docId>
                            <sourceRoot>${project.basedir}/src/main/znai</sourceRoot>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!--endregion-->

        <!--region Phase 21: verify-->
        <profile>
            <id>maven-dependency-plugin</id>

            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <configuration>
                                <ignoredUnusedDeclaredDependencies>
                                    <ignoredUnusedDeclaredDependency>ch.qos.logback:logback-classic</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>com.google.auto.service:auto-service-annotations</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>com.h2database:h2</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>io.liftwizard:liftwizard-logging-buffered-appender</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>io.liftwizard:liftwizard-logging-p6spy</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>io.liftwizard:liftwizard-reladomo-simulated-sequence</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>org.eclipse.collections:eclipse-collections</ignoredUnusedDeclaredDependency>
                                    <ignoredUnusedDeclaredDependency>org.junit.vintage:junit-vintage-engine</ignoredUnusedDeclaredDependency>
                                </ignoredUnusedDeclaredDependencies>
                            </configuration>
                        </plugin>

                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <!--endregion-->

    </profiles>

</project>
