<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.mule.tests</groupId>
        <artifactId>mule-tests</artifactId>
        <version>4.3.0-20220919</version>
    </parent>
    <artifactId>mule-tests-performance</artifactId>
    <packaging>jar</packaging>
    <name>Performance Tests</name>
    <description>Micro-benchmarks to test the performance of core Mule functionality</description>

    <properties>
        <jmh.version>1.21</jmh.version>
    
        <skipExportTests>false</skipExportTests>
        <formatterConfigPath>../../formatter.xml</formatterConfigPath>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>3.2.0</version>
                <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>-Djmh.ignoreLock=true</argLine>
                    <systemPropertyVariables>
                        <contiperf.active>false</contiperf.active>
                        <enablePerformanceTests>false</enablePerformanceTests>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>net.bytebuddy</groupId>
            <artifactId>byte-buddy</artifactId>
        </dependency>
        <!-- Mule Container dependencies -->
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-core-tests</artifactId>
            <version>${project.version}</version>
            <type>test-jar</type>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-extensions-support</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-extensions-spring-support</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-spring-config</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-unit</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Services -->
        <!--TODO: MULE-10837-->
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-module-service</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.services</groupId>
            <artifactId>mule-service-weave</artifactId>
            <classifier>mule-service</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-dwb-api</artifactId>                
        </dependency>
        <!-- Test dependencies -->
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-functional</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-infrastructure</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.databene</groupId>
            <artifactId>contiperf</artifactId>
            <version>2.2.0</version>
            <scope>test</scope>
        </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>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>no-large-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.2</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>performance</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>-Djmh.ignoreLock=false</argLine>
                            <systemPropertyVariables>
                                <enablePerformanceTests>true</enablePerformanceTests>
                                <contiperf.active>true</contiperf.active>
                                <mule.test.timeoutSecs>300</mule.test.timeoutSecs>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
            </plugins>
            </build>
        </profile>
        <profile>
            <id>micro-benchmark</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>-Djmh.ignoreLock=false</argLine>
                            <systemPropertyVariables>
                                <enablePerformanceTests>false</enablePerformanceTests>
                                <contiperf.active>false</contiperf.active>
                                <mule.test.timeoutSecs>300</mule.test.timeoutSecs>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.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>10</argument>
                                        <!--Number of Warmup Iterations-->
                                        <argument>-wi</argument>
                                        <argument>10</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
<!--                     <plugin> -->
<!--                         <groupId>org.mule.jmh</groupId> -->
<!--                         <artifactId>jmh-elasticsearch-maven-plugin</artifactId> -->
<!--                         <version>${mule.jmh.elasticsearch.maven.plugin.version}</version> -->
<!--                             <executions> -->
<!--                                 <execution> -->
<!--                                     <phase>post-integration-test</phase> -->
<!--                                     <goals> -->
<!--                                         <goal>generate-report</goal> -->
<!--                                     </goals> -->
<!--                                     <configuration> -->
<!--                                         <index>/runtime/jmh/</index> -->
<!--                                         <host>${elasticsearch.url}</host> -->
<!--                                         <userName>${elasticsearch.user}</userName> -->
<!--                                         <userPassword>${elasticsearch.password}</userPassword> -->
<!--                                         <version>${project.version}</version> -->
<!--                                         <reportPath>${basedir}/target/jmh-result.json</reportPath> -->
<!--                                     </configuration> -->
<!--                                 </execution> -->
<!--                             </executions> -->
<!--                     </plugin> -->
                </plugins>
            </build>
        </profile>
        <profile>
            <id>benchmark-jar</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>-Djmh.ignoreLock=false</argLine>
                        </configuration>
                    </plugin>
                    <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-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>
