<?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>
    <groupId>com.avioconsulting.mule</groupId>
    <artifactId>mule-deploy-library</artifactId>
    <packaging>jar</packaging>
    <name>Mule deployment library</name>
    <description>Deploys Mule applications via Runtime Manager APIs</description>
    <parent>
        <groupId>com.avioconsulting.mule</groupId>
        <artifactId>mule-deploy-parent</artifactId>
        <version>1.2.0</version>
    </parent>

    <properties>
        <apache.http.version>4.5.13</apache.http.version>
        <log4j2.version>2.17.1</log4j2.version>
        <generate.file.for.testing>false</generate.file.for.testing>
        <pitest.version>1.5.0</pitest.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>3.7.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>${groovy.compiler.version}-03</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>com.bluetrainsoftware.maven</groupId>
                <artifactId>groovydoc-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <destinationDirectory>${project.build.directory}/site/groovydocs</destinationDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.8.2</version>
                <configuration>
                    <validate>true</validate>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <systemPropertyVariables>
                        <!-- Allows plugin to use the Maven version we are running with  -->
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <excludes>
                                <exclude>**/IntegrationTest.java</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test</id>
                        <phase>none</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/IntegrationTest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.sparow199</groupId>
                <artifactId>apollo-client-maven-plugin</artifactId>
                <version>2.3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generateIntrospectionFile>true</generateIntrospectionFile>
                            <schemaUrl>https://anypoint.mulesoft.com/graph/api/v1/graphql</schemaUrl>
                            <rootPackageName>com.avioconsulting.mule.deployment.internal.models.graphql</rootPackageName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <id>generate-gdsl</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <output.dir>${project.build.outputDirectory}</output.dir>
                                <generate.file.for.testing>${generate.file.for.testing}</generate.file.for.testing>
                            </properties>
                            <classpathScope>runtime</classpathScope>
                            <source>import com.avioconsulting.mule.deployment.api.models.AwsRegions
                            import com.avioconsulting.mule.deployment.api.models.Features
                            import com.avioconsulting.mule.deployment.api.models.HttpMethod
                            import com.avioconsulting.mule.deployment.api.models.WorkerTypes
                            import org.apache.commons.io.FileUtils

                            def engine = new org.apache.velocity.app.VelocityEngine()
                            engine.setProperty(org.apache.velocity.runtime.RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
                                               properties['output.dir'])
                            engine.init()
                            def templateFileName = 'evaluate.gdsl.vm'
                            def template = engine.getTemplate(templateFileName)
                            def context = new org.apache.velocity.VelocityContext()
                            context.put('workerTypes',
                                        WorkerTypes.values().collect { v -> v.name().toLowerCase() })
                            context.put('awsRegions',
                                        AwsRegions.values().collect { v -> v.name().toLowerCase() })
                            context.put('httpMethods',
                                        HttpMethod.values().collect { v -> v.name().toLowerCase() })
                            context.put('features',
                                        Features.values().collect { v -> v.name().uncapitalize() })
                            def file = new File(properties['output.dir'],
                                                'evaluate.gdsl')
                            def writer = new OutputStreamWriter(new FileOutputStream(file))
                            template.merge(context,
                                           writer)
                            writer.close()
                            new File(properties['output.dir'],
                                     templateFileName).delete()
                            if (properties['generate.file.for.testing'] == 'true') {
                                println 'making a copy for testing'
                                FileUtils.copyFileToDirectory(file,
                                                              new File('src/main/resources'))
                            }
                            </source>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.velocity</groupId>
                        <artifactId>velocity-engine-core</artifactId>
                        <version>2.1</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!-- Right now pitest does not fully support Groovy but it can be slightly informative anyways -->
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>${pitest.version}</version>
                <configuration>
                    <coverageThreshold>89</coverageThreshold>
                    <mutationThreshold>48</mutationThreshold>
                    <threads>2</threads>
                    <excludedClasses>
                        <!-- We did not write these, generated code -->
                        <excludedClass>com.avioconsulting.mule.deployment.internal.models.graphql.*</excludedClass>
                        <!-- Groovy's equality code -->
                        <excludedClass>com.avioconsulting.mule.deployment.internal.models.CloudhubAppProperties</excludedClass>
                        <excludedClass>com.avioconsulting.mule.deployment.internal.models.ExistingPolicy</excludedClass>
                        <excludedClass>com.avioconsulting.mule.deployment.internal.models.ExistingApiSpec</excludedClass>
                        <excludedClass>com.avioconsulting.mule.deployment.internal.models.ResolvedApiSpec</excludedClass>
                    </excludedClasses>
                    <excludedTestClasses>
                        <excludedTestClass>com.avioconsulting.mule.integrationtest.IntegrationTest</excludedTestClass>
                    </excludedTestClasses>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>${pitest.version}</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>

    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>${groovy.compiler.version}</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-json</artifactId>
            <version>${groovy.compiler.version}</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-xml</artifactId>
            <version>${groovy.compiler.version}</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-nio</artifactId>
            <version>${groovy.compiler.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mule.apikit</groupId>
            <artifactId>parser-service</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-test</artifactId>
            <version>${groovy.compiler.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-ant</artifactId>
            <version>${groovy.compiler.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${apache.http.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>${apache.http.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.10.5.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.10.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.10.2</version>
        </dependency>
        <dependency>
            <groupId>com.apollographql.apollo</groupId>
            <artifactId>apollo-api</artifactId>
            <version>1.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>19.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-web</artifactId>
            <version>3.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.10.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-invoker</artifactId>
            <version>3.0.1</version>
            <scope>test</scope>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.apache.logging.log4j</groupId>-->
<!--            <artifactId>log4j-1.2-api</artifactId>-->
<!--            <version>${log4j2.version}</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.apache.logging.log4j</groupId>-->
<!--            <artifactId>log4j-core</artifactId>-->
<!--            <version>${log4j2.version}</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->
    </dependencies>

    <repositories>
        <repository>
            <id>android</id>
            <url>https://dl.bintray.com/apollographql/android/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>groovy</id>
            <name>Groovy</name>
            <layout>default</layout>
            <url>https://groovy.jfrog.io/artifactory/libs-release-local</url>
            <snapshots>

            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>
