<?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>one.jpro.platform.jpms</groupId>
        <artifactId>jpms-parent</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>${core.artifact.artifactId}</artifactId>
    <packaging>jar</packaging>
    <version>${core.artifact.version}-${core.artifact.release}</version>

    <name>JPro Platform JWKS RSA JPMS Module</name>
    <description>A modularized version of JWKS RSA, repackaged for use with the JPro platform, providing support for
        JSON Web Key Set (JWKS) RSA keys.</description>

    <properties>
        <!-- Change release here-->
        <core.artifact.groupId>com.auth0</core.artifact.groupId>
        <core.artifact.artifactId>jwks-rsa</core.artifact.artifactId>
        <core.artifact.version>0.22.1</core.artifact.version>

        <!-- Transitive dependency versions -->
        <jackson.version>2.17.2</jackson.version>
        <jpro.guava.version>33.3.0-jre-jpms</jpro.guava.version>
    </properties>

    <!-- transitive dependencies of the repackaged artifact -->
    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>guava</artifactId>
            <version>${jpro.guava.version}</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${basedir}/</directory>
                <includes>
                    <include>LICENSE.txt</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>sources</id>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>${core.artifact.groupId}</groupId>
                                    <artifactId>${core.artifact.artifactId}</artifactId>
                                    <version>${core.artifact.version}</version>
                                    <classifier>sources</classifier>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>${core.artifact.groupId}</groupId>
                                    <artifactId>${core.artifact.artifactId}</artifactId>
                                    <version>${core.artifact.version}</version>
                                    <classifier>javadoc</classifier>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/dependency/${artifactId}-${core.artifact.version}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                                <artifact>
                                    <file>${project.build.directory}/dependency/${artifactId}-${core.artifact.version}-javadoc.jar</file>
                                    <type>jar</type>
                                    <classifier>javadoc</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-module-infos</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-module-info</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/moditect</outputDirectory>
                            <overwriteExistingFiles>true</overwriteExistingFiles>
                            <modules>
                                <module>
                                    <artifact>
                                        <groupId>${core.artifact.groupId}</groupId>
                                        <artifactId>${core.artifact.artifactId}</artifactId>
                                        <version>${core.artifact.version}</version>
                                    </artifact>
                                    <moduleInfoSource>
                                        open module jwks.rsa {
                                            requires com.fasterxml.jackson.databind;
                                            requires com.fasterxml.jackson.core;
                                            requires com.fasterxml.jackson.annotation;
                                            requires com.google.common;
                                            exports com.auth0.jwk;
                                        }
                                    </moduleInfoSource>
                                </module>
                            </modules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>rename-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo message="renaming sources file" />
                                <copy file="${project.build.directory}/dependency/${artifactId}-${core.artifact.version}-sources.jar"
                                      tofile="${project.build.directory}/${artifactId}-${core.artifact.version}-${core.artifact.release}-sources.jar" />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>rename-javadoc</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo message="renaming javadoc file" />
                                <copy file="${project.build.directory}/dependency/${artifactId}-${core.artifact.version}-javadoc.jar"
                                      tofile="${project.build.directory}/${artifactId}-${core.artifact.version}-${core.artifact.release}-javadoc.jar" />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>prepare-package</phase>
                        <configuration>
                            <target>
                                <echo message="unzipping files" />
                                <unzip
                                        src="${project.build.directory}/moditect/${project.artifactId}-${core.artifact.version}.jar"
                                        dest="${project.build.directory}/classes/">
                                    <patternset>
                                        <exclude name="**/MANIFEST.MF" />
                                    </patternset>
                                </unzip>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
