<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>io.metersphere</groupId>
        <artifactId>metersphere-scriptengine</artifactId>
        <version>1.1.0</version>
    </parent>
    <groupId>io.metersphere</groupId>
    <artifactId>python-scriptengine</artifactId>
    <repositories>
        <!--
        Uncomment to use builds from snapshot repository. This is typically not necessary as all require artefacts are used on Maven
        central.
        -->
        <!--
        <repository>
            <id>graalvm-snapshot-repo</id>
            <name>graalvm-snapshot-repo</name>
            <url>file:///path/to/snapshot/repo</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        -->
    </repositories>


    <dependencies>
        <!--
        The polyglot dependency is always required for Java embeddings.
        It contains the polyglot embedding APIs to include any polyglot language. -->
        <dependency>
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>polyglot</artifactId>
            <version>${graalvm.version}</version>
            <type>jar</type>
        </dependency>
        <!--
        Choose here which languages should be used.
        Available languages in the polyglot group are:
            js, ruby, python, wasm, llvm, llvm-native, java

        Switch to community licenses by adding a `-community` suffix to the artefact id (e.g. `js-communtiy`).
        Switch to native isolate versions of languages by adding a `-isolate` suffix. (`js-isolate`).

        Any dependency in the org.graalvm.polyglot group is intended for use by polyglot embeddings.
        -->
        <dependency>
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>python-community</artifactId>
            <version>${graalvm.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>llvm-community</artifactId>
            <version>${graalvm.version}</version>
            <type>pom</type>
        </dependency>

        <!-- Uncomment to include language tooling like a sampling profiler and the chrome inspector support. -->
        <!--
         <dependency>
             <groupId>org.graalvm.polyglot</groupId>
             <artifactId>tools</artifactId>
             <version>${graalvm.version}</version>
             <type>pom</type>
         </dependency>
         -->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>no-runtime-compilation</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <arguments>
                                <!-- We recommend running from the module-path by default.
                                     But you can also switch to the class-path here.-->
                                <argument>--module-path</argument>
                                <modulepath/>
                                <argument>-m</argument>
                                <argument>embedding/io.metersphere.js.scriptengine.Main</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <executable>${java.home}/bin/java</executable>
                    <arguments>
                        <!-- We recommend running from the module-path by default.
                        But you can also switch to the class-path here.-->
                        <argument>--module-path</argument>
                        <modulepath/>
                        <argument>-m</argument>
                        <argument>embedding/io.metersphere.js.scriptengine.Main</argument>
                    </arguments>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-jlink-plugin</artifactId>
                <version>3.1.0</version>
                <extensions>true</extensions>
                <configuration>
                    <ignoreSigningInformation>true</ignoreSigningInformation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!--
            Run native image build with: mvn -Pnative package.
            This profile may be removed if no native-image builds are needed.
            -->
            <id>native</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>0.9.25</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>${project.artifactId}</imageName>
                            <mainClass>io.metersphere.js.scriptengine.Main</mainClass>
                            <buildArgs>
                                <buildArg>--no-fallback</buildArg>
                                <buildArg>-J-Xmx20g</buildArg>
                            </buildArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <!--
             Profile used when running on a different JDK than GraalVM.
             This profile may be removed if you are always running with a
             GraalVM JDK or if you don't want to use the optimizing runtime.

             Note: Using this configuration unlocks experimental options and is therefore
             not recommended for production use.
             -->
            <id>not-graalvm-jdk</id>
            <activation>
                <file>
                    <!-- Detect if we are not running with a GraalVM JDK. -->
                    <missing>${java.home}/lib/graalvm</missing>
                </file>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.6.0</version>
                        <executions>
                            <!--
                            Copies compiler dependencies to the target/compiler folder. In order to run with an
                            optimizing runtime on other JDKs than GraalVM we need to put the compiler on the upgrade-module-path.
                            -->
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>
                                        ${project.build.directory}/compiler
                                    </outputDirectory>
                                    <artifactItems>
                                        <!--
                                        Unfortunately Maven does not support resolving transitive dependencies
                                        here automatically. So the list of dependencies might need to be updated when upgrading
                                        to new versions of GraalVM.
                                        -->
                                        <artifactItem>
                                            <groupId>org.graalvm.sdk</groupId>
                                            <artifactId>collections</artifactId>
                                            <version>${graalvm.version}</version>
                                            <type>jar</type>
                                            <destFileName>collections.jar</destFileName>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.graalvm.sdk</groupId>
                                            <artifactId>word</artifactId>
                                            <version>${graalvm.version}</version>
                                            <type>jar</type>
                                            <destFileName>word.jar</destFileName>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.graalvm.truffle</groupId>
                                            <artifactId>truffle-compiler</artifactId>
                                            <version>${graalvm.version}</version>
                                            <type>jar</type>
                                            <destFileName>truffle-compiler.jar</destFileName>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.graalvm.compiler</groupId>
                                            <artifactId>compiler</artifactId>
                                            <version>${graalvm.version}</version>
                                            <type>jar</type>
                                            <destFileName>compiler.jar</destFileName>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.1.2</version>
                        <configuration>
                            <argLine>
                                -XX:+UnlockExperimentalVMOptions
                                -XX:+EnableJVMCI
                                --upgrade-module-path=${project.build.directory}/compiler
                            </argLine>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <id>default-cli</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${java.home}/bin/java</executable>
                                    <arguments>
                                        <argument>--module-path</argument>
                                        <modulepath/>
                                        <argument>-XX:+UnlockExperimentalVMOptions</argument>
                                        <argument>-XX:+EnableJVMCI</argument>
                                        <argument>--upgrade-module-path=${project.build.directory}/compiler/</argument>
                                        <argument>-m</argument>
                                        <argument>embedding/io.metersphere.js.scriptengine.Main</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>no-runtime-compilation</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${java.home}/bin/java</executable>
                                    <arguments>
                                        <argument>--module-path</argument>
                                        <modulepath/>
                                        <argument>-m</argument>
                                        <argument>embedding/io.metersphere.js.scriptengine.Main</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>

    </profiles>

</project>
