<?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">
    <parent>
        <groupId>com.mulesoft.mule.tests</groupId>
        <artifactId>mule-ee-integration-tests</artifactId>
        <version>4.7.3</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mule-ee-integration-performance-tests</artifactId>
    <packaging>jar</packaging>
    <name>Mule EE Integration Performance Tests</name>

    <properties>
        <surefire.args>
            -XX:+IgnoreUnrecognizedVMOptions
            --add-opens=java.base/java.lang=ALL-UNNAMED
            ${surefire.slf4j.module.args}
        </surefire.args>

        <javaModuleName>com.mulesoft.mule.test.integration.performance</javaModuleName>
        <jmh.version>1.22</jmh.version>
        <kryo.version>4.0.3</kryo.version>

        <formatterConfigPath>../formatter.xml</formatterConfigPath>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                    </execution>
                </executions>
                <configuration>
                    <processors>
                        <processor>org.openjdk.jmh.generators.BenchmarkProcessor</processor>
                    </processors>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>${surefire.args}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Target modules -->
        <dependency>
            <groupId>com.mulesoft.mule.runtime.modules</groupId>
            <artifactId>mule-module-kryo-serializer-ee</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.esotericsoftware</groupId>
            <artifactId>kryo-shaded</artifactId>
            <version>${kryo.version}</version>
        </dependency>

        <!-- AbstractBenchmark class -->
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-performance</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- JMH -->
        <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>
    </dependencies>

    <profiles>
        <profile>
            <id>micro-benchmark</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>${surefire.args}</argLine>
                            <systemPropertyVariables>
                                <mule.test.timeoutSecs>300</mule.test.timeoutSecs>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>run-benchmarks</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <classpathScope>test</classpathScope>
                                    <executable>java</executable>
                                    <workingDirectory>${basedir}/target</workingDirectory>
                                    <arguments>
                                        <argument>-classpath</argument>
                                        <classpath/>
                                        <mainClass>org.openjdk.jmh.Main</mainClass>
                                        <!--Run only a certain class-->
                                        <argument>${jmh.benchmark}</argument>
                                        <!--Create json report-->
                                        <argument>-rf</argument>
                                        <argument>json</argument>
                                        <!--Enable gc profiler-->
                                        <argument>-prof</argument>
                                        <argument>gc</argument>
                                        <!--Number of Iterations-->
                                        <argument>-i</argument>
                                        <argument>15</argument>
                                        <!--Number of Warmup Iterations-->
                                        <argument>-wi</argument>
                                        <argument>5</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>benchmark-jar</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>${shade.plugin.version}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <finalName>mule-runtime-integration-benchmarks-${project.version}</finalName>
                                    <transformers>
                                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                            <mainClass>org.openjdk.jmh.Main</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>