<?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>com.mulesoft.mule.framework</groupId>
        <artifactId>micro-bechmarks-parent</artifactId>
        <version>1.3.0</version>
    </parent>

    <artifactId>micro-bechmarks-embedded</artifactId>

    <name>Mule Embedded Framework Micro-Bechmarks</name>
    <description>Mule Embedded Framework Micro-Bechmarks</description>

    <properties>
        <muleDistrosFolder>${project.build.directory}/distros</muleDistrosFolder>
        <muleFrameworkImplDependenciesFolder>${project.build.directory}/dependencies</muleFrameworkImplDependenciesFolder>
        <!-- TODO W-10624034 (MMP-581) - remove this and define apps in a module  -->
        <settingsFile>${java.io.tmpdir}/effective-settings.xml</settingsFile>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-benchmark-static-resources</id>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <includeArtifactIds>micro-bechmarks-static</includeArtifactIds>
                            <excludes>org/**</excludes>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-distro</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.distributions</groupId>
                                    <artifactId>mule-ee-distribution-standalone</artifactId>
                                    <type>zip</type>
                                    <version>${muleVersion}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${muleDistrosFolder}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-framework-impl-dependencies-bundle</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.framework</groupId>
                                    <artifactId>mule-framework</artifactId>
                                    <classifier>dependencies</classifier>
                                    <type>zip</type>
                                    <version>${project.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${muleFrameworkImplDependenciesFolder}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    <profiles>
        <profile>
            <id>performance</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <configuration>
                            <classpathScope>test</classpathScope>
                            <executable>java</executable>
                            <workingDirectory>${basedir}/target</workingDirectory>
                            <arguments>
                                <argument>-classpath</argument>
                                <classpath />

                                <argument>--add-opens=java.base/java.lang=ALL-UNNAMED</argument>
                                <argument>--add-opens=java.base/java.lang.reflect=ALL-UNNAMED</argument>
                                <argument>--add-opens=java.base/java.lang.invoke=ALL-UNNAMED</argument>

                                <argument>-DframeworkTestBomVersion=${project.version}</argument>
                                <argument>-Dmule.test.maven.artifacts.dir=noDir</argument>
                                <argument>-Dsettings.file=${settingsFile}</argument>
                                <argument>-Dmaven.home=${maven.home}</argument>
                                <argument>-Dmule.maven.plugin.version=${mule.maven.plugin.version}</argument>
                                <argument>-Dmule.framework.services.bundle.dir=${project.build.directory}/dependency/mule-framework-static-requirements-bundle-${project.version}/services</argument>
                                <argument>-DmuleVersion=${muleVersion}</argument>
                                <argument>-DmuleDistro=${muleDistrosFolder}/mule-enterprise-standalone-${muleVersion}</argument>
                                <argument>-DmuleFrameworkImplDependencies=${muleFrameworkImplDependenciesFolder}/mule-framework-${project.version}/lib</argument>
                                <mainClass>org.openjdk.jmh.Main</mainClass>
                                <!--Run only a certain class-->
                                <argument>${jmh.benchmark}</argument>
                                <!--Create json report-->
                                <argument>-rf</argument>
                                <argument>json</argument>
                                <!--Number of Iterations-->
                                <argument>-i</argument>
                                <argument>10</argument>
                                <!--Number of Warmup Iterations-->
                                <argument>-wi</argument>
                                <argument>10</argument>
                                <!--Number of forks-->
                                <argument>-f</argument>
                                <argument>1</argument>
                            </arguments>
                        </configuration>
                        <executions>
                            <execution>
                                <id>run-benchmarks</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>micro-bechmarks-static</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.mulesoft.mule.framework</groupId>
                    <artifactId>mule-framework-bom</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>
