<?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.github.achird-labs</groupId>
    <artifactId>rift-java-parent</artifactId>
    <version>0.3.2</version>
  </parent>

  <artifactId>rift-java-embedded</artifactId>
  <name>rift-java-embedded</name>
  <description>In-process Rift engine over the Panama FFM API (stable, JDK 22+). C-ABI v2 binding.</description>
  <url>https://github.com/achird-labs/rift-java</url>

  <properties>
    <!-- Stable java.lang.foreign requires JDK 22+. This module is reactor-activated by the
         `embedded` profile (JDK [22,)). -->
    <maven.compiler.release>22</maven.compiler.release>
    <!-- Path to a librift_ffi cdylib; the FFM integration tests run against it and skip when unset.
         Override with -Drift.ffi.lib=/path/to/librift_ffi.<ext>. -->
    <rift.ffi.lib></rift.ffi.lib>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.github.achird-labs</groupId>
      <artifactId>rift-java-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <!-- FFM downcalls are restricted methods; grant native access to silence the enforced warning. -->
          <argLine>--enable-native-access=ALL-UNNAMED</argLine>
          <systemPropertyVariables>
            <rift.ffi.lib>${rift.ffi.lib}</rift.ffi.lib>
          </systemPropertyVariables>
          <!-- The real-FFM integration test is named *IT (its own convention here, not Failsafe's)
               and would otherwise be skipped by Surefire's default *Test(s)/TestCase includes. -->
          <includes>
            <include>**/*Test.java</include>
            <include>**/*IT.java</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!-- Release path: this module is pulled into the JDK 21 deploy reactor (root pom's
         `dual-embedded` profile) so it publishes alongside rift-java-embedded-jdk21. Its stable FFM
         sources need JDK 22+, so compile and javadoc them through a JDK 22 toolchain (declared in
         ~/.m2/toolchains.xml on the runner) instead of the reactor's JDK 21. `maven.compiler.release`
         stays 22 above; the toolchain only changes which JDK runs javac/javadoc. -->
    <profile>
      <id>dual-embedded</id>
      <activation>
        <property>
          <name>dualEmbedded</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <jdkToolchain>
                <version>22</version>
              </jdkToolchain>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
              <jdkToolchain>
                <version>22</version>
              </jdkToolchain>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
