<?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.7</version>
  </parent>

  <artifactId>rift-java-embedded-jdk21</artifactId>
  <name>rift-java-embedded-jdk21</name>
  <description>In-process Rift engine on JDK 21 (preview FFM). Same sources as rift-java-embedded.</description>
  <url>https://github.com/achird-labs/rift-java</url>

  <properties>
    <!-- The JDK 21 variant is reactor-activated by the `embedded-jdk21` profile (JDK 21 exactly).
         Built from rift-java-embedded's main/test sources (added below) under release 21 with
         preview features enabled; FfmCompat resolves the two renamed FFM methods reflectively. -->
    <maven.compiler.release>21</maven.compiler.release>
    <!-- Path to a librift_ffi cdylib for the FFM integration tests (-Drift.ffi.lib=/path/to/librift_ffi.<ext>);
         unset, they read $RIFT_FFI_LIB, as the SDK does. With neither they skip, unless RIFT_IT is set,
         which promises a live engine and so fails them (EmbeddedTestLibrary). -->
    <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.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${build-helper-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.basedir}/../rift-java-embedded/src/main/java</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.basedir}/../rift-java-embedded/src/test/java</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <!-- Resources (e.g. the META-INF/services EmbeddedEngineProvider registration) aren't
                 shared via add-source, so pull them in explicitly for this artifact too. -->
            <id>add-resource</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>add-resource</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>${project.basedir}/../rift-java-embedded/src/main/resources</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <!-- Shared test resources (e.g. the fake native/<classifier>/librift_ffi.<ext> the
                 resolver tests extract) aren't shared via add-test-source, so add them explicitly. -->
            <id>add-test-resource</id>
            <phase>generate-test-resources</phase>
            <goals>
              <goal>add-test-resource</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>${project.basedir}/../rift-java-embedded/src/test/resources</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <release>21</release>
          <compilerArgs>
            <arg>--enable-preview</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <!-- The added rift-java-embedded sources use the JDK 21 preview FFM API, so javadoc (run by the
           release profile's attach-javadocs) must also enable preview and target release 21, or it
           fails with "<API> is a preview API and is disabled by default". -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <release>21</release>
          <additionalJOptions>
            <additionalJOption>--enable-preview</additionalJOption>
          </additionalJOptions>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <!-- Preview FFM class files require the enable-preview flag at runtime too; FFM
               downcalls are restricted methods, so also grant native access to silence the
               enforced warning. -->
          <argLine>--enable-preview --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>
          <excludes>
            <!-- Asserts JDK >= 22; this module runs on JDK 21. EmbeddedJdk21RuntimeTest below
                 covers the equivalent >= 21 assertion for this module. -->
            <exclude>**/EmbeddedRuntimeTest.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
