<?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.29</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>

        <!-- 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>
    </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>
                <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>
        </plugins>
    </build>

    <profiles>
        <!-- Profile for building standalone distribution -->
        <profile>
            <id>dist</id>
            <build>
                <plugins>
                    <!-- Copy XAR and Rumi distribution -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.6.1</version>
                        <executions>
                            <!-- Copy XAR artifact -->
                            <execution>
                                <id>copy-xar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.neeve</groupId>
                                            <artifactId>nvx-rumi-docchat-system</artifactId>
                                            <version>${project.version}</version>
                                            <type>xar</type>
                                            <destFileName>${project.artifactId}-${project.version}.xar</destFileName>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                </configuration>
                            </execution>
                            <!-- Copy Rumi distribution -->
                            <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>
        </profile>
    </profiles>
</project>
