<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.smallrye</groupId>
        <artifactId>jandex-parent</artifactId>
        <version>3.0.5</version>
    </parent>

    <artifactId>jandex-test-data</artifactId>

    <name>Jandex: Test Data</name>

    <properties>
        <java.version>17</java.version>

        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.release>${java.version}</maven.compiler.release>
    </properties>

    <build>
        <plugins>
            <!-- doesn't work correctly on nested records, even with the `compliance` version set -->
            <plugin>
                <groupId>net.revelc.code</groupId>
                <artifactId>impsort-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>sort-imports</id>
                        <phase>none</phase>
                        <configuration>
                            <compliance>${java.version}</compliance>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>parameters</id>
            <activation>
                <property>
                    <name>parameters</name>
                    <value>true</value>
                </property>
            </activation>
            <properties>
                <maven.compiler.parameters>true</maven.compiler.parameters>
            </properties>
        </profile>

        <profile>
            <id>fix-module-info</id>
            <activation>
                <jdk>[17,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>${version.exec-maven-plugin}</version>
                        <executions>
                            <execution>
                                <id>jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${env.JAVA_HOME}/bin/jar</executable>
                                    <workingDirectory>${project.build.directory}</workingDirectory>
                                    <arguments>
                                        <argument>--update</argument>
                                        <argument>--file</argument>
                                        <argument>${project.build.directory}/${project.build.finalName}.jar</argument>
                                        <argument>--main-class</argument>
                                        <argument>test.exec.Main</argument>
                                        <argument>--module-version</argument>
                                        <argument>1.0</argument>
                                        <argument>-C</argument>
                                        <argument>${project.build.outputDirectory}</argument>
                                        <argument>module-info.class</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>build-with-downloaded-jdk17</id>
            <activation>
                <jdk>(,17)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.igormaznitsa</groupId>
                        <artifactId>mvn-jlink-wrapper</artifactId>
                        <version>${version.mvn-jlink-wrapper}</version>
                        <executions>
                            <execution>
                                <id>download-jdk</id>
                                <goals>
                                    <goal>cache-jdk</goal>
                                </goals>
                                <configuration>
                                    <jdkCachePath>${project.basedir}/jdk-cache</jdkCachePath>
                                    <jdkPathProperty>custom-jdk-path</jdkPathProperty>
                                    <provider>ADOPT</provider>
                                    <providerConfig>
                                        <release>${java.version}</release>
                                        <arch>x64</arch> <!-- TODO select automatically, but how? -->
                                    </providerConfig>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-compile</id>
                                <configuration>
                                    <executable>${custom-jdk-path}/bin/javac</executable>
                                    <fork>true</fork>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- exclude `module-info.class`, otherwise Maven JAR plugin invokes current JDK's `jar`, which may fail -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>module-info.class</exclude>
                            </excludes>
                        </configuration>
                    </plugin>

                    <!-- add `module-info.class` and the module attributes using custom JDK's `jar` -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>${version.exec-maven-plugin}</version>
                        <executions>
                            <execution>
                                <id>jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${custom-jdk-path}/bin/jar</executable>
                                    <workingDirectory>${project.build.directory}</workingDirectory>
                                    <arguments>
                                        <argument>--update</argument>
                                        <argument>--file</argument>
                                        <argument>${project.build.directory}/${project.build.finalName}.jar</argument>
                                        <argument>--main-class</argument>
                                        <argument>test.exec.Main</argument>
                                        <argument>--module-version</argument>
                                        <argument>1.0</argument>
                                        <argument>-C</argument>
                                        <argument>${project.build.outputDirectory}</argument>
                                        <argument>module-info.class</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <configuration>
                            <javadocExecutable>${custom-jdk-path}/bin/javadoc</javadocExecutable>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
