<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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.tooling</groupId>
        <artifactId>mule-runtime-tooling-client-parent</artifactId>
        <version>4.0.3-hf1</version>
    </parent>

    <artifactId>mule-agent-rest-client</artifactId>
    <name>Mule Runtime Tooling Client :: Mule Agent REST</name>
    <description>REST Client for Mule Agent Tooling Services</description>

    <properties>
        <formatterConfigPath>../formatter.xml</formatterConfigPath>
        <runtime.location>${project.build.directory}/runtimes</runtime.location>
        <mule.distribution.folder>mule-enterprise-standalone-${mule.version}</mule.distribution.folder>
        <mulePluginClassifier>mule-plugin</mulePluginClassifier>
    </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-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skip>true</skip>
                    <systemProperties>
                        <property>
                            <name>MULE_HOME</name>
                            <value>${runtime.location}/${mule.distribution.folder}</value>
                        </property>
                        <property>
                            <name>mule.agent.version</name>
                            <value>${mule.agent.version}</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.19.1</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8 -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectjVersion}/aspectjweaver-${aspectjVersion}.jar -javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile='${session.executionRootDirectory}/target/jacoco-it.exec'</argLine>
                    <includes>
                        <include>**/*TestCase</include>
                    </includes>
                    <systemPropertyVariables>
                        <property>
                            <mule.agent.version>${mule.agent.version}</mule.agent.version>
                        </property>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.tooling</groupId>
            <artifactId>mule-tooling-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mule.runtime</groupId>
            <artifactId>mule-extensions-api-persistence</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-base</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.agent</groupId>
            <artifactId>mule-agent-web-interface</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.agent</groupId>
            <artifactId>mule-agent-api</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>com.mulesoft.mule.distributions</groupId>
            <artifactId>mule-ee-distribution-standalone</artifactId>
            <version>${mule.version}</version>
            <type>tar.gz</type>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.agent</groupId>
            <artifactId>mule-agent-plugin</artifactId>
            <version>${mule.agent.version}</version>
            <classifier>mule-server-plugin</classifier>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

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

        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</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.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <scope>test</scope>
        </dependency>
        
        
    </dependencies>

    <profiles>
        <profile>
            <id>prepare-integration-tests</id>
            <activation>
                <property>
                    <name>skipPrepareIntegrationTests</name>
                    <value>!true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>com.mulesoft.agent</groupId>
                                <artifactId>mule-agent-plugin</artifactId>
                                <version>${mule.agent.version}</version>
                                <classifier>mule-server-plugin</classifier>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>unpack-mule-standalone</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.mulesoft.mule.distributions</groupId>
                                            <artifactId>mule-ee-distribution-standalone</artifactId>
                                            <version>${mule.version}</version>
                                            <type>tar.gz</type>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${runtime.location}</outputDirectory>
                                    <overWriteReleases>true</overWriteReleases>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-agent-mule</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeArtifactIds>mule-agent-plugin</includeArtifactIds>
                                    <outputDirectory>${runtime.location}/${mule.distribution.folder}/server-plugins/</outputDirectory>
                                    <overWriteReleases>true</overWriteReleases>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>configure-pristine-runtimes</id>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <target>
                                        <copy file="${project.build.testOutputDirectory}/descriptors/mule-agent.yml" todir="${runtime.location}/${mule.distribution.folder}/conf/" overwrite="true" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
