<?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.connectors</groupId>
        <artifactId>mule4-connectors-parent</artifactId>
        <version>2.0.7</version>
    </parent>
    <groupId>org.mule.modules</groupId>
    <artifactId>mule-scripting-module</artifactId>
    <packaging>mule-extension</packaging>
    <version>2.1.2</version>
    <name>Scripting Module</name>
    <description>Support for embedding scripts inside Mule artifacts</description>
    <properties>
        <formatterConfigPath>formatter.xml</formatterConfigPath>
        <jython.version>2.7.4</jython.version>
        <groovy.version>3.0.25</groovy.version>
        <jruby.version>9.4.15.0</jruby.version>
        <jruby.jdk25.version>10.1.1.0</jruby.jdk25.version>
        <graal.version>22.0.0</graal.version>
        <rhino.engine.version>1.9.1</rhino.engine.version>
        <project.reactor.version>3.8.6</project.reactor.version>
        <file.connector.version>1.5.6</file.connector.version>
        <mulesoftLicenseVersion>1.4.0</mulesoftLicenseVersion>
        <licensePath>LICENSE_HEADER_CPAL.txt</licensePath>
        <licenseYear>2023</licenseYear>
        <commons.lang.version>3.20.0</commons.lang.version>
        <munit.extensions.maven.plugin.version>1.7.1-rc1</munit.extensions.maven.plugin.version>
        <munit.version>3.7.1-rc1</munit.version>
        <mtf.tools.version>1.3.0-rc3</mtf.tools.version>
        <!--
            Default JS engine for MUnit suites (J8/J11/J17 surefire build).
            Overridden by the jdk25 profile when MUnit forks on JDK 25
            (SFCI's -Dmunit.jvm path; Maven itself still runs on the build JDK).
        -->
        <js.engine>Nashorn</js.engine>
    </properties>
    <dependencies>
        <!-- Reactor -->
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-core</artifactId>
            <version>${project.reactor.version}</version>
        </dependency>
        <!-- Test dependencies -->
        <dependency>
            <groupId>org.mule.tests.plugin</groupId>
            <artifactId>mule-tests-component-plugin</artifactId>
            <version>${mule.version}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mule.tests</groupId>
            <artifactId>mule-tests-model</artifactId>
            <version>${mule.version}</version>
            <scope>test</scope>
        </dependency>
        <!--Groovy-->
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>${groovy.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-jsr223</artifactId>
            <version>${groovy.version}</version>
            <scope>test</scope>
        </dependency>
        <!--Jython-->
        <dependency>
            <groupId>org.python</groupId>
            <artifactId>jython-standalone</artifactId>
            <version>${jython.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-file-connector</artifactId>
            <version>${file.connector.version}</version>
            <classifier>mule-plugin</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons.lang.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <profiles>
        <!--
            ============================================================================
            Surefire JVM pin — IMPORTANT
            ============================================================================
            Surefire runs the plain-JUnit tests on JDK 8 by design (the parent
            mule4-connectors-parent pins surefire's <jvm> to JAVA_8_HOME). This
            connector relies on that pin for the unit tests in
            ScriptRunnerTestCase that probe getEngineByName("ECMAScript") /
            "Oracle Nashorn" — those names are only advertised by the JDK 8
            built-in Nashorn engine. Rhino does NOT advertise "ECMAScript",
            and Nashorn was removed in JDK 15 (JEP 372).

            The jdk25 profile only changes which JVM forks the *MUnit* run
            (-Dmunit.jvm), not Surefire. If a future change (e.g. W-22856334)
            ever moves the Surefire JVM off JDK 8, the ECMAScript-named tests
            in ScriptRunnerTestCase must be revisited (extend the ScriptRunner
            fallback to also map "ECMAScript", or add an Assume guard).
            ============================================================================
        -->
        <!--
            legacy-jdk profile: active by default; Maven automatically supersedes it
            with the jdk25 profile whenever that one activates (i.e. MUnit forks on
            JDK 25 — see the jdk25 profile below).
            Provides JRuby 9.4.x and GraalJS 22.x as test deps + MUnit shared libs.
            Both engines work on J8/J11/J17 and are class file v52 / v55, so they're
            safe on the J8 Surefire classpath.
        -->
        <profile>
            <id>legacy-jdk</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.jruby</groupId>
                    <artifactId>jruby-core</artifactId>
                    <version>${jruby.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jruby</groupId>
                    <artifactId>jruby-stdlib</artifactId>
                    <version>${jruby.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.graalvm.js</groupId>
                    <artifactId>js</artifactId>
                    <version>${graal.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.graalvm.js</groupId>
                    <artifactId>js-scriptengine</artifactId>
                    <version>${graal.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.mulesoft.munit</groupId>
                        <artifactId>munit-extensions-maven-plugin</artifactId>
                        <configuration>
                            <sharedLibraries combine.children="append">
                                <sharedLibrary>
                                    <groupId>org.jruby</groupId>
                                    <artifactId>jruby-core</artifactId>
                                </sharedLibrary>
                                <sharedLibrary>
                                    <groupId>org.graalvm.js</groupId>
                                    <artifactId>js</artifactId>
                                </sharedLibrary>
                                <sharedLibrary>
                                    <groupId>org.graalvm.js</groupId>
                                    <artifactId>js-scriptengine</artifactId>
                                </sharedLibrary>
                            </sharedLibraries>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!--
            jdk25 profile: auto-activates when MUnit forks on JDK 25.
            Maven itself runs on the connector's build JDK (JDK 8/17 on SFCI), so
            profile activation cannot key off <jdk>/${java.version} — those see the
            Maven process JVM, never the forked MUnit JVM. The only JDK-25 signal
            Maven can observe is the munit.jvm system property, which SFCI sets to
            the JDK 25 launcher path on the JDK-25 runtime lane.
            On JDK 25, JRuby 9.4.x and GraalJS 22.x both fail at <clinit> due to
            sun.misc.Unsafe, so they are replaced by JRuby 10.x and Rhino.

            NOTE (W-22856334): matching the exact SFCI agent path below is a stopgap.
            It is brittle — it breaks if infra relocates the JDK, and it does NOT
            activate for local run-j25-tests runs (which fork munit.jvm to a different
            path). The robust fix is to have connectors-cicd-sfci-build pass a stable
            semantic flag (e.g. -DmunitJdk25=true) on the JDK-25 lane; when that lands,
            switch the activation below back to that property.
        -->
        <profile>
            <id>jdk25</id>
            <activation>
                <property>
                    <name>munit.jvm</name>
                    <value>/opt/java/jdk25/bin/java</value>
                </property>
            </activation>
            <properties>
                <js.engine>rhino</js.engine>
            </properties>
            <!--
                JRuby 10.x must live in the PROJECT dependency graph so the MUnit
                <sharedLibrary>org.jruby:jruby-base</sharedLibrary> below can resolve
                the jar and map it into the JDK-25 test-app region; when this profile
                activates it supersedes legacy-jdk, which was the only place JRuby was
                declared as a project dependency.

                NOTE: in JRuby 10.x the JSR-223 JRubyEngineFactory (and its
                META-INF/services registration) live in jruby-base — the old
                jruby-core artifact is now just a relocation pointer to jruby-base,
                so the shared library and dependencies must reference jruby-base by
                artifactId, otherwise the JSR-223 provider never maps into the region
                and the 'jruby' engine resolves to SCRIPTING:UNKNOWN_ENGINE.

                jruby-base is kept off the JDK-8 Surefire fork via
                classpathDependencyExcludes (below) because jruby 10.x is class file
                v65 (JDK 21+): on the JDK-25 lane SFCI runs Surefire on JDK 8, and
                constructing a ScriptEngineManager there would instantiate
                JRubyEngineFactory via the JSR-223 ServiceLoader and crash the unit
                tests with UnsupportedClassVersionError — same rationale as rhino-engine.
            -->
            <dependencies>
                <dependency>
                    <groupId>org.jruby</groupId>
                    <artifactId>jruby-base</artifactId>
                    <version>${jruby.jdk25.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jruby</groupId>
                    <artifactId>jruby-stdlib</artifactId>
                    <version>${jruby.jdk25.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <!--
                                Keep JRuby 10.x (class file v65 / JDK 21+) off the JDK-8
                                Surefire classpath so the unit-test ScriptEngineManager
                                does not fail with UnsupportedClassVersionError. JRuby is
                                only needed by the JDK-25 MUnit fork via the shared library.
                            -->
                            <classpathDependencyExcludes>
                                <classpathDependencyExclude>org.jruby:jruby-base</classpathDependencyExclude>
                                <classpathDependencyExclude>org.jruby:jruby-stdlib</classpathDependencyExclude>
                            </classpathDependencyExcludes>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.mulesoft.munit</groupId>
                        <artifactId>munit-extensions-maven-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>org.jruby</groupId>
                                <artifactId>jruby-base</artifactId>
                                <version>${jruby.jdk25.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.jruby</groupId>
                                <artifactId>jruby-stdlib</artifactId>
                                <version>${jruby.jdk25.version}</version>
                            </dependency>
                            <!--
                                rhino-engine replaces GraalJS as the JS engine on the JDK 25
                                MUnit fork (js.engine=rhino). It is plugin-scoped, NOT a plain
                                test dependency, because rhino-engine ${rhino.engine.version} is
                                Java 11 bytecode (class file v55): the parent pins Surefire to
                                JDK 8, and constructing a ScriptEngineManager there instantiates
                                every registered ScriptEngineFactory via the JSR-223 ServiceLoader,
                                so a classpath RhinoScriptEngineFactory crashes the JDK 8 unit
                                tests with UnsupportedClassVersionError. On JDK 8 the unit tests
                                use the built-in Nashorn engine; Rhino is only needed by the MUnit
                                fork — same rationale as JRuby 10.x above.
                            -->
                            <dependency>
                                <groupId>org.mozilla</groupId>
                                <artifactId>rhino-engine</artifactId>
                                <version>${rhino.engine.version}</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <sharedLibraries combine.children="append">
                                <sharedLibrary>
                                    <groupId>org.jruby</groupId>
                                    <artifactId>jruby-base</artifactId>
                                </sharedLibrary>
                                <sharedLibrary>
                                    <groupId>org.mozilla</groupId>
                                    <artifactId>rhino-engine</artifactId>
                                </sharedLibrary>
                            </sharedLibraries>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <jruby.version>${jruby.version}</jruby.version>
                        <jython.version>${jython.version}</jython.version>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.mulesoft.munit</groupId>
                <artifactId>munit-extensions-maven-plugin</artifactId>
                <configuration>
                    <runtimeConfiguration>
                        <discoverRuntimes>
                            <minMuleVersion>${minVersion}</minMuleVersion>
                            <includeSnapshots>false</includeSnapshots>
                            <product>EE</product>
                        </discoverRuntimes>
                    </runtimeConfiguration>
                    <systemPropertyVariables>
                        <js.engine>${js.engine}</js.engine>
                    </systemPropertyVariables>
                    <sharedLibraries>
                        <sharedLibrary>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-jsr223</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>org.python</groupId>
                            <artifactId>jython-standalone</artifactId>
                        </sharedLibrary>
                        <sharedLibrary>
                            <groupId>org.mule.tests</groupId>
                            <artifactId>mule-tests-model</artifactId>
                        </sharedLibrary>
                        <!--
                            JS engine + JRuby shared libraries are appended by the legacy-jdk
                            and jdk25 profiles (JRuby 9 + GraalJS for legacy, JRuby 10 + Rhino
                            for J25).
                        -->
                    </sharedLibraries>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <ignoredUnusedDeclaredDependencies>
                        <ignoredUnusedDeclaredDependency>org.codehaus.groovy:groovy</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.codehaus.groovy:groovy-jsr223</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.python:jython-standalone</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.jruby:jruby-core</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.jruby:jruby-base</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.jruby:jruby-stdlib</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.apache.commons:commons-lang3</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.graalvm.js:js</ignoredUnusedDeclaredDependency>
                        <ignoredUnusedDeclaredDependency>org.graalvm.js:js-scriptengine</ignoredUnusedDeclaredDependency>
                    </ignoredUnusedDeclaredDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
