<?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>

  <groupId>org.wickra</groupId>
  <artifactId>wickra-gym</artifactId>
  <version>0.1.0</version>
  <packaging>jar</packaging>

  <name>wickra-gym</name>
  <description>A deterministic, Gymnasium-compatible backtest environment for the JVM over the Wickra C ABI (FFM/Panama): precompute a candle dataset once into a fixed feature tensor, then step an RL environment in O(1) with byte-identical trajectories.</description>
  <url>https://github.com/wickra-lib/wickra-gym</url>

  <licenses>
    <license>
      <name>MIT OR Apache-2.0</name>
    </license>
  </licenses>
  <developers>
    <developer>
      <id>kingchenc</id>
      <name>kingchenc</name>
      <url>https://github.com/kingchenc</url>
    </developer>
  </developers>
  <scm>
    <connection>scm:git:https://github.com/wickra-lib/wickra-gym.git</connection>
    <developerConnection>scm:git:https://github.com/wickra-lib/wickra-gym.git</developerConnection>
    <url>https://github.com/wickra-lib/wickra-gym</url>
  </scm>

  <properties>
    <maven.compiler.release>22</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- The native C ABI library is built by `cargo build -p wickra-gym-c`
         (debug profile) into the workspace target/debug directory. -->
    <native.lib.dir>${project.basedir}/../../target/debug</native.lib.dir>
    <junit.version>6.1.3</junit.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.16.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.6.0</version>
        <configuration>
          <!-- FFM needs native access enabled. native.lib.dir goes through
               systemPropertyVariables (not argLine) so a path with spaces is not
               split into separate JVM arguments. -->
          <argLine>--enable-native-access=ALL-UNNAMED</argLine>
          <systemPropertyVariables>
            <native.lib.dir>${native.lib.dir}</native.lib.dir>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <!--
      Release profile (CI only, gated). `release.yml` runs
      `mvn -B -f bindings/java -Prelease deploy -DskipTests`, so everything
      Maven Central requires beyond a plain jar lives here: a sources jar, a
      javadoc jar, a GPG signature over every artifact, and the publishing
      plugin that uploads them.

      There was no profiles block at all until 0.1.1, and Maven only warns about
      a `-P` that matches nothing. So the deploy ran bare and died on
      `repository element was not specified in the POM inside
      distributionManagement`, which is Maven saying it had nowhere to send the
      artifacts. `github-release` depends on this job, so that rejection took
      the whole GitHub Release with it, and v0.1.0 has none.

      The native libraries are staged into src/main/resources/native/<os>-<arch>/
      from the c-abi-* artifacts before the deploy runs, so the published jar
      carries every platform's library.
    -->
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.4.0</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals><goal>jar-no-fork</goal></goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.12.0</version>
            <configuration>
              <!-- Central requires a javadoc jar, not perfect javadoc; doclint
                   would fail the release over a missing @param on a binding
                   whose contract is the C ABI. -->
              <doclint>none</doclint>
              <quiet>true</quiet>
            </configuration>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals><goal>jar</goal></goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>3.2.8</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals><goal>sign</goal></goals>
                <configuration>
                  <!-- Non-interactive signing on CI: modern GPG needs loopback
                       pinentry to take the passphrase from the env without a
                       TTY. The key and passphrase are wired in by setup-java. -->
                  <gpgArguments>
                    <arg>--pinentry-mode</arg>
                    <arg>loopback</arg>
                  </gpgArguments>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.sonatype.central</groupId>
            <artifactId>central-publishing-maven-plugin</artifactId>
            <version>0.11.0</version>
            <extensions>true</extensions>
            <configuration>
              <!-- Matches `server-id: central` in the setup-java step, which is
                   where CENTRAL_USERNAME / CENTRAL_PASSWORD are bound. -->
              <publishingServerId>central</publishingServerId>
              <autoPublish>true</autoPublish>
              <!-- Wait for the deployment to be *published*, not merely
                   validated. The default stops at validation and prints "to
                   finish publishing visit ...", so the job goes green while the
                   artifact is not yet on the repository, and anything that fails
                   after validation is invisible to this workflow. A green Maven
                   job should mean the jar is public. -->
              <waitUntil>published</waitUntil>
              <!-- Central publishes when it gets to it: a sibling's first
                   deployment was validated in minutes and published after the
                   plugin's default 30-minute wait had expired. Two hours. -->
              <waitMaxTime>7200</waitMaxTime>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
