<?xml version="1.0"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-statistics-examples</artifactId>
    <version>1.3</version>
  </parent>

  <artifactId>commons-statistics-examples-jmh</artifactId>
  <name>Apache Commons Statistics JMH Benchmark</name>

  <description>Code for running JMH benchmarks that assess performance.
  Code in this module is not part of the public API.</description>

  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-statistics-descriptive</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-statistics-distribution</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-statistics-ranking</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-rng-simple</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-rng-sampling</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-numbers-fraction</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-numbers-rootfinder</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-math3</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-math4-legacy</artifactId>
      <version>${statistics.commons.math4.version}</version>
    </dependency>

    <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>
    </dependency>
  </dependencies>

  <properties>
    <!-- OSGi -->
    <commons.osgi.symbolicName>org.apache.commons.statistics.examples.jmh</commons.osgi.symbolicName>
    <commons.osgi.export>org.apache.commons.statistics.examples.jmh</commons.osgi.export>
    <!-- Java 9+ -->
    <commons.module.name>org.apache.commons.statistics.examples.jmh</commons.module.name>
    <!-- Workaround to avoid duplicating config files. -->
    <statistics.parent.dir>${basedir}/../..</statistics.parent.dir>
    <!-- Reproducible builds -->
    <project.build.outputTimestamp>${statistics.build.outputTimestamp}</project.build.outputTimestamp>

    <!-- JDK 11+ required for Math.multiplyHigh -->
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <maven.compiler.release>11</maven.compiler.release>
    <commons.compiler.release>11</commons.compiler.release>

    <!-- JMH Benchmark related properties: version, name of the benchmarking uber jar. -->
    <jmh.version>1.37</jmh.version>
    <uberjar.name>examples-jmh</uberjar.name>
    <project.mainClass>org.openjdk.jmh.Main</project.mainClass>
    <!-- Disable analysis for benchmarking code. -->
    <pmd.skip>true</pmd.skip>
    <spotbugs.skip>true</spotbugs.skip>
    <!-- Disable JDK compatibility check for benchmarking code. -->
    <animal.sniffer.skip>true</animal.sniffer.skip>

    <!--
      NOTE:
      This module uses Java 11 but does not have an explicit module-info for imported packages.
      A module-info is generated by the moditect plugin. This does not appear to be discovered
      as it is in the build output directory.
      This can cause the javadoc plugin to fail when run with the package phase so skip to make
      this module compatible with the default goal. Run javadoc plugin using e.g.:
      mvn javadoc:javadoc -Dmaven.javadoc.skip=false
    -->
    <maven.javadoc.skip>true</maven.javadoc.skip>
  </properties>

  <build>
    <plugins>
      <plugin>
        <!-- NOTE: javadoc config must also be set under <reporting> -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <sourceFileExcludes>
            <sourceFileExclude>**/jmh_generated/*.java</sourceFileExclude>
          </sourceFileExcludes>
          <failOnWarnings>false</failOnWarnings>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <configuration>
          <excludes>**/jmh_generated/*.java</excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <reporting>
    <plugins>
      <plugin>
        <!-- NOTE: javadoc config must also be set under <build> -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <sourceFileExcludes>
            <sourceFileExclude>**/jmh_generated/*.java</sourceFileExclude>
          </sourceFileExcludes>
          <failOnWarnings>false</failOnWarnings>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <configuration>
          <excludes>**/jmh_generated/*.java</excludes>
        </configuration>
      </plugin>
    </plugins>
  </reporting>

  <profiles>
    <profile>
      <!-- Run a named benchmark from maven. The class to run can be specified as a property
           using -Dbenchmark=[XXX], for example:
           mvn test -Pbenchmark -Dbenchmark=InverseProbabilityPerformance
      -->
      <id>benchmark</id>
      <properties>
        <skipTests>true</skipTests>
        <benchmark>org.apache</benchmark>
        <java.cmd>java</java.cmd>
      </properties>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <compilerVersion>${maven.compiler.target}</compilerVersion>
              <source>${maven.compiler.target}</source>
              <target>${maven.compiler.target}</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>benchmark</id>
                <phase>test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <classpathScope>test</classpathScope>
                  <executable>${java.cmd}</executable>
                  <arguments>
                    <argument>-classpath</argument>
                    <classpath />
                    <argument>${project.mainClass}</argument>
                    <argument>-rf</argument>
                    <argument>json</argument>
                    <argument>-rff</argument>
                    <argument>target/jmh-result.${benchmark}.json</argument>
                    <argument>${benchmark}</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <!-- Build an executable jar that runs JMH:
           mvn package -Pexamples-jmh

           java -jar target/examples-jmh.jar -h
           java -jar target/examples-jmh.jar InverseProbabilityPerformance -rf json -rff out.json
           java -jar target/examples-jmh.jar InverseProbabilityPerformance -p implementation=ChiSquared:0.5
      -->
      <id>examples-jmh</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <compilerVersion>${maven.compiler.target}</compilerVersion>
              <source>${maven.compiler.target}</source>
              <target>${maven.compiler.target}</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <finalName>${uberjar.name}</finalName>
                  <createDependencyReducedPom>false</createDependencyReducedPom>
                  <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>${project.mainClass}</mainClass>
                    </transformer>
                  </transformers>
                  <filters>
                    <filter>
                      <!-- Shading signed JARs will fail without this. http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar -->
                      <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>
