<?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 Guava JPMS Module</name>
    <description>A customized, modularized version of Google’s Guava library, repackaged for the JPro platform with
        additional support for JPMS and enhanced artifact management.</description>

    <properties>
        <!-- Change release here-->
        <core.artifact.groupId>com.google.guava</core.artifact.groupId>
        <core.artifact.artifactId>guava</core.artifact.artifactId>
        <core.artifact.version>33.3.0-jre</core.artifact.version>

        <!-- Transitive dependency versions -->
        <guava-failureaccess.version>1.0.2</guava-failureaccess.version>
        <guava-lisstenablefuture.version>9999.0-empty-to-avoid-conflict-with-guava</guava-lisstenablefuture.version>
        <jsr305.version>3.0.2-jpms</jsr305.version>
        <checkerqual.version>3.46.0</checkerqual.version>
        <google.errorprone.version>2.30.0</google.errorprone.version>
        <j2objc-annotations.version>3.0.0</j2objc-annotations.version>
    </properties>

    <!-- transitive dependencies of the repackaged artifact -->
    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>failureaccess</artifactId>
            <version>${guava-failureaccess.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>listenablefuture</artifactId>
            <version>${guava-lisstenablefuture.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jsr305</artifactId>
            <version>${jsr305.version}</version>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <version>${checkerqual.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.errorprone</groupId>
            <artifactId>error_prone_annotations</artifactId>
            <version>${google.errorprone.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.j2objc</groupId>
            <artifactId>j2objc-annotations</artifactId>
            <version>${j2objc-annotations.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/${project.artifactId}-${core.artifact.version}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                                <artifact>
                                    <file>${project.build.directory}/dependency/${project.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 com.google.common {
                                        requires jdk.unsupported;
                                        requires java.logging;
                                        requires static com.google.common.util.concurrent.internal;
                                        requires static org.checkerframework.checker.qual;
                                        requires static com.google.errorprone.annotations;

                                        exports com.google.common.annotations;
                                        exports com.google.common.base;
                                        exports com.google.common.base.internal;
                                        exports com.google.common.cache;
                                        exports com.google.common.collect;
                                        exports com.google.common.escape;
                                        exports com.google.common.eventbus;
                                        exports com.google.common.graph;
                                        exports com.google.common.hash;
                                        exports com.google.common.html;
                                        exports com.google.common.io;
                                        exports com.google.common.math;
                                        exports com.google.common.net;
                                        exports com.google.common.primitives;
                                        exports com.google.common.reflect;
                                        exports com.google.common.util.concurrent;
                                        exports com.google.common.xml;
                                        }
                                    </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/${project.artifactId}-${core.artifact.version}-sources.jar"
                                      tofile="${project.build.directory}/${project.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/${project.artifactId}-${core.artifact.version}-javadoc.jar"
                                      tofile="${project.build.directory}/${project.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>
