<?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-grandparent-build</artifactId>
        <version>2.1.14</version>
        <relativePath>../liftwizard-grandparent-build</relativePath>
    </parent>

    <artifactId>liftwizard-parent-build</artifactId>

    <packaging>pom</packaging>
    <name>Liftwizard Parent Build</name>

    <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>
                                    <!-- Based on https://github.com/openrewrite/rewrite-static-analysis/blob/main/src/main/resources/META-INF/rewrite/static-analysis.yml-->
                                    <!-- But these recipes are disabled in Liftwizard:-->
                                    <!-- - org.openrewrite.staticanalysis.EqualsAvoidsNull-->
                                    <!-- As well as all formatting recipes, since we can rely on auto-formatters instead.-->
                                    <!-- - org.openrewrite.java.format.MethodParamPad-->
                                    <!-- - org.openrewrite.java.format.NoWhitespaceAfter-->
                                    <!-- - org.openrewrite.java.format.NoWhitespaceBefore-->
                                    <!-- - org.openrewrite.java.format.PadEmptyForLoopComponents-->
                                    <recipe>io.liftwizard.staticanalysis.CodeCleanup</recipe>

                                    <!-- Based on https://github.com/openrewrite/rewrite-static-analysis/blob/main/src/main/resources/META-INF/rewrite/common-static-analysis.yml-->
                                    <!-- But these recipes are disabled in Liftwizard:-->
                                    <!-- - org.openrewrite.staticanalysis.EqualsAvoidsNull-->
                                    <!-- - org.openrewrite.staticanalysis.InlineVariable-->
                                    <!-- - org.openrewrite.staticanalysis.StringLiteralEquality-->
                                    <recipe>io.liftwizard.staticanalysis.CommonStaticAnalysis</recipe>

                                    <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>
                            <dependencies>
                                <dependency>
                                    <groupId>io.liftwizard</groupId>
                                    <artifactId>liftwizard-rewrite</artifactId>
                                    <version>2.1.14</version>
                                </dependency>
                            </dependencies>
                        </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>

                                    <recipe>io.liftwizard.java.migrate.UpgradeToJava17</recipe>
                                </activeRecipes>
                            </configuration>
                            <dependencies>
                                <dependency>
                                    <groupId>io.liftwizard</groupId>
                                    <artifactId>liftwizard-rewrite</artifactId>
                                    <version>2.1.14</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <!--endregion-->

        <!--region Phase 17: package-->
        <profile>
            <id>maven-shade-plugin</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <artifactId>maven-shade-plugin</artifactId>
                            <version>3.6.0</version>
                            <configuration>
                                <createDependencyReducedPom>true</createDependencyReducedPom>
                                <transformers>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>reference.conf</resource>
                                    </transformer>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>${mainClass}</mainClass>
                                    </transformer>
                                </transformers>
                                <!-- exclude signed Manifests -->
                                <filters>
                                    <filter>
                                        <artifact>*:*</artifact>
                                        <excludes>
                                            <exclude>module-info.class</exclude>
                                            <exclude>META-INF/*.SF</exclude>
                                            <exclude>META-INF/*.DSA</exclude>
                                            <exclude>META-INF/*.RSA</exclude>
                                        </excludes>
                                    </filter>
                                </filters>
                            </configuration>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>shade</goal>
                                    </goals>
                                    <phase>package</phase>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <!--endregion-->

    </profiles>

</project>
