<?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>mule-framework-tests</artifactId>
        <version>1.2.1</version>
    </parent>

    <artifactId>mule-embedded-framework-tests</artifactId>

    <name>Mule Embedded Framework Integration Tests</name>

    <properties>
        <keepServicesAliveAfterLastFrameworkClosed>true</keepServicesAliveAfterLastFrameworkClosed>

        <surefire.args>
            ${surefire.args.base}
            -XX:+IgnoreUnrecognizedVMOptions
            <!-- TODO - W-14673966 make these directed when possible -->
            --add-opens=java.base/java.lang=ALL-UNNAMED
            --add-opens=java.base/java.lang.reflect=ALL-UNNAMED
            --add-opens=java.base/java.lang.invoke=ALL-UNNAMED
        </surefire.args>

        <frameworkTestBomVersion>${project.version}</frameworkTestBomVersion>
        <muleDistrosFolder>${project.build.directory}/distros</muleDistrosFolder>
        <muleFrameworkImplDependenciesFolder>${project.build.directory}/dependencies</muleFrameworkImplDependenciesFolder>
        <muleMavenPluginVersion>4.0.0</muleMavenPluginVersion>

        <disruptor.java8.version>3.4.4</disruptor.java8.version>

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

    <build>
        <testResources>
            <testResource>
                <filtering>true</filtering>
                <directory>${basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <propertiesEncoding>UTF-8</propertiesEncoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-custom-4.8-bundle</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.framework</groupId>
                                    <artifactId>mule-framework-4.8-bundle</artifactId>
                                    <type>zip</type>
                                    <version>${project.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/custom-4.8-bundle</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-custom-latest-bundle</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.framework</groupId>
                                    <artifactId>mule-framework-latest-bundle</artifactId>
                                    <type>zip</type>
                                    <version>${project.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/custom-latest-bundle</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>predownload-no-services-bom-49</id>
                        <goals>
                            <goal>get</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifact>com.mulesoft.mule.distributions:mule-runtime-impl-no-services-bom:${mule49Version}:pom</artifact>
                        </configuration>
                    </execution>
                    <execution>
                        <id>predownload-services-49</id>
                        <goals>
                            <goal>get</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifact>com.mulesoft.mule.distributions:mule-services-all:${mule49Version}:pom</artifact>
                        </configuration>
                    </execution>
                    <execution>
                        <id>predownload-no-services-bom-410</id>
                        <goals>
                            <goal>get</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifact>com.mulesoft.mule.distributions:mule-runtime-impl-no-services-bom:${mule410Version}:pom</artifact>
                        </configuration>
                    </execution>
                    <execution>
                        <id>predownload-services-410</id>
                        <goals>
                            <goal>get</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifact>com.mulesoft.mule.distributions:mule-services-all:${mule410Version}:pom</artifact>
                        </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>${mule49Version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.distributions</groupId>
                                    <artifactId>mule-ee-distribution-standalone</artifactId>
                                    <type>zip</type>
                                    <version>${mule410Version}</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>
                    <execution>
                        <id>unpack-framework-integration-resources</id>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <includeArtifactIds>mule-framework-integration-tests</includeArtifactIds>
                            <excludes>org/**</excludes>
                            <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-services-bundle</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.framework</groupId>
                                    <artifactId>mule-framework-static-requirements-bundle</artifactId>
                                    <type>zip</type>
                                    <version>${project.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.framework</groupId>
                                    <artifactId>mule-framework-static-requirements-reduced-bundle</artifactId>
                                    <type>zip</type>
                                    <version>${project.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/dependency</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-integration-tests</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.mulesoft.mule.framework</groupId>
                                    <artifactId>mule-framework-integration-tests</artifactId>
                                    <version>${project.version}</version>
                                    <classifier>tests</classifier>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/integration-tests</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- This plugin copies the effective maven settings to a file so it can be used by MavenTestUtils. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-help-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-test-resources</phase>
                        <id>copy-settings</id>
                        <goals>
                            <goal>effective-settings</goal>
                        </goals>
                        <configuration>
                            <output>${settingsFile}</output>
                            <showPasswords>true</showPasswords>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <useModulePath>false</useModulePath>
                    <systemPropertyVariables>
                        <!-- Avoid regenerating the services classloaders for every muleFwk created by tests, which cause the tests to take longer -->
                        <mule.framework.keepServicesAliveAfterLastFrameworkClosed>${keepServicesAliveAfterLastFrameworkClosed}</mule.framework.keepServicesAliveAfterLastFrameworkClosed>

                        <!-- TODO W-10624034 (MMP-581) - remove this and define apps in a module  -->
                        <mule.test.maven.artifacts.dir>noDir</mule.test.maven.artifacts.dir>
                        <settings.file>${settingsFile}</settings.file>
                        <custom.local.repo>${project.build.directory}/custom-repo</custom.local.repo>
                        <project.build.directory>${project.build.directory}</project.build.directory>
                        <maven.home>${maven.home}</maven.home>
                        <muleVersion>${muleVersion}</muleVersion>
                        <mule48Version>${mule48Version}</mule48Version>
                        <mule49Version>${mule49Version}</mule49Version>
                        <mule410Version>${mule410Version}</mule410Version>
                        <distribution-4.6>${project.build.directory}/custom-4.8-bundle/mule-framework-4.8-bundle-${project.version}</distribution-4.6>
                        <distribution-latest-bundle>${project.build.directory}/custom-latest-bundle/mule-framework-latest-bundle-${project.version}</distribution-latest-bundle>
                        <distribution-4.9>${muleDistrosFolder}/mule-enterprise-standalone-${mule49Version}</distribution-4.9>
                        <distribution-4.10>${muleDistrosFolder}/mule-enterprise-standalone-${mule410Version}</distribution-4.10>
                        <muleFrameworkImplDependencies>${muleFrameworkImplDependenciesFolder}/mule-framework-${project.version}/lib</muleFrameworkImplDependencies>
                        <mule.framework.services.bundle.dir>${project.build.directory}/dependency/mule-framework-static-requirements-bundle-${project.version}/services</mule.framework.services.bundle.dir>
                        <mule.framework.services.reduced.bundle.dir>${project.build.directory}/dependency/mule-framework-static-requirements-reduced-bundle-${project.version}/services</mule.framework.services.reduced.bundle.dir>
                        <mule.framework.integration.tests.dir>${project.build.directory}/integration-tests</mule.framework.integration.tests.dir>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Ensure the Mule Framework still works with Java 8 -->
        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>${disruptor.java8.version}</version>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-integration-tests</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-integration-tests</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <type>test-jar</type>
            <exclusions>
                <exclusion>
                    <groupId>com.mulesoft.mule.framework</groupId>
                    <artifactId>mule-framework-bom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.mulesoft.mule.framework</groupId>
                    <artifactId>mule-framework-classpath</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.mulesoft.mule.framework</groupId>
                    <artifactId>mule-framework-service-diet-scheduler</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-test-utils</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-test-connectors-resolver</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mule.weave</groupId>
            <artifactId>runtime</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-invoker</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>javax.inject</groupId>
                    <artifactId>javax.inject</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4jVersion}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit5</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.tika</groupId>
                    <artifactId>tika-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.wiremock</groupId>
            <artifactId>wiremock</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.mule.framework</groupId>
            <artifactId>mule-framework-static-requirements-bundle</artifactId>
            <type>zip</type>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- TODO W-13712868 - remove if support for Java 8 is dropped -->
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <!-- This is needed only for jdk8, the required classes from here -->
            <!-- are already available in the jdk on versions 11+ -->
            <scope>provided</scope>
        </dependency>
    </dependencies>

</project>
