<?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>org.mule.tooling</groupId>
        <artifactId>mule-runtime-tooling-client-parent</artifactId>
        <version>4.7.3</version>
    </parent>

    <artifactId>mule-runtime-tooling-tests</artifactId>
    <name>Mule Runtime Tooling Client :: Tests</name>
    <description>Integration Tests for Mule Runtime Tooling Client</description>

    <properties>
        <formatterConfigPath>../formatter.xml</formatterConfigPath>
        <mulePluginClassifier>mule-plugin</mulePluginClassifier>
        <httpClient.version>4.5.13</httpClient.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.plugin.version}</version>
                    <configuration>
                        <argLine>--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.xml/javax.xml.namespace=ALL-UNNAMED --add-exports java.base/sun.net.www.protocol.jar=ALL-UNNAMED</argLine>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <testResources>
            <testResource>
                <filtering>true</filtering>
                <directory>${basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-tooling-bootstrap</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-runtime-tooling-tests-utils</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.kristofa</groupId>
            <artifactId>mock-http-server</artifactId>
            <version>4.1</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.mockftpserver</groupId>
            <artifactId>MockFtpServer</artifactId>
            <version>2.7.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>xmlunit</groupId>
            <artifactId>xmlunit</artifactId>
            <version>1.6</version>
            <scope>test</scope>
        </dependency>

        <!-- Conflicts with transtive dependencies from wiremock and test-utils from MTS -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpClient.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-1.2-api</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Just to let Maven build this project at the end of the reactor, these dependencies cannot be included in surefire classpath -->
        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-runtime-tooling-client</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit4</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-marvel-extension</artifactId>
            <version>${marvelExtensionVersion}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.194</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-unit</artifactId>
            <version>${mule.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.mule.skyscreamer</groupId>
            <artifactId>jsonassert</artifactId>
            <version>${jsonassert.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>tooling-agent-plugin</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.mule.runtime</groupId>
                    <artifactId>mule-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mule.sdk</groupId>
                    <artifactId>mule-sdk-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mule.runtime</groupId>
                    <artifactId>mule-extensions-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>tooling-support-test-extension</artifactId>
            <type>test-jar</type>
            <version>${toolingSupportTestExtensionVersion}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>



    <profiles>
        <profile>
            <id>testJdkWithoutXmlModule</id>
            <activation>
                <!-- This profile cannot be activated based on the jdk because the jdk on which this has to be activated or not -->
                <!-- is the one used to run the tests, not the one used to run Maven. -->
                <property>
                    <name>!testJdkWithXmlModule</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.5.0</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>properties</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${maven.surefire.plugin.version}</version>
                        <configuration>
                            <argLine>--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.xml/javax.xml.namespace=ALL-UNNAMED --add-exports java.base/sun.net.www.protocol.jar=ALL-UNNAMED</argLine>
                            <additionalClasspathElements>
                                <!-- Add this to the classpath so it is available when running tests with jvm8 -->
                                <!-- but it does not interfere with the module system -->
                                <!-- (it has colliding packages with java.xml module) when running with java11+ -->
                                <additionalClasspathElement>${org.mule.apache:xerces2-xsd11:jar:}</additionalClasspathElement>
                            </additionalClasspathElements>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <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>
        </profile>
        <profile>
            <id>prepare-integration-tests</id>
            <activation>
                <property>
                    <name>skipPrepareIntegrationTests</name>
                    <value>!true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-invoker-plugin</artifactId>
                        <version>3.1.0</version>
                        <configuration>
                            <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
                            <goals>install</goals>
                        </configuration>
                        <executions>
                            <execution>
                                <id>process-test-resources</id>
                                <phase>process-test-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-tooling-bundle</id>
                                <phase>process-test-resources</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.mule.tooling</groupId>
                                            <artifactId>mule-runtime-tooling-client-bundle</artifactId>
                                            <version>${project.version}</version>
                                            <type>zip</type>
                                            <classifier>zip</classifier>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/tooling-client-bundle</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                            <execution>
                                <id>get-extensions</id>
                                <phase>process-test-resources</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.mulesoft.anypoint</groupId>
                                            <artifactId>mule-http-proxy-extension</artifactId>
                                            <version>${agwHttpProxyExtensionVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.modules</groupId>
                                            <artifactId>mule-module-file-extension-common</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-ftp-connector</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-file-connector</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-db-connector</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-email-connector</artifactId>
                                            <version>1.0.0</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-http-connector</artifactId>
                                            <version>${muleHttpFixedConnectorVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-sockets-connector</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-jms-connector</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.modules</groupId>
                                            <artifactId>mule-validation-module</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.connectors</groupId>
                                            <artifactId>mule-wsc-connector</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.modules</groupId>
                                            <artifactId>mule-spring-module</artifactId>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <!-- smart connectors samples below -->
                                        <artifactItem>
                                            <groupId>org.mule.tests</groupId>
                                            <artifactId>smart-connector-using-core</artifactId>
                                            <version>${smartConnectorUsingCoreVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.tests</groupId>
                                            <artifactId>smart-connector-using-custom-types</artifactId>
                                            <version>${smartConnectorUsingCustomTypesVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.tooling</groupId>
                                            <artifactId>smart-connector-using-dw</artifactId>
                                            <version>${project.version}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.tests</groupId>
                                            <artifactId>smart-connector-using-file</artifactId>
                                            <version>${smartConnectorUsingFileVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.tests</groupId>
                                            <artifactId>smart-connector-using-http</artifactId>
                                            <version>${smartConnectorUsingHttpVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.mule.tests</groupId>
                                            <artifactId>smart-connector-using-smart-connector</artifactId>
                                            <version>${smartConnectorUsingSmartConnectorVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                        <!-- Test Extensions -->
                                        <artifactItem>
                                            <groupId>org.mule.tests</groupId>
                                            <artifactId>test-crafted-extension</artifactId>
                                            <version>${testCraftedExtensionVersion}</version>
                                            <classifier>${mulePluginClassifier}</classifier>
                                            <overWrite>true</overWrite>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${project.build.directory}/extensions</outputDirectory>
                                    <useBaseVersion>true</useBaseVersion>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

            <dependencies>
                <dependency>
                    <groupId>org.mule.tooling</groupId>
                    <artifactId>mule-runtime-tooling-client-bundle</artifactId>
                    <version>${project.version}</version>
                    <classifier>zip</classifier>
                    <type>zip</type>
                    <exclusions>
                        <exclusion>
                            <groupId>*</groupId>
                            <artifactId>*</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <activation>
                <jdk>17</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${maven.surefire.plugin.version}</version>
                        <configuration>
                            <argLine>--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.xml/javax.xml.namespace=ALL-UNNAMED --add-exports java.base/sun.net.www.protocol.jar=ALL-UNNAMED</argLine>
                            <excludedGroups>NeedsJava8Test</excludedGroups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>java11</id>
            <activation>
                <jdk>11</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${maven.surefire.plugin.version}</version>
                        <configuration>
                            <argLine>--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.xml/javax.xml.namespace=ALL-UNNAMED --add-exports java.base/sun.net.www.protocol.jar=ALL-UNNAMED</argLine>
                            <excludedGroups>NeedsJava8Test</excludedGroups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>session-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${maven.surefire.plugin.version}</version>
                        <configuration>
                            <argLine>--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.xml/javax.xml.namespace=ALL-UNNAMED --add-exports java.base/sun.net.www.protocol.jar=ALL-UNNAMED</argLine>
                            <groups>org.mule.tooling.client.tests.integration.tooling.client.services.SessionTest</groups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <properties>
                <skipNoSnapshotsEnforcerPluginRule>false</skipNoSnapshotsEnforcerPluginRule>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <version>${maven.enforcer.plugin.version}</version>
                        <executions>
                            <execution>
                                <id>enforce-no-snapshots-in-deps</id>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <requireReleaseDeps>
                                            <message>No Snapshots Allowed in Deps!</message>
                                        </requireReleaseDeps>
                                        <requireReleaseVersion>
                                            <message>No Snapshots Allowed in Project Version!</message>
                                        </requireReleaseVersion>
                                        <requirePluginVersions>
                                            <message>Best Practice is to always define plugin versions!</message>
                                            <unCheckedPluginList>
                                                org.apache.maven.plugins:maven-clean-plugin,
                                                org.apache.maven.plugins:maven-install-plugin,
                                                org.apache.maven.plugins:maven-source-plugin,
                                                org.apache.maven.plugins:maven-site-plugin,
                                                org.apache.maven.plugins:maven-javadoc-plugin,
                                                org.apache.maven.plugins:maven-deploy-plugin,
                                                org.apache.maven.plugins:maven-resources-plugin,
                                                org.apache.maven.plugins:maven-jar-plugin,
                                                org.apache.maven.plugins:maven-surefire-plugin
                                            </unCheckedPluginList>
                                        </requirePluginVersions>
                                    </rules>
                                    <skip>${skipNoSnapshotsEnforcerPluginRule}</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
 </project>
