<!--

    Copyright ©2023-2025 LogonBox Ltd
    All changes post March 2025 Copyright © 2023 JADAPTIVE Limited (support@jadaptive.com)

    Permission is hereby granted, free of charge, to any person obtaining a copy of this
    software and associated documentation files (the “Software”), to deal in the Software
    without restriction, including without limitation the rights to use, copy, modify,
    merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to the following
    conditions:

    The above copyright notice and this permission notice shall be included in all copies
    or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
    PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-->
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.jadaptive</groupId>
        <artifactId>nodal-core</artifactId>
    	<version>1.0.0</version>
    	<relativePath>../</relativePath>
    </parent>
    <artifactId>nodal-core-tools</artifactId>
    <name>Nodal Core - Example Utility</name>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>com.sshtools</groupId>
            <artifactId>porter</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
            <version>4.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>nodal-core-lib</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>nodal-core-remote-node</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sshtools</groupId>
            <artifactId>jadaptive-oauth-client</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <description>
        An example of how to use nodal-core, ndl-quick sets up a simple
        wireguard tunnel.
    </description>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>uk.co.bithatch</groupId>
                            <artifactId>native-image-annotations</artifactId>
                            <version>${native.image.annotations.version}</version>
                        </path>
                        <path>
                            <groupId>info.picocli</groupId>
                            <artifactId>picocli-codegen</artifactId>
                            <version>4.7.5</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>oss-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <snapshots/>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

    <profiles>
        <!-- Native Driver Activation -->
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
				<graalvm.firstArgs>-H:+UnlockExperimentalVMOptions -H:+AddAllCharsets</graalvm.firstArgs>
			</properties>
            <dependencies>
                <dependency>
                    <groupId>com.jadaptive</groupId>
                    <artifactId>nodal-core-windows</artifactId>
                    <version>${project.version}</version>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>linux</id>
            <activation>
                <os>
                    <family>linux</family>
                </os>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.jadaptive</groupId>
                    <artifactId>nodal-core-linux</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.github.hypfvieh</groupId>
                    <artifactId>dbus-java-transport-native-unixsocket</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>macos</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.jadaptive</groupId>
                    <artifactId>nodal-core-macos</artifactId>
                    <version>${project.version}</version>
                </dependency>
            </dependencies>
        </profile>
        <!-- Graal Native Image -->
        <profile>
            <id>native-image</id>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>${graalvm.version}</version>
                        <executions>
                            <execution>
                                <id>ndl-exe</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                                <configuration>
                                    <mainClass>com.jadaptive.nodal.core.quick.Ndl</mainClass>
                                    <imageName>ndl</imageName>
                                    <buildArgs>
										<buildArg>-H:Log=registerResource:verbose</buildArg>
                                        <buildArg>--report-unsupported-elements-at-runtime</buildArg>
                                        <buildArg>-R:MaxHeapSize=64m</buildArg>
										<buildArg>--install-exit-handlers</buildArg>
                                        <buildArg>-H:+AddAllCharsets</buildArg>
                                        <buildArg>--enable-native-access=ALL-UNNAMED</buildArg>

										<!--TODO This should not be necessary! For some reason native-image-annotations is not working for these -->
                                        <buildArg>-H:IncludeResources=win32.*</buildArg>
                                        <buildArgs>-march=compatibility</buildArgs>
                                    </buildArgs>
                                     <metadataRepository>
                                        <enabled>true</enabled>
                                     </metadataRepository>
                                </configuration>
                            </execution>
                            <execution>
                                <id>ndl-quick</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                                <configuration>
                                    <mainClass>com.jadaptive.nodal.core.quick.NdlQuick</mainClass>
                                    <imageName>ndl-quick</imageName>
                                    <buildArgs>
										<buildArg>-H:Log=registerResource:verbose</buildArg>
                                        <buildArg>--report-unsupported-elements-at-runtime</buildArg>
                                        <buildArg>-R:MaxHeapSize=64m</buildArg>
										<buildArg>--install-exit-handlers</buildArg>
										<buildArg>--enable-http</buildArg>
										<buildArg>--enable-https</buildArg>
										<buildArg>--enable-url-protocols=http,https</buildArg>
                                        <buildArg>-H:+AddAllCharsets</buildArg>
                                        <buildArg>--enable-native-access=ALL-UNNAMED</buildArg>

										<!--TODO This should not be necessary! For some reason native-image-annotations is not working for these -->
                                        <buildArg>-H:IncludeResources=win32.*</buildArg>
                                    </buildArgs>
                                     <metadataRepository>
                                        <enabled>true</enabled>
                                     </metadataRepository>
                                </configuration>
                            </execution>
                            <execution>
                                <id>ndl-remote-node-agent</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                                <configuration>
                                    <mainClass>com.jadaptive.nodal.core.quick.NdlRemoteNodeAgent</mainClass>
                                    <imageName>ndl-remote-node-agent</imageName>
                                    <buildArgs>
										<buildArg>-H:Log=registerResource:verbose</buildArg>
                                        <buildArg>--report-unsupported-elements-at-runtime</buildArg>
                                        <buildArg>-R:MaxHeapSize=64m</buildArg>
										<buildArg>--install-exit-handlers</buildArg>
										<buildArg>--enable-http</buildArg>
										<buildArg>--enable-https</buildArg>
										<buildArg>--enable-url-protocols=http,https</buildArg>
                                        <buildArg>-H:+AddAllCharsets</buildArg>
                                        <buildArg>--enable-native-access=ALL-UNNAMED</buildArg>

										<!--TODO This should not be necessary! For some reason native-image-annotations is not working for these -->
                                        <buildArg>-H:IncludeResources=win32.*</buildArg>
                                    </buildArgs>
                                     <metadataRepository>
                                        <enabled>true</enabled>
                                     </metadataRepository>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>windows-signing</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
           
            <build>
                <plugins>
					<plugin>
						<groupId>net.jsign</groupId>
						<artifactId>jsign-maven-plugin</artifactId>
						<executions>
							<execution>
								<id>sign-windows-ndl</id>
								<goals>
									<goal>sign</goal>
								</goals>
								<configuration>
									<file>target/ndl.exe</file>
									<name>Nodal Core Tool</name>
									<url>https://jadaptive.com</url>
									<storetype>ETOKEN</storetype>
									<storepass>${install4j.safeNet.pin}</storepass>
									<keystore>${install4j.safeNet.slot}</keystore>
								</configuration>
							</execution>
							<execution>
								<id>sign-windows-ndl-quick</id>
								<goals>
									<goal>sign</goal>
								</goals>
								<configuration>
									<file>target/ndl-quick.exe</file>
									<name>Nodal Core Tool</name>
									<url>https://jadaptive.com</url>
									<storetype>ETOKEN</storetype>
									<storepass>${install4j.safeNet.pin}</storepass>
									<keystore>${install4j.safeNet.slot}</keystore>
								</configuration>
							</execution>
							<execution>
								<id>sign-windows-ndl-remote-node-agent</id>
								<goals>
									<goal>sign</goal>
								</goals>
								<configuration>
									<file>target/ndl-remote-node-agent.exe</file>
									<name>Nodal Core Tool</name>
									<url>https://jadaptive.com</url>
									<storetype>ETOKEN</storetype>
									<storepass>${install4j.safeNet.pin}</storepass>
									<keystore>${install4j.safeNet.slot}</keystore>
								</configuration>
							</execution>
						</executions>
					</plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>shaded</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>2.4.3</version>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.jadaptive.nodal.core.quick.NdlRemoteNodeAgent</mainClass>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>module-info.class</exclude>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>launcher</shadedClassifierName>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
