<?xml version="1.0" encoding="UTF-8"?>
<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>dev.logchange</groupId>
        <artifactId>logchange</artifactId>
        <version>1.16.9</version>
    </parent>

    <artifactId>logchange-cli</artifactId>

    <properties>
        <packaging>jar</packaging>
        <graal.version>24.1.2</graal.version>
        <svm.version>24.1.2</svm.version>
        <jdk.version>21</jdk.version>
        <!-- If you are building with JDK 9 or higher, you can uncomment the lines below to set the release version -->
        <release.version>21</release.version>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>

        <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
        <native-maven-plugin.version>0.10.5</native-maven-plugin.version>
        <maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>

        <picocli.version>4.7.6</picocli.version>

        <exec.mainClass>dev.logchange.cli.LogchangeCliCommand</exec.mainClass>

        <jib-maven-plugin.version>3.4.4</jib-maven-plugin.version>
        <jib.docker.image>${project.artifactId}</jib.docker.image>
        <jib.docker.tag>${project.version}</jib.docker.tag>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>dev.logchange</groupId>
            <artifactId>logchange-commands</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
            <version>${picocli.version}</version>
        </dependency>

        <!-- TESTS -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths combine.children="append">
                        <path>
                            <groupId>info.picocli</groupId>
                            <artifactId>picocli-codegen</artifactId>
                            <version>${picocli.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven-shade-plugin.version}</version>
                <executions>
                    <execution>
                        <id>default-shade</id>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>${exec.mainClass}</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <version>${native-maven-plugin.version}</version>
                <extensions>true</extensions>
                <configuration combine.self="override">
                    <imageName>${project.artifactId}</imageName>
                    <mainClass>${exec.mainClass}</mainClass>
                    <buildArgs>
                        <buildArg>--no-fallback</buildArg>
                    </buildArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>${jib-maven-plugin.version}</version>
                <configuration>
                    <to>
                        <image>${jib.docker.image}:${jib.docker.tag}</image>
                    </to>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>write-version</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <includes>
                                        <include>version.txt</include>
                                    </includes>
                                    <!-- This enables the replacement of ${project.version} -->
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <profiles>
        <profile>
            <id>jdk-9-or-later</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <properties>
                <maven.compiler.release>${release.version}</maven.compiler.release>
            </properties>
        </profile>
        <profile>
            <id>graalvm</id>
            <activation>
                <file>
                    <exists>${env.JAVA_HOME}/bin/native-image</exists>
                </file>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.graalvm.sdk</groupId>
                    <artifactId>graal-sdk</artifactId>
                    <version>${graal.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.graalvm.nativeimage</groupId>
                    <artifactId>svm</artifactId>
                    <version>${svm.version}</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>${maven-compiler-plugin.version}</version>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>native</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>${native-maven-plugin.version}</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                            <execution>
                                <id>test-native</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <phase>test</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <buildArgs>
                                <arg>--initialize-at-build-time=org.xml.sax.helpers.LocatorImpl</arg>
                                <arg>--initialize-at-build-time=org.xml.sax.helpers.AttributesImpl</arg>
                            </buildArgs>
                            <imageName>logchange</imageName>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>
        <profile>
            <id>native-static</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>${native-maven-plugin.version}</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                            <execution>
                                <id>test-native</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <phase>test</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <buildArgs>
                                <arg>--libc=musl</arg>
                                <arg>--static</arg>
                                <arg>--initialize-at-build-time=org.xml.sax.helpers.LocatorImpl</arg>
                                <arg>--initialize-at-build-time=org.xml.sax.helpers.AttributesImpl</arg>
                            </buildArgs>
                            <imageName>logchange</imageName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
