<?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>
    <parent>
        <groupId>com.mulesoft.mule.distributions</groupId>
        <artifactId>mule-ee-distributions</artifactId>
        <version>4.8.0-mule-ic-custom-dev-runtime-SNAPSHOT</version>
    </parent>
    <artifactId>mule-ee-distribution-standalone</artifactId>
    <packaging>pom</packaging>
    <name>Standalone Distribution</name>
    <description>Includes the Mule server with all of its APIs and internal modules</description>

    <properties>
        <standaloneStructureDir>${project.build.directory}/distribution-structure</standaloneStructureDir>
        <standaloneStructure>mule-standalone-structure</standaloneStructure>
        
        <libPatchesOutputDir>${project.build.directory}/lib/patches</libPatchesOutputDir>
        <muleArtifactsPatchesOutputDir>${libPatchesOutputDir}/mule-artifact-patches</muleArtifactsPatchesOutputDir>

        <formatterConfigPath>../formatter.xml</formatterConfigPath>
        <groovyAllVersion>2.4.19</groovyAllVersion>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <!--
                         These have to happen early in the build lifecycle so that plugins running
                         later in the build lifecycle can work on the unpacked distro.
                    --> 
                    <execution>
                        <id>unpack-mule-config-files</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeArtifactIds>mule-config-files</includeArtifactIds>
                            <outputDirectory>${project.build.directory}/dependency-config-files</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-standaloneStructure</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeArtifactIds>${standaloneStructure}</includeArtifactIds>
                            <outputDirectory>${standaloneStructureDir}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-agent-setup</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeArtifactIds>agent-setup</includeArtifactIds>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-wrapper-delta-pack</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeArtifactIds>wrapper-delta-pack</includeArtifactIds>
                            <outputDirectory>${project.build.directory}/wrapper</outputDirectory>
                            <fileMappers>
                                <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                    <pattern>wrapper-delta-pack-\d+\.\d+\.\d+-st/</pattern>
                                    <replacement>./</replacement>
                                </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>                                
                            </fileMappers>
                            <includes>*/lib/**,*/bin/**</includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-container-app-plugins-jar-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/plugins</outputDirectory>
                            <includeTypes>jar</includeTypes>
                            <includeGroupIds>
                                org.mule.modules,com.mulesoft.mule.modules
                            </includeGroupIds>
                            <includeClassifiers>mule-plugin</includeClassifiers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>standalone</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>mule-enterprise-standalone-${project.version}</finalName>
                            <descriptors>
                                <descriptor>src/assembly/assembly.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                            <tarLongFileMode>posix</tarLongFileMode>
                        </configuration>
                    </execution>
                    <execution>
                        <id>cumulative-patch</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                </manifest>
                                <manifestEntries>
                                    <Build-Revision>${buildNumber}</Build-Revision>
                                    <Build-Date>${timestamp}</Build-Date>
                                </manifestEntries>
                            </archive>
                            <finalName>mule-enterprise-standalone-${project.version}</finalName>
                            <descriptors>
                                <descriptor>src/assembly/assembly-patch.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>true</appendAssemblyId>
                            <tarLongFileMode>posix</tarLongFileMode>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.mulesoft.mule.distributions</groupId>
                        <artifactId>container-descriptor-handler</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.mule.tools</groupId>
                <artifactId>mule-assembly-verifier</artifactId>
                <configuration>
                    <skip>${skipVerifications}</skip>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <projectOutputFile>mule-enterprise-standalone-${project.version}.zip</projectOutputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.1.1</version>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>${groovyAllVersion}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <defaults>
                                <basedir>${project.basedir}</basedir>
                            </defaults>
                            <source>${project.basedir}/src/main/groovy/buildtools/GenerateModulesRepositoryInformation.groovy</source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
                 We generate a full source bundle using the groovy plugin above. Do not
                 publish maven's autogenerated and empty sources jar of this module.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <attach>false</attach>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.nicoulaj.maven.plugins</groupId>
                <artifactId>checksum-maven-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>artifacts</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <attachChecksums>true</attachChecksums>
                    <algorithms>
                        <algorithm>SHA-256</algorithm>
                    </algorithms>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>
                <configuration>
                    <includes>
                        <include>**/*TestCase.java</include>
                    </includes>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${basedir}/src/main/groovy</additionalClasspathElement>
                    </additionalClasspathElements>
                    <systemPropertyVariables>
                        <baseDir>${project.basedir} </baseDir>
                        <outputDir>${project.build.directory}</outputDir>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-build-distribution-metadata</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.basedir}/target/BUILD.json</file>
                                    <type>json</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.mulesoft.mule.distributions</groupId>
            <artifactId>support-tools-installer</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.mule.distributions</groupId>
            <artifactId>mule-runtime-impl-bom</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.mule.runtime.boot</groupId>
            <artifactId>mule-module-boot-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.mule.runtime.boot</groupId>
            <artifactId>mule-module-tanuki-boot</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Overwrite Jackson dependency with our own version -->
        <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.module</groupId>
            <artifactId>jackson-module-jsonSchema</artifactId>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </dependency>

        <!-- Mule distribution structure -->

        <dependency>
            <groupId>com.mulesoft.mule.distributions</groupId>
            <artifactId>mule-config-files</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.agent</groupId>
            <artifactId>agent-setup</artifactId>
            <type>zip</type>
        </dependency>

        <dependency>
            <groupId>org.mule.distributions</groupId>
            <artifactId>${standaloneStructure}</artifactId>
            <version>${project.version}</version>
            <type>tar.gz</type>
        </dependency>

        <dependency>
            <groupId>org.mule.distributions</groupId>
            <artifactId>mule-wrapper-additional-parameters-parser</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.mulesoft.mule.distributions</groupId>
            <artifactId>mule-wrapperless-arguments-resolver</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>tanukisoft</groupId>
            <artifactId>wrapper-delta-pack</artifactId>
            <type>tar.gz</type>
        </dependency>

        <!-- It's picking this up from CE and we have a new version for EE -->
        <dependency>
            <groupId>tanukisoft</groupId>
            <artifactId>wrapper</artifactId>
        </dependency>

        <!-- API Gateway -->
        <dependency>
            <groupId>com.mulesoft.mule.distributions</groupId>
            <artifactId>api-gateway-bom-impl</artifactId>
            <type>pom</type>
        </dependency>

        <!-- Mule Artifact patches -->
        <dependency>
            <groupId>com.mulesoft.mule.runtime.bom</groupId>
            <artifactId>mule-artifact-patches-bom</artifactId>
            <type>pom</type>
            <exclusions>
                <!-- Remove patches that are applied to the compatibility-plugin -->
                <exclusion>
                    <groupId>
                        com.mulesoft.mule.artifact.patches
                    </groupId>
                    <artifactId>EE-7996-1.2.2-1.2.1-1.2.0</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>
                        com.mulesoft.mule.artifact.patches
                    </groupId>
                    <artifactId>EE-7996-1.1.2</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>
                        com.mulesoft.mule.artifact.patches
                    </groupId>
                    <artifactId>EE-7996-1.1.1</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-unit</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.objenesis</groupId>
                    <artifactId>objenesis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>${groovyAllVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
