<?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>io.keikai.parent</groupId>
        <artifactId>keikai-build</artifactId>
        <version>7.0.0.FL.20260612-Eval</version>
    </parent>
    <!-- Ship under io.keikai (like every other shipped module: keikai-model,
         keikai, keikai-ex, ...), NOT the inherited io.keikai.parent build-parent
         groupId. Without this, the artifact publishes to io/keikai/parent/. -->
    <groupId>io.keikai</groupId>
    <artifactId>keikai-native</artifactId>
    <name>Keikai Native</name>
    <description>Rust native engine bridge via JNI. Bundles platform-specific native libraries.</description>

    <dependencies>
        <dependency>
            <groupId>io.keikai</groupId>
            <artifactId>keikai-model</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <!--
              Build the keikai-jni-shim cdylib via cargo and stage it into
              src/main/resources/native/<platform>/ before the resources
              phase copies them into the jar. Runs for the current host
              platform only; cross-platform releases require running the
              build on each target platform and committing the resulting
              dylib/so/dll under the matching native/<platform>/ directory.

              To skip this (e.g. when packaging on a machine without the
              Rust toolchain and a pre-staged dylib already exists in
              resources/), pass -Dnative.build.skip=true.
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.4.1</version>
                <executions>
                    <execution>
                        <id>build-jni-shim</id>
                        <phase>generate-resources</phase>
                        <goals><goal>exec</goal></goals>
                        <configuration>
                            <executable>bash</executable>
                            <workingDirectory>${project.basedir}</workingDirectory>
                            <arguments>
                                <argument>build-native.sh</argument>
                            </arguments>
                            <skip>${native.build.skip}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Enable Multi-Release JAR (FFM classes added via ffm profile) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Multi-Release>true</Multi-Release>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <native.build.skip>false</native.build.skip>
    </properties>

    <profiles>
        <!-- FFM profile: compile Java 22 sources into META-INF/versions/22/ -->
        <!-- Activate only when JDK 22+ is available: mvn install -Pffm -->
        <profile>
            <id>ffm</id>
            <activation>
                <jdk>[22,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>compile-java22</id>
                                <phase>compile</phase>
                                <goals><goal>compile</goal></goals>
                                <configuration>
                                    <release>22</release>
                                    <compileSourceRoots>
                                        <compileSourceRoot>${project.basedir}/src/main/java22</compileSourceRoot>
                                    </compileSourceRoots>
                                    <outputDirectory>${project.build.outputDirectory}/META-INF/versions/22</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
