<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source
~ Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors
~ as indicated by the @authors tag. All rights reserved.
~ See the copyright.txt in the distribution for a
~ full listing of individual contributors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~ http://www.apache.org/licenses/LICENSE-2.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 https://maven.apache.org/maven-v4_0_0.xsd">

    <parent>
        <groupId>org.aesh</groupId>
        <artifactId>readline-all</artifactId>
        <version>3.18.4</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>terminal-detect</artifactId>
    <packaging>jar</packaging>
    <name>Æsh Terminal Detection</name>
    <description>Lightweight terminal capability detection with zero dependencies</description>
    <scm>
        <connection>scm:git:git://github.com/aeshell/aesh-readline.git</connection>
        <developerConnection>scm:git:ssh://git@github.com/aeshell/aesh-readline.git</developerConnection>
        <url>https://github.com/aeshell/aesh-readline/tree/master</url>
    </scm>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0</url>
        </license>
    </licenses>

    <properties>
        <javaModuleName>org.aesh.terminal.detect</javaModuleName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                            <Multi-Release>true</Multi-Release>
                            <Enable-Native-Access>ALL-UNNAMED</Enable-Native-Access>
                        </manifestEntries>
                        <index>true</index>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- Multi-release JAR: compile FFM variant when building with Java 22+ -->
        <profile>
            <id>java22-ffm</id>
            <activation>
                <jdk>[22,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>compile-java-22</id>
                                <phase>compile</phase>
                                <goals><goal>compile</goal></goals>
                                <configuration>
                                    <release>22</release>
                                    <compileSourceRoots>
                                        <compileSourceRoot>${project.basedir}/src/main/java22</compileSourceRoot>
                                    </compileSourceRoots>
                                    <multiReleaseOutput>true</multiReleaseOutput>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <argLine>--enable-native-access=ALL-UNNAMED</argLine>
                        </configuration>
                    </plugin>
                    <!-- Copy MRJAR Java 22+ classes to test-classes so surefire can
                         find them. MUST NOT copy to target/classes — that would put
                         Java 22 bytecode in the base path of the released JAR,
                         breaking older-JDK users. -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-mrjar-for-test</id>
                                <phase>process-test-classes</phase>
                                <goals><goal>run</goal></goals>
                                <configuration>
                                    <target>
                                        <copy todir="${project.build.testOutputDirectory}" overwrite="true"
                                              failonerror="false">
                                            <fileset dir="${project.build.outputDirectory}/META-INF/versions/22"
                                                     erroronmissingdir="false"/>
                                        </copy>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- Native-image test run: executes the JUnit tests as a native
             binary, proving FFM downcall registration end to end (#301).
             Unlike terminal-tty, nothing is deleted here: the FFM classes
             under test must be present for registration to be exercised. -->
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>env.GRAALVM_HOME</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <!-- JUnit 5.x ONLY — 6.x is incompatible with native-maven-plugin 1.1.3 -->
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                    <version>5.14.4</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <!-- JUnit 5.x ONLY — 6.x is incompatible with native-maven-plugin 1.1.3 -->
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-launcher</artifactId>
                    <version>1.14.4</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <!-- 1.1.6 is broken: missing org.apache.maven.shared.utils.logging.MessageUtils -->
                        <artifactId>native-maven-plugin</artifactId>
                        <version>1.1.13</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>test-native</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <phase>test</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <quickBuild>true</quickBuild>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
