<?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>

    <groupId>org.mule.extensions</groupId>
    <artifactId>mule-java-extension-parent</artifactId>
    <version>1.11.2</version>
    <packaging>pom</packaging>

    <name>Mule Java Extensions Parent POM</name>
    <description>Mule modules that augment the core Mule functionality through the Mule SDK API</description>

    <properties>
        <!-- this determines the version of the mule dependencies for the compiler annotation processor -->
        <mule.version>4.11.2</mule.version>
        <!-- lowest version provides the stuff required by sdk-api -->
        <mule.api.version>1.5.0</mule.api.version>
        <mule.sdk.api.version>1.0.0</mule.sdk.api.version>
        <mule.extensions.ast.loader.version>1.10.2</mule.extensions.ast.loader.version>
        <mule.extensions.maven.plugin.version>1.11.2</mule.extensions.maven.plugin.version>

        <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
        <java.release.version>17</java.release.version>
        <maven.compiler.release>${java.release.version}</maven.compiler.release>
        <maven.build.timestamp.format>yyyy-MM-dd-HH:mm:ss</maven.build.timestamp.format>
        
        <extensionsAnnotationProcessorCompileProc></extensionsAnnotationProcessorCompileProc>
        <extensionsAnnotationProcessor>
            org.mule.runtime.ast.extension.api.loader.ASTExtensionResourcesGeneratorAnnotationProcessor
        </extensionsAnnotationProcessor>
        <exportedPackagesValidator.skip>false</exportedPackagesValidator.skip>
        <exportedPackagesValidator.strictValidation>false</exportedPackagesValidator.strictValidation>
        
        <munit.input.directory>src/test/munit</munit.input.directory>
        <munit.output.directory>${basedir}/target/test-mule/munit</munit.output.directory>
        <munit.extensions.maven.plugin.version>1.6.1</munit.extensions.maven.plugin.version>
        <munit.version>3.6.3</munit.version>

        <maven.source.plugin.version>3.4.0</maven.source.plugin.version>
        <maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>
        <maven.clean.plugin.version>3.5.0</maven.clean.plugin.version>
        <maven.compiler.plugin.version>3.14.1</maven.compiler.plugin.version>
        <maven.install.plugin.version>3.1.4</maven.install.plugin.version>
        <maven.deploy.plugin.version>3.1.4</maven.deploy.plugin.version>
        <maven.jar.plugin.version>3.5.0</maven.jar.plugin.version>
        <maven.javadoc.plugin.version>3.12.0</maven.javadoc.plugin.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.mule.runtime</groupId>
                <artifactId>mule-api</artifactId>
                <version>${mule.api.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.mule.sdk</groupId>
                <artifactId>mule-sdk-api</artifactId>
                <version>${mule.sdk.api.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven.compiler.plugin.version}</version>
                    <configuration>
                        <encoding>ISO-8859-1</encoding>
                        <release>${java.release.version}</release>
                        <proc>${extensionsAnnotationProcessorCompileProc}</proc>
                        <parameters>true</parameters>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.mule.runtime</groupId>
                                <artifactId>mule-extension-ast-loader</artifactId>
                                <version>${mule.extensions.ast.loader.version}</version>
                            </path>
                            <path>
                                <groupId>org.mule.runtime</groupId>
                                <artifactId>mule-module-extensions-spring-support</artifactId>
                                <version>${mule.version}</version>
                            </path>
                        </annotationProcessorPaths>
                        <annotationProcessors>
                            <annotationProcessors>${extensionsAnnotationProcessor}</annotationProcessors>
                        </annotationProcessors>
                        <compilerArgs>
                            <arg>-Aextension.version=${project.version}</arg>
                            <arg>-Aextension.resources=${project.build.resources[0].directory}</arg>
                            <arg>-AexportedPackagesValidator.skip=${exportedPackagesValidator.skip}</arg>
                            <arg>-AexportedPackagesValidator.strictValidation=${exportedPackagesValidator.strictValidation}</arg>
                        </compilerArgs>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.mule.runtime</groupId>
                            <artifactId>mule-api</artifactId>
                            <version>${mule.api.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.mule.sdk</groupId>
                            <artifactId>mule-sdk-api</artifactId>
                            <version>${mule.sdk.api.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.mule.runtime.plugins</groupId>
                    <artifactId>mule-extensions-maven-plugin</artifactId>
                    <version>${mule.extensions.maven.plugin.version}</version>
                    <extensions>true</extensions>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven.resources.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>copy-munit-resources</id>
                            <phase>process-test-resources</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${munit.output.directory}</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>${munit.input.directory}</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>com.mulesoft.munit</groupId>
                    <artifactId>munit-extensions-maven-plugin</artifactId>
                    <version>${munit.extensions.maven.plugin.version}</version>
                    <dependencies>
                        <!-- MUnit Dependencies -->
                        <dependency>
                            <groupId>com.mulesoft.munit</groupId>
                            <artifactId>munit-runner</artifactId>
                            <version>${munit.version}</version>
                            <classifier>mule-plugin</classifier>
                        </dependency>
                        <dependency>
                            <groupId>com.mulesoft.munit</groupId>
                            <artifactId>munit-tools</artifactId>
                            <version>${munit.version}</version>
                            <classifier>mule-plugin</classifier>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.plugin.version}</version>
                <configuration>
                    <archive>
                        <!--
                            Disabled for http://mule.mulesoft.org/jira/browse/MULE-1153
                            and http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526
                         -->
                        <index>false</index>
                        <!-- List dependencies in the MANIFEST.MF -->
                        <manifest>
                            <!-- Note that we do not generate a classpath into the manifest, since doing so
                                 significnatly slows down compilations that use the jar -->
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Build-Date>${maven.build.timestamp}</Build-Date>
                            <!-- Custom Entries -->
                            <Target-Java-Release-Version>${java.release.version}</Target-Java-Release-Version>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mule.runtime.plugins</groupId>
                <artifactId>mule-extensions-maven-plugin</artifactId>
            </plugin>

            <!-- Maven Plugins -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>${maven.clean.plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven.source.plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>${maven.install.plugin.version}</version>
                <configuration>
                    <!-- allow for publishing a jar file even if the packaging is mule-extension -->
                    <allowIncompleteProjects>true</allowIncompleteProjects>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>${maven.deploy.plugin.version}</version>
                <configuration>
                    <!-- allow for publishing a jar file even if the packaging is mule-extension -->
                    <allowIncompleteProjects>true</allowIncompleteProjects>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>${maven.javadoc.plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doclint>none</doclint>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>mule</id>
            <name>Mule Repository</name>
            <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-plugin-releases</id>
            <name>MuleSoft Release Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </pluginRepository>
        <pluginRepository>
            <id>mulesoft-plugin-snapshots</id>
            <name>MuleSoft Snapshots Repository</name>
            <url>https://repository.mulesoft.org/snapshots/</url>
            <layout>default</layout>
        </pluginRepository>
    </pluginRepositories>

    <profiles>
        <profile>
            <id>skip-ast</id>
            <activation>
                <property>
                    <name>skipAst</name>
                </property>
            </activation>
            <properties>
                <!-- Prevent doing the annotation processing during compilation, because compiled classes are not available yet -->
                <extensionsAnnotationProcessorCompileProc>none</extensionsAnnotationProcessorCompileProc>
                <extensionsAnnotationProcessor>org.mule.runtime.module.extension.api.resources.ExtensionResourcesGeneratorAnnotationProcessor</extensionsAnnotationProcessor>
            </properties>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <executions>
                                <!-- Do just the annotation processing part, but with access to the compiled classes -->
                                <execution>
                                    <phase>compile</phase>
                                    <id>post-compile-annotaiton-processing</id>
                                    <goals>
                                        <goal>compile</goal>
                                    </goals>
                                    <configuration>
                                        <proc>only</proc>
                                        <compilerArgs combine.children="append">
                                            <arg>-Aextension.classes=${project.build.outputDirectory}</arg>
                                        </compilerArgs>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>

</project>
