<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2022 N5 Technologies, Inc.

    This product includes software developed at N5 Technologies, Inc
    (http://www.n5corp.com/) and software licenced to N5 Technologies,
    Inc under one or more contributor license agreements.

    N5 Technologies, Inc licenses this file to you under the Polyform
    Internal Use License Version 1.1.0 (the "License"); you may not use
    this file except in compliance with the License.  You may obtain a
    copy of the License at:

        https://polyformproject.org/licenses/internal-use/1.0.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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">
    <name>Rumi DocChat System</name>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>nvx-rumi-docchat-system</artifactId>
    <packaging>jar</packaging>

    <parent>
        <groupId>com.neeve</groupId>
        <artifactId>nvx-rumi-docchat-parent</artifactId>
        <version>1.0.7</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>com.neeve</groupId>
            <artifactId>nvx-rumi-docchat-roe</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.neeve</groupId>
            <artifactId>nvx-rumi-docchat-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- Rumi distribution (Linux x86-64) for standalone packaging -->
        <dependency>
            <groupId>com.neeve</groupId>
            <artifactId>nvx-rumi</artifactId>
            <version>${nvx.rumi.version}</version>
            <classifier>nojre-0</classifier>
            <type>0.0-linux-x86-64-release.tar.gz</type>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- JAXB for Rumi (old javax namespace) -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.3</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Configure surefire for Java 17+ -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.5</version>
                <configuration>
                    <argLine>
                        --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED
                        --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
                        --add-opens=java.base/java.lang=ALL-UNNAMED
                        --add-opens=java.base/java.nio=ALL-UNNAMED
                        --add-opens=java.base/java.io=ALL-UNNAMED
                        --add-opens=java.management/sun.management=ALL-UNNAMED
                    </argLine>
                </configuration>
            </plugin>

            <!-- Build XAR -->
            <plugin>
                <groupId>com.neeve</groupId>
                <artifactId>nvx-rumi-xar-maven-plugin</artifactId>
                <version>${nvx.rumi.management.version}</version>
                <configuration>
                    <jarDirectory>${project.build.directory}/xar-jars</jarDirectory>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.neeve</groupId>
                        <artifactId>nvx-rumi-controller</artifactId>
                        <version>${nvx.rumi.management.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>com.neeve</groupId>
                        <artifactId>nvx-rumi</artifactId>
                        <version>${nvx.rumi.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>jakarta.xml.bind</groupId>
                        <artifactId>jakarta.xml.bind-api</artifactId>
                        <version>2.3.2</version>
                    </dependency>
                    <dependency>
                        <groupId>org.glassfish.jaxb</groupId>
                        <artifactId>jaxb-runtime</artifactId>
                        <version>2.3.2</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>Xar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>xar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Copy dependencies for XAR and standalone packaging -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.6.1</version>
                <executions>
                    <!-- Copy all runtime dependencies for XAR -->
                    <execution>
                        <id>copy-dependencies-for-xar</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/xar-jars</outputDirectory>
                            <includeScope>runtime</includeScope>
                            <excludeTypes>tar.gz,0.0-linux-x86-64-release.tar.gz</excludeTypes>
                        </configuration>
                    </execution>
                    <!-- Copy Rumi distribution for standalone packaging -->
                    <execution>
                        <id>copy-rumi-dist</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.neeve</groupId>
                                    <artifactId>nvx-rumi</artifactId>
                                    <version>${nvx.rumi.version}</version>
                                    <classifier>nojre-0</classifier>
                                    <type>0.0-linux-x86-64-release.tar.gz</type>
                                    <destFileName>nvx-rumi-dist.tar.gz</destFileName>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Run repackage script to create standalone distribution -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <id>repackage-standalone</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${project.basedir}/../install/repackage.sh</executable>
                            <workingDirectory>${project.build.directory}</workingDirectory>
                            <arguments>
                                <argument>${project.build.directory}/nvx-rumi-dist.tar.gz</argument>
                                <argument>${project.build.directory}/${project.artifactId}-${project.version}.xar</argument>
                                <argument>${project.artifactId}-${project.version}-standalone</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Attach standalone distribution as artifact -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>attach-standalone</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-${project.version}-standalone.tar.gz</file>
                                    <type>tar.gz</type>
                                    <classifier>standalone</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
