<?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.14.0-SNAPSHOT</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.14.0-SNAPSHOT</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.3.0-SNAPSHOT</mule.sdk.api.version>
        <mule.extensions.ast.loader.version>1.13.0-SNAPSHOT</mule.extensions.ast.loader.version>
        <mule.extensions.maven.plugin.version>1.14.0-SNAPSHOT</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>

        <!-- Sourced from the BOM's errorProneVersion property, resolved when this template is filtered
             at holder-module build time (the reactor's parent chain inherits it from
             mule-runtime-bom-parent). -->
        <errorprone.version>2.42.0</errorprone.version>

        <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.7.1-SNAPSHOT</munit.extensions.maven.plugin.version>
        <munit.version>3.7.4-SNAPSHOT</munit.version>

        <maven.source.plugin.version>3.4.0</maven.source.plugin.version>
        <maven.resources.plugin.version>3.5.0</maven.resources.plugin.version>
        <maven.clean.plugin.version>3.5.0</maven.clean.plugin.version>
        <maven.compiler.plugin.version>3.16.0</maven.compiler.plugin.version>
        <maven.install.plugin.version>3.2.0</maven.install.plugin.version>
        <maven.deploy.plugin.version>3.2.0</maven.deploy.plugin.version>
        <maven.jar.plugin.version>3.5.1</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>
                            <!-- Error Prone itself is loaded as a compiler plugin (-Xplugin below), not a
                                 JSR-269 annotation processor - it just needs to be on this path so its
                                 classes (and mule-extensions-errorprone-checks', registered against it via
                                 @AutoService) are on the compiler's own classpath. -->
                            <path>
                                <groupId>com.google.errorprone</groupId>
                                <artifactId>error_prone_core</artifactId>
                                <version>${errorprone.version}</version>
                            </path>
                            <path>
                                <groupId>org.mule.runtime.plugins</groupId>
                                <artifactId>mule-extensions-errorprone-checks</artifactId>
                                <version>${mule.extensions.maven.plugin.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>
                            <!-- Static path (resolved at model build time) of the file the supported-java-versions goal writes
                                 the configured <supportedJavaVersions> into; read by the extension annotation processor. -->
                            <arg>-Aextension.supportedJavaVersions.file=${project.build.directory}/generated-resources/mule/supported-java-versions.json</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>
                    <executions>
                        <!-- The Error Prone activation below is scoped to default-compile ONLY, not
                             default-testCompile. javax.inject findings are recorded to a single shared
                             file (mule-javax-inject-findings.txt) that JavaxInjectUsageCheck's constructor
                             clears on every javac invocation that loads it (see that class for why). If
                             this activation lived in the shared top-level <configuration> above, Maven
                             would apply it to default-testCompile too - and any connector with test
                             sources (the common case) would reconstruct the checker there and wipe the
                             main-source findings before extension-validate ever reads them, silently
                             suppressing the warning. Scoping to default-compile keeps the checker running
                             exactly once per build, against main sources only. -->
                        <execution>
                            <id>default-compile</id>
                            <configuration>
                                <fork>true</fork>
                                <!-- combine.children="append" is required here: without it, Maven's
                                     execution-level <compilerArgs> replaces the shared top-level
                                     <compilerArgs> (the -Aextension.version=... etc. args above) wholesale
                                     instead of adding to it, silently dropping them from default-compile. -->
                                <compilerArgs combine.children="append">
                                    <!-- Records javax.inject usages to a findings file for extension-validate (verify
                                         phase) to warn on, gated on this connector's *computed* minMuleVersion. See
                                         mule-extensions-errorprone-checks' JavaxInjectUsageCheck for the full rationale,
                                         including why the MMV gate lives solely in extension-validate. -->
                                    <arg>-XDcompilePolicy=simple</arg>
                                    <arg>--should-stop=ifError=FLOW</arg>
                                    <arg>-Xplugin:ErrorProne -XepOpt:MuleJavaxInject:FindingsFile=${project.build.directory}/mule-javax-inject-findings.txt</arg>
                                    <!-- Error Prone runs INSIDE the connector's own javac process, as the "-Xplugin"
                                         above rather than a JSR-269 annotation processor. Because of that, the module
                                         graph that needs patching to let error_prone_core (and its javac-internal
                                         dependencies) see com.sun.tools.javac.* is the HOST JVM's - i.e. the javac
                                         launcher process forked below - not the target of compilation. That is done
                                         with JVM-level launcher flags, which javac only recognizes with the "-J"
                                         prefix, and only takes effect in a forked process (fork=true below); a
                                         same-JVM (non-forked) javac invocation cannot re-open its own already-running
                                         module graph this way. Contrast with mule-extensions-errorprone-checks' own
                                         pom, which compiles source that imports com.sun.tools.javac.* directly by
                                         name - there, the plain (non "-J"-prefixed) add-exports compiler flag
                                         suffices, and no fork is needed. -->
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
                                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
                                    <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
                                    <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
                                </compilerArgs>
                            </configuration>
                        </execution>
                    </executions>
                </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>
