<?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>srl.forge</groupId>
    <artifactId>jjbridge-engine-v8</artifactId>
    <version>0.2.0</version>
    <packaging>${packaging.type}</packaging>

    <name>JJBridge V8 Engine</name>
    <description>A JJBridge library bundled with the V8 JavaScript Engine</description>
    <url>https://github.com/Forge-Srl/jjbridge-engine-v8</url>

    <licenses>
        <license>
            <name>MIT</name>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Tommaso Bossi</name>
            <email>tommaso.bossi@forge.srl</email>
            <organization>Forge S.r.l.</organization>
            <organizationUrl>https://forge.srl</organizationUrl>
            <timezone>Europe/Rome</timezone>
            <roles>
                <role>Developer</role>
            </roles>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git@github.com:forge-srl/jjbridge-engine-v8.git</connection>
        <developerConnection>scm:git:git@github.com:forge-srl/jjbridge-engine-v8.git</developerConnection>
        <url>https://github.com/Forge-Srl/jjbridge-engine-v8/tree/main</url>
        <tag>release/0.2.0</tag>
    </scm>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <profiles>
        <profile>
            <id>Windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <script.toExecute>${project.basedir}${file.separator}build_Windows.ps1</script.toExecute>
                <script.toExecuteAndroid>${project.basedir}${file.separator}build_Android.ps1</script.toExecuteAndroid>
                <script.executor>powershell.exe</script.executor>
                <jar.classifier>windows</jar.classifier>
                <reuseForksInSurefire>false</reuseForksInSurefire>
                <skipSigning>true</skipSigning>
            </properties>
        </profile>
        <profile>
            <id>Linux</id>
            <activation>
                <os>
                    <family>unix</family>
                    <name>Linux</name>
                </os>
            </activation>
            <properties>
                <script.toExecute>${project.basedir}${file.separator}build_Linux.sh</script.toExecute>
                <script.toExecuteAndroid>${project.basedir}${file.separator}build_Android.sh</script.toExecuteAndroid>
                <script.executor>bash</script.executor>
                <jar.classifier>linux</jar.classifier>
                <reuseForksInSurefire>false</reuseForksInSurefire>
                <skipSigning>true</skipSigning>
            </properties>
        </profile>
        <profile>
            <id>macOS</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <script.toExecute>${project.basedir}${file.separator}build_macOS.sh</script.toExecute>
                <script.toExecuteAndroid>${project.basedir}${file.separator}build_Android.sh</script.toExecuteAndroid>
                <script.executor>zsh</script.executor>
                <jar.classifier>macos</jar.classifier>
                <reuseForksInSurefire>false</reuseForksInSurefire>
                <skipSigning>true</skipSigning>
            </properties>
        </profile>
        <profile>
            <id>Android</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <packaging.type>aar</packaging.type>
                <skipSigning>true</skipSigning>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>android-cli</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <phase>compile</phase>
                                <configuration>
                                    <executable>${script.executor}</executable>
                                    <commandlineArgs>${script.toExecuteAndroid}</commandlineArgs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.simpligility.maven.plugins</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <version>4.6.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <classifier>android</classifier>
                            <nativeLibrariesDirectory>${project.basedir}${file.separator}target${file.separator}jni${file.separator}android${file.separator}</nativeLibrariesDirectory>
                            <androidManifestFile>${project.basedir}${file.separator}src${file.separator}android${file.separator}AndroidManifest.xml</androidManifestFile>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>Common</id>
            <activation>
                <property>
                    <name>!unsetDefaultProfile</name>
                </property>
            </activation>
            <properties>
                <jniRelativePath>target${file.separator}jni${file.separator}${jar.classifier}${file.separator}x86_64</jniRelativePath>
                <packaging.type>jar</packaging.type>
            </properties>
            <build>
                <defaultGoal>compile:nativeDeps</defaultGoal>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>default-cli</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <phase>compile</phase>
                                <configuration>
                                    <executable>${script.executor}</executable>
                                    <commandlineArgs>${script.toExecute}</commandlineArgs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <rerunFailingTestsCount>3</rerunFailingTestsCount>
                            <runOrder>random</runOrder>
                            <forkCount>1</forkCount>
                            <reuseForks>${reuseForksInSurefire}</reuseForks>
                            <testFailureIgnore>false</testFailureIgnore>
                            <argLine>-ea -Xcheck:jni -Djava.library.path=${project.basedir}${file.separator}${jniRelativePath}</argLine>
                            <environmentVariables>
                                <PATH>${env.PATH}${path.separator}${project.basedir}${file.separator}${jniRelativePath}</PATH>
                            </environmentVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <includes>
                                <include>**/RuntimeTest.java</include>
                            </includes>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <classesDirectory>target${file.separator}${project.artifactId}-${project.version}-${jar.classifier}.${packaging.type}</classesDirectory>
                                    <runOrder>random</runOrder>
                                    <forkCount>1</forkCount>
                                    <reuseForks>${reuseForksInSurefire}</reuseForks>
                                    <testFailureIgnore>false</testFailureIgnore>
                                    <environmentVariables>
                                        <PATH />
                                    </environmentVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>3.2.0</version>
                        <configuration>
                            <descriptors>
                                <descriptor>assembly-descriptors${file.separator}${jar.classifier}-assembly-descriptor.xml</descriptor>
                            </descriptors>
                        </configuration>
                        <executions>
                            <execution>
                                <id>make-assembly</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release-github</id>
            <activation>
                <property>
                    <name>release-repo</name>
                    <value>github</value>
                </property>
            </activation>
            <properties>
                <skipSigning>false</skipSigning>
            </properties>
            <distributionManagement>
                <repository>
                    <id>github</id>
                    <name>GitHub Forge S.r.l. Apache Maven Packages</name>
                    <url>https://maven.pkg.github.com/forge-srl/jjbridge-engine-v8</url>
                </repository>
            </distributionManagement>
        </profile>
        <profile>
            <id>release-maven-central</id>
            <activation>
                <property>
                    <name>release-repo</name>
                    <value>maven-central</value>
                </property>
            </activation>
            <properties>
                <skipSigning>false</skipSigning>
            </properties>
            <distributionManagement>
                <repository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
            </distributionManagement>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.8</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            <keepStagingRepositoryOnCloseRuleFailure>true</keepStagingRepositoryOnCloseRuleFailure>
                            <stagingProgressTimeoutMinutes>10</stagingProgressTimeoutMinutes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.1</version>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>8.36</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <linkXRef>false</linkXRef>
                </configuration>
                <executions>
                    <execution>
                        <id>validate</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.0.4</version>
                <configuration>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <xmlOutput>true</xmlOutput>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <configuration>
                            <skip>${skipSigning}</skip>
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>3.0.0-M1</version>
                <configuration>
                    <scmCommentPrefix>build: </scmCommentPrefix>
                    <tagNameFormat>release/@{project.version}</tagNameFormat>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>add-platform-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>target${file.separator}${project.artifactId}-${project.version}.aar</file>
                                    <type>aar</type>
                                    <classifier>android</classifier>
                                </artifact>
                                <artifact>
                                    <file>target${file.separator}${project.artifactId}-${project.version}-linux.jar</file>
                                    <type>jar</type>
                                    <classifier>linux</classifier>
                                </artifact>
                                <artifact>
                                    <file>target${file.separator}${project.artifactId}-${project.version}-macos.jar</file>
                                    <type>jar</type>
                                    <classifier>macos</classifier>
                                </artifact>
                                <artifact>
                                    <file>target${file.separator}${project.artifactId}-${project.version}-windows.jar</file>
                                    <type>jar</type>
                                    <classifier>windows</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>github-jjbridge-api</id>
            <url>https://maven.pkg.github.com/forge-srl/jjbridge-api</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>srl.forge</groupId>
            <artifactId>jjbridge-api</artifactId>
            <version>0.2.0</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-annotations</artifactId>
            <version>4.1.2</version>
            <scope>provided</scope>
            <!--
            Setting as optional to bypass LGPL limitations.
            See: https://github.com/spotbugs/discuss/issues/64#issuecomment-454634426
            -->
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.5.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.0.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>