<?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
                             https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>io.unmeshed</groupId>
    <artifactId>unmeshed-sdk</artifactId>
    <version>${revision}</version>
    <packaging>jar</packaging>

    <name>unmeshed-sdk</name>
    <description>Java SDK for Unmeshed Workflow Engine.</description>
    <url>https://github.com/unmeshed/unmeshed-java-sdk</url>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>http://www.opensource.org/licenses/mit-license.php</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>unmeshed-devs</id>
            <name>Unmeshed Devs</name>
            <email>unmeshed-devs@unmeshed.com</email>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:https://github.com/unmeshed/unmeshed-java-sdk.git</connection>
        <developerConnection>scm:git:ssh://github.com/unmeshed/unmeshed-java-sdk.git</developerConnection>
        <url>https://github.com/unmeshed/unmeshed-java-sdk</url>
    </scm>

    <properties>
        <revision>2.0.9</revision> <!-- Maven release version -->
        <java.version>22.0.1</java.version>
        <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <unmeshed.version>${env.UNMESHED_VERSION}</unmeshed.version>
        <spring-boot-bom.version>4.0.2</spring-boot-bom.version>
        <junit-bom.version>5.10.0</junit-bom.version>

        <!-- Dynamic versions -->
        <unmeshed-sdk.version>1.10.3</unmeshed-sdk.version> <!-- S3 precompiled JAR version -->
        <unmeshed-api-common.version>2.0.9</unmeshed-api-common.version> <!-- Dependency version -->
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Mirrors Gradle dependencyManagement import. -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot-bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>${junit-bom.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.38</version> <!-- use latest stable -->
            <scope>provided</scope>
        </dependency>

        <!-- Dependency on unmeshed-api-common -->
        <dependency>
            <groupId>io.unmeshed</groupId>
            <artifactId>unmeshed-api-common</artifactId>
            <version>${unmeshed-api-common.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.16</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.18.1</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.18.1</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-common</artifactId>
            <version>3.1.8</version>
        </dependency>

        <dependency>
            <groupId>io.github.classgraph</groupId>
            <artifactId>classgraph</artifactId>
            <version>4.8.177</version>
        </dependency>

        <!-- Optional Spring integration (compile-time only; provided by consumers at runtime). -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.16</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>5.20.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>5.20.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.27.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <!-- Maven Compiler Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <release>21</release>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.38</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

            <!-- Download and unpack S3 sources -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <!-- Download compiled JAR -->
                    <execution>
                        <id>download-main-jar</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}"/>
                                <exec executable="aws">
                                    <arg value="s3"/>
                                    <arg value="cp"/>
                                    <arg value="s3://unmeshed-sdk/maven-repo/io/unmeshed/unmeshed-sdk/${unmeshed-sdk.version}/unmeshed-sdk-${unmeshed-sdk.version}.jar"/>
                                    <arg value="${project.build.directory}/${project.build.finalName}.jar"/>
                                    <env key="AWS_ACCESS_KEY_ID" value="${env.AWS_ACCESS_KEY_ID}"/>
                                    <env key="AWS_SECRET_ACCESS_KEY" value="${env.AWS_SECRET_ACCESS_KEY}"/>
                                    <env key="AWS_REGION" value="${env.AWS_REGION}"/>
                                </exec>
                            </target>
                        </configuration>
                    </execution>

                    <!-- Download and unpack sources JAR -->
                    <execution>
                        <id>download-and-unpack-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}/generated-sources/unmeshed"/>
                                <exec executable="aws">
                                    <arg value="s3"/>
                                    <arg value="cp"/>
                                    <arg value="s3://unmeshed-sdk/maven-repo/io/unmeshed/unmeshed-sdk/${unmeshed-sdk.version}/unmeshed-sdk-${unmeshed-sdk.version}-sources.jar"/>
                                    <arg value="${project.build.directory}/unmeshed-sdk-sources.jar"/>
                                    <env key="AWS_ACCESS_KEY_ID" value="${env.AWS_ACCESS_KEY_ID}"/>
                                    <env key="AWS_SECRET_ACCESS_KEY" value="${env.AWS_SECRET_ACCESS_KEY}"/>
                                    <env key="AWS_REGION" value="${env.AWS_REGION}"/>
                                </exec>
                                <unzip src="${project.build.directory}/unmeshed-sdk-sources.jar"
                                       dest="${project.build.directory}/generated-sources/unmeshed"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Add real sources to Maven build -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>add-real-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/unmeshed</source>
                                <source>${project.build.directory}/generated-sources/annotations</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- JAR Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <forceCreation>true</forceCreation>
                </configuration>
            </plugin>

            <!-- Sources JAR (from unpacked S3 sources) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>attach-real-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                        <configuration>
                            <includePom>true</includePom>
                            <forceCreation>true</forceCreation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Javadoc JAR - Using Delombok sources -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.4.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <doclint>none</doclint>
                            <failOnError>false</failOnError>
                            <failOnWarnings>false</failOnWarnings>
                            <quiet>true</quiet>
                            <source>21</source>
                            <!-- Exclude the problematic classes -->
                            <excludePackageNames>io.unmeshed.client:io.unmeshed.client.schedulers</excludePackageNames>
                            <!-- Force creation of JAR even if empty -->
                            <forceCreation>true</forceCreation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- GPG Signing -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>${maven-gpg-plugin.version}</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <configuration>
                            <useAgent>true</useAgent>
                            <gpgArguments>
                                <arg>--batch</arg>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Nexus Central Publishing -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.8.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>ossrh</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

</project>
