<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) 2019, RTE (http://www.rte-france.com)
    This Source Code Form is subject to the terms of the Mozilla Public
    License, v. 2.0. If a copy of the MPL was not distributed with this
    file, You can obtain one at http://mozilla.org/MPL/2.0/.

-->
<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>com.powsybl</groupId>
        <artifactId>powsybl</artifactId>
        <version>24</version>
    </parent>
    <artifactId>powsybl-parent</artifactId>
    <packaging>pom</packaging>

    <name>Powsybl Parent</name>
    <description>Powsybl Parent</description>

    <modules>
        <module>powsybl-parent-ws</module>
    </modules>

    <properties>
        <java.version>21</java.version>

        <maven.buildnumber.version>3.2.1</maven.buildnumber.version>
        <maven.checkstyle.version>3.6.0</maven.checkstyle.version>
        <checkstyle.version>11.0.1</checkstyle.version> <!-- The maven checkstyle plugin depends on an old version of Checkstyle -->
        <maven.failsafe.version>3.5.2</maven.failsafe.version>
        <maven.gmavenplus.version>4.1.1</maven.gmavenplus.version>
        <!--
            For groovydoc, we must use the same version as the project's groovy version. Standardize on the groovy.version property.
            For projects which don't use groovy at all, this means the pluginmanagement will hold an invalid <version> definition
            (the literal string '${groovy.version}' instead of a valid version like '2.5.8') but this doesn't break the build.
            For projects which do use groovy (ie at least one submodule declares gmavenplus in their <build><plugins> element)
            then the build will break until either groovy.version or maven.groovydoc.version is set. It will break not just for the release profile
            so projects can detect errors early and fix their groovydoc configuration.
        -->
        <maven.groovydoc.version>${groovy.version}</maven.groovydoc.version>
        <maven.jacoco.version>0.8.12</maven.jacoco.version>
        <maven.javadoc.version>3.11.2</maven.javadoc.version>
        <maven.plugin.version>3.15.1</maven.plugin.version>
        <maven.shade.version>3.6.0</maven.shade.version>
        <maven.source.version>3.3.1</maven.source.version>
        <maven.templating.version>3.0.0</maven.templating.version>
        <maven.sonar.version>5.0.0.4389</maven.sonar.version>

        <!-- Some plugins have dependencies we need to add -->
        <!--
            Maven don't seem to have a way to reference the version of 'powsybl-parent' from child pom, so we hardcode a value here.
            For example, in a multi-module project having 'powsybl-parent' as parent and sub-modules having as parent "../pom.xml", ${parent.version} refere to the root project...
            Remember to update this property when upgrading this artifact, particularly when updating lombok.config in powsybl-build-tools.
        -->
        <powsybl-build-tools.version>24</powsybl-build-tools.version>

        <!--
            by default don't override the javadocs. if you want to override the javadocs,
            set the following property in the project
            <properties>
                <groovydoc.attach>true</groovydoc.attach>
                <groovydoc.classifier>javadoc</groovydoc.classifier>
                <groovydoc.groovyDocJavaSources>true</groovydoc.groovyDocJavaSources>
                <maven.javadoc.skip>true</maven.javadoc.skip>
            </properties>
        -->
        <groovydoc.attach>false</groovydoc.attach>
        <groovydoc.classifier>groovydoc</groovydoc.classifier>
        <groovydoc.groovyDocJavaSources>false</groovydoc.groovyDocJavaSources>

        <sonar.exclusions>
            **/generated/**/*
        </sonar.exclusions>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>buildnumber-maven-plugin</artifactId>
                    <version>${maven.buildnumber.version}</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>create</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <doCheck>false</doCheck>
                        <doUpdate>false</doUpdate>
                        <revisionOnScmFailure>UNKNOWN_BUILD</revisionOnScmFailure>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${maven.failsafe.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.gmavenplus</groupId>
                    <artifactId>gmavenplus-plugin</artifactId>
                    <version>${maven.gmavenplus.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>addSources</goal>
                                <goal>addTestSources</goal>
                                <goal>generateStubs</goal>
                                <goal>compile</goal>
                                <goal>generateTestStubs</goal>
                                <goal>compileTests</goal>
                                <goal>removeStubs</goal>
                                <goal>removeTestStubs</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven.javadoc.version}</version>
                    <configuration>
                        <additionalOptions>-Xdoclint:none</additionalOptions>
                        <docfilessubdirs>true</docfilessubdirs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-plugin-plugin</artifactId>
                    <version>${maven.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>default-descriptor</id>
                            <phase>process-classes</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>${maven.shade.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>templating-maven-plugin</artifactId>
                    <version>${maven.templating.version}</version>
                    <executions>
                        <execution>
                            <id>filter-src</id>
                            <goals>
                                <goal>filter-sources</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>${maven.sonar.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>java9+</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <build>
                <!-- This is merged in the main configuration but plexus-compiler-javac is smart enough
                  to ignore the source and target arguments when the release argument is supplied. -->
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                <release>${java.version}</release>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>java21+</id>
            <activation>
                <jdk>[21,)</jdk>
            </activation>
            <properties>
                <!--
                  Temporary solution to remove the JDK21 warning during compilation "Annotation
                  processing is enabled because one or more processors were
                  found on the class path." and keep the same behavior as previous JDKs.
                  This may stop working in the future (java23+ ?) and the
                  annotation processors probably will have to be explictly
                  listed using maven's configuration (annotationProcessorPaths ?).
                  Using this configuration now gives us and the maven community more time to
                  establish best practices regarding this configuration, how to use it in large
                  projects with shared inherited build systems.
                -->
                <maven.compiler.proc>full</maven.compiler.proc>
                <!--
                  need to create an empty argLine property here otherwise tests won't start
                  with "can't open {argLine}" because of the EnableDynamicAgentLoading workaround
                -->
                <argLine/>
            </properties>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <!--
                                  Temporary solution to remove the JDK21 warning during tests using mockito
                                  or other agents "WARNING: A Java agent has been loaded dynamically"
                                  and keep the same behavior as previous JDKs.
                                  This may stop working in the future (java23+ ?) and the
                                  agents probably will have to be explictly
                                  listed using maven's configuration (inject the target artifact jars into argLine).
                                  Using this configuration now gives us and the maven community more time to
                                  establish best practices regarding this configuration, how to use it in large
                                  projects with shared inherited build systems.
                                  @{argLine} syntax to append instead of replace
                                -->
                                <argLine>@{argLine} -XX:+EnableDynamicAgentLoading</argLine>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <configuration>
                                <!--
                                    Temporary solution to remove the JDK21 warning during tests using mockito
                                    or other agents "WARNING: A Java agent has been loaded dynamically"
                                    and keep the same behavior as previous JDKs.
                                    This may stop working in the future (java23+ ?) and the
                                    agents probably will have to be explictly
                                    listed using maven's configuration (inject the target artifact jars into argLine).
                                    Using this configuration now gives us and the maven community more time to
                                    establish best practices regarding this configuration, how to use it in large
                                    projects with shared inherited build systems.
                                    @{argLine} syntax to append instead of replace
                                -->
                                <argLine>@{argLine} -XX:+EnableDynamicAgentLoading</argLine>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>jacoco</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>${maven.jacoco.version}</version>
                        <configuration>
                            <excludes>
                                <!-- exclude generated classes -->
                                <exclude>**/generated/**/*</exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>checks</id>
            <activation>
                <property>
                    <name>powsybl.checks.skip</name>
                    <value>!true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>${maven.checkstyle.version}</version>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                                <configuration>
                                    <configLocation>powsybl-build-tools/checkstyle.xml</configLocation>
                                    <consoleOutput>true</consoleOutput>
                                    <failsOnError>true</failsOnError>
                                    <excludes>**/generated/**/*,**/module-info.java</excludes>
                                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>com.powsybl</groupId>
                                <artifactId>powsybl-build-tools</artifactId>
                                <version>24</version>
                            </dependency>
                            <dependency>
                                <groupId>com.puppycrawl.tools</groupId>
                                <artifactId>checkstyle</artifactId>
                                <version>${checkstyle.version}</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>${maven.javadoc.version}</version>
                        <executions>
                            <execution>
                                <id>javadoc-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>${maven.source.version}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                    <goal>test-jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.gmavenplus</groupId>
                            <artifactId>gmavenplus-plugin</artifactId>
                            <version>${maven.gmavenplus.version}</version>
                            <executions>
                                <execution>
                                    <id>groovydoc-jar</id>
                                    <goals>
                                        <goal>groovydoc-jar</goal>
                                    </goals>
                                    <configuration>
                                        <attach>${groovydoc.attach}</attach>
                                        <includeClasspath>PROJECT_AND_PLUGIN</includeClasspath>
                                        <classifier>${groovydoc.classifier}</classifier>
                                        <groovyDocJavaSources>${groovydoc.groovyDocJavaSources}</groovyDocJavaSources>
                                    </configuration>
                                </execution>
                            </executions>
                            <dependencies>
                                <dependency>
                                    <groupId>org.apache.groovy</groupId>
                                    <artifactId>groovy-groovydoc</artifactId>
                                    <version>${maven.groovydoc.version}</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>

        <profile>
            <id>lombok-config-copy</id>
            <activation>
                <file>
                    <exists>${basedir}/.mvn/lombok-config-copy.marker</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>lombok-copy-tools</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.powsybl</groupId>
                                            <artifactId>powsybl-build-tools</artifactId>
                                            <version>${powsybl-build-tools.version}</version>
                                            <type>jar</type>
                                            <outputDirectory>${project.build.directory}/configs</outputDirectory>
                                            <destFileName>powsybl-build-tools.jar</destFileName>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>check-lombok</id>
            <activation>
                <file>
                    <exists>${basedir}/.mvn/lombok-config-copy.marker</exists>
                </file>
            </activation>
            <properties>
                <powsybl.internal.lombok-import-line>import target/configs/powsybl-build-tools.jar!powsybl-build-tools/lombok.config</powsybl.internal.lombok-import-line>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>lombok-verify-main-file</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <requireFilesExist>
                                            <files>
                                                <file>${project.basedir}/lombok.config</file>
                                            </files>
                                            <message>Missing file "lombok.config" in project. Please create it starting with the following content "${powsybl.internal.lombok-import-line}".</message>
                                        </requireFilesExist>
                                        <evaluateBeanshell>
                                            <condition>org.codehaus.plexus.util.FileUtils.fileRead(new File(URI.create("${project.baseUri}").resolve("lombok.config")), "UTF-8").startsWith("${powsybl.internal.lombok-import-line}")</condition>
                                            <message>The lombok.config file must start with the line "${powsybl.internal.lombok-import-line}"</message>
                                        </evaluateBeanshell>
                                    </rules>
                                    <failFast>true</failFast>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
