<?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>cloud.nstart.terravault.ordinis</groupId>
    <artifactId>ordinis-parent</artifactId>
    <version>0.1.0-SNAPSHOT</version>
  </parent>

  <artifactId>ordinis-bench</artifactId>
  <name>Ordinis :: Benchmarks</name>
  <description>JMH microbenchmarks for hot paths. Не deployable — runs ad-hoc
    via `mvn -P bench package` + `java -jar target/benchmarks.jar`. Catches
    algorithmic complexity regressions (например parseRef становится O(n²),
    schema traversal превышает 1ms на 100 dicts).</description>

  <properties>
    <jmh.version>1.37</jmh.version>
    <skip.bench>true</skip.bench>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-core</artifactId>
      <version>${jmh.version}</version>
    </dependency>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-generator-annprocess</artifactId>
      <version>${jmh.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- Production deps мы измеряем. -->
    <dependency>
      <groupId>cloud.nstart.terravault.ordinis</groupId>
      <artifactId>ordinis-rest-api</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>cloud.nstart.terravault.ordinis</groupId>
      <artifactId>ordinis-domain</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- JMH annotation processor pulled через jmh-generator-annprocess (provided). -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>org.openjdk.jmh</groupId>
              <artifactId>jmh-generator-annprocess</artifactId>
              <version>${jmh.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>

      <!-- Surefire skip: бенчи в src/main, тестов нет. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!--
      Profile `bench`: собирает uber-jar `target/benchmarks.jar` через
      maven-shade. Активируется через `mvn -P bench package`. По default
      выключен — обычный `mvn package` не строит JMH JAR (медленно, не нужно).

      После build:
        java -jar target/benchmarks.jar -h           # all options
        java -jar target/benchmarks.jar Lineage      # filter benchmarks
        java -jar target/benchmarks.jar -prof gc     # GC profiler
    -->
    <profile>
      <id>bench</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
              <execution>
                <!-- unique id чтобы не конфликтовать с parent's default. -->
                <id>jmh-uber-jar</id>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <finalName>benchmarks</finalName>
                  <transformers>
                    <transformer
                      implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <manifestEntries>
                        <Main-Class>org.openjdk.jmh.Main</Main-Class>
                      </manifestEntries>
                    </transformer>
                    <transformer
                      implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                  </transformers>
                  <filters>
                    <filter>
                      <artifact>*:*</artifact>
                      <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                      </excludes>
                    </filter>
                  </filters>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
