<?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>org.ligoj.api</groupId>
		<artifactId>parent</artifactId>
		<version>4.3.2</version>
		<relativePath>../parent/pom.xml</relativePath>
	</parent>

	<artifactId>plugin-parent</artifactId>
	<packaging>pom</packaging>
	<name>Ligoj - Plugin Parent</name>
	<description>Plugin parent pom the plugins should have.</description>
	<url>https://github.com/ligoj/ligoj-api/plugin-parent</url>
	
	<properties>
		<sonar.sources>src/main/java,src/main/resources/META-INF/resources/webjars</sonar.sources>
		<sonar.cpd.exclusions>**/messages.js</sonar.cpd.exclusions>
	</properties>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.ligoj.api</groupId>
				<artifactId>plugin-core</artifactId>
				<version>4.3.2</version>
				<scope>provided</scope>
			</dependency>
			<dependency>
				<groupId>org.ligoj.api</groupId>
				<artifactId>plugin-api-test</artifactId>
				<version>4.3.2</version>
				<scope>test</scope>
			</dependency>
			<dependency>
				<groupId>org.ligoj.api</groupId>
				<artifactId>plugin-iam-empty</artifactId>
				<version>4.3.2</version>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.ligoj.api</groupId>
			<artifactId>plugin-core</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.ligoj.api</groupId>
			<artifactId>plugin-api-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
				</includes>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>false</filtering>
				<excludes>
					<exclude>**/*.properties</exclude>
					<exclude>**/*.xml</exclude>
				</excludes>
			</resource>
		</resources>
	</build>

	<profiles>
		<!--
			Code signing of the plugin JAR (jarsigner, embedded signature - unrelated to the detached GPG
			signature required by Maven Central). Auto-activated when the release machine holds the
			code-signing keystore. The signature is verified at startup by the host's PluginsClassLoader and
			the signer identity is displayed in the plugin administration view.

			Use `-Djarsigner.skip=true` to skip the sign.

			One-time keystore creation:
			  keytool -genkeypair -keystore ~/.ligoj/code-signing.p12 -storetype PKCS12 -alias ligoj \
			    -keyalg RSA -keysize 3072 -validity 3650 -dname "CN=Ligoj, O=Ligoj"
			Truststore for the runtime verification (certificates only, never the signing key), read from
			the 'ligoj.plugin.signature.truststore' system property, defaulting to the 'plugin-vendors.p12'
			file inside the LIGOJ_HOME directory of the installation:
			  keytool -exportcert -keystore ~/.ligoj/code-signing.p12 -alias ligoj -file ligoj-vendor.cer
			  keytool -importcert -keystore plugin-vendors.p12 -storetype PKCS12 -alias ligoj -file ligoj-vendor.cer -noprompt

			The keystore password comes from the LIGOJ_SIGN_STOREPASS environment variable or the
			'ligoj.sign.storepass' property.
		-->
		<profile>
			<id>code-sign</id>
			<activation>
				<file>
					<exists>${user.home}/.ligoj/code-signing.p12</exists>
				</file>
			</activation>
			<properties>
				<ligoj.sign.keystore>${user.home}/.ligoj/code-signing.p12</ligoj.sign.keystore>
				<ligoj.sign.alias>ligoj</ligoj.sign.alias>
				<ligoj.sign.storepass>${env.LIGOJ_SIGN_STOREPASS}</ligoj.sign.storepass>
				<!-- RFC3161 timestamping: keeps the signature valid after the certificate expiry -->
				<ligoj.sign.tsa>http://timestamp.digicert.com</ligoj.sign.tsa>
			</properties>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-jarsigner-plugin</artifactId>
						<version>3.1.0</version>
						<executions>
							<execution>
								<id>sign-plugin</id>
								<goals>
									<goal>sign</goal>
								</goals>
							</execution>
						</executions>
						<configuration>
							<keystore>${ligoj.sign.keystore}</keystore>
							<storetype>PKCS12</storetype>
							<alias>${ligoj.sign.alias}</alias>
							<storepass>${ligoj.sign.storepass}</storepass>
							<tsa>${ligoj.sign.tsa}</tsa>
							<!-- Only the main JAR carries code: sources/javadoc artifacts stay untouched -->
							<processAttachedArtifacts>false</processAttachedArtifacts>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<!--
			Build the plugin's Vue.js front-end (Vite) and emit it into
			src/main/resources/.../webjars/<plugin>/vue (the Vite outDir), which
			process-resources then copies into target/classes so it is packaged in
			the plugin JAR. That bundle is gitignored, so without this a clean
			`mvn package` would ship a JAR with no front-end.

			Bound to generate-resources — i.e. BEFORE process-resources copies
			src/main/resources to target/classes; binding to `package` would be too
			late (the JAR is already assembled). Self-contained: a pinned Node/npm is
			downloaded under target/, then `npm ci` + `npm run build`.

			Auto-activated ONLY when ui/package.json exists, so Java-only plugins are
			left untouched and no useless Node download happens. Skip explicitly with
			-Dskip.ui.build=true (e.g. for a fast Java-only build).
		-->
		<profile>
			<id>ui-build</id>
			<activation>
				<file>
					<exists>${project.basedir}/ui/package.json</exists>
				</file>
			</activation>
			<properties>
				<skip.ui.build>false</skip.ui.build>
				<ui.node.version>v25.7.0</ui.node.version>
			</properties>
			<build>
				<plugins>
					<plugin>
						<groupId>com.github.eirslett</groupId>
						<artifactId>frontend-maven-plugin</artifactId>
						<version>1.15.4</version>
						<configuration>
							<workingDirectory>ui</workingDirectory>
							<!-- Node/npm extracted under target/ so `mvn clean` removes them -->
							<installDirectory>${project.build.directory}</installDirectory>
							<skip>${skip.ui.build}</skip>
						</configuration>
						<executions>
							<execution>
								<id>ui-install-node-npm</id>
								<phase>generate-resources</phase>
								<goals>
									<goal>install-node-and-npm</goal>
								</goals>
								<configuration>
									<nodeVersion>${ui.node.version}</nodeVersion>
									<!-- use the npm bundled with the installed Node -->
									<npmVersion>provided</npmVersion>
								</configuration>
							</execution>
							<execution>
								<id>ui-npm-ci</id>
								<phase>generate-resources</phase>
								<goals>
									<goal>npm</goal>
								</goals>
								<configuration>
									<arguments>ci</arguments>
								</configuration>
							</execution>
							<execution>
								<id>ui-npm-build</id>
								<phase>generate-resources</phase>
								<goals>
									<goal>npm</goal>
								</goals>
								<configuration>
									<arguments>run build</arguments>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>
</project>
