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

    Copyright (C) 2017-2025 Dominic Heutelbeck (dominic@heutelbeck.com)

    SPDX-License-Identifier: Apache-2.0

    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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>io.sapl</groupId>
		<artifactId>sapl-policy-engine</artifactId>
		<version>3.0.0</version>
	</parent>
	<artifactId>sapl-maven-plugin</artifactId>
	<name>SAPL Maven Plugin</name>
	<packaging>maven-plugin</packaging>

	<properties>
		<maven.version>3.9.0</maven.version>
		<sonar.sources>src/main/java,src/main/resources/html/templates</sonar.sources>
	</properties>

	<dependencies>
		<!-- Maven Plugin Dependencies -->
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-plugin-api</artifactId>
			<version>${maven.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-core</artifactId>
			<version>${maven.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.maven.plugin-tools</groupId>
			<artifactId>maven-plugin-annotations</artifactId>
			<version>${maven.version}</version><!--$NO-MVN-MAN-VER$-->
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>jakarta.xml.bind</groupId>
			<artifactId>jakarta.xml.bind-api</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.activation</groupId>
			<artifactId>activation</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>org.glassfish.jaxb</groupId>
			<artifactId>jaxb-runtime</artifactId>
		</dependency>

		<!-- SAPL -->
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>sapl-coverage-api</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>io.sapl</groupId>
			<artifactId>sapl-lang</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>io.sapl</groupId>
			<artifactId>sapl-web</artifactId>
			<version>${project.version}</version>
		</dependency>
		<!-- Sapl Plugin Dependencies -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

		<!-- Testing -->
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.maven.plugin-testing</groupId>
			<artifactId>maven-plugin-testing-harness</artifactId>
			<scope>test</scope>
			<version>3.3.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-compat</artifactId>
			<version>${maven.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-core</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<?m2e ignore?>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-plugin-plugin</artifactId>
				<version>3.10.2</version>
			</plugin>

			<plugin>
				<?m2e ignore?>
				<groupId>org.eclipse.sisu</groupId>
				<artifactId>sisu-maven-plugin</artifactId>
				<version>0.3.5</version>
				<executions>
					<execution>
						<id>generate-index</id>
						<goals>
							<goal>main-index</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<!-- 
        		The CSS and JS resources of the xtext web dependency have to copied 
				to the matching frontend folder CSS and images are hard coded into the HTML 
				template of the web component JS file
			 -->

			<plugin>
				<?m2e ignore?>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>unpack-sapl</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<artifactItems>
								<artifactItem>
									<groupId>${project.groupId}</groupId>
									<artifactId>sapl-web</artifactId>
									<version>${project.version}</version>
									<overWrite>true</overWrite>
									<outputDirectory>
										${project.build.directory}/sapl</outputDirectory>
									<includes>static/**/*</includes>
								</artifactItem>
							</artifactItems>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>com.github.eirslett</groupId>
				<artifactId>frontend-maven-plugin</artifactId>
				<version>1.15.0</version>
				<configuration>
					<installDirectory>${project.build.directory}</installDirectory>
				</configuration>
				<executions>
					<execution>
						<phase>generate-resources</phase>
						<id>install node and npm</id>
						<goals>
							<goal>install-node-and-npm</goal>
						</goals>
						<configuration>
							<nodeVersion>v18.18.2</nodeVersion>
							<npmVersion>9.8.1</npmVersion>
						</configuration>
					</execution>
					<execution>
						<id>npm install</id>
						<goals>
							<goal>npm</goal>
						</goals>
						<configuration>
							<arguments>install</arguments>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-resources-sapl</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>
								${project.build.directory}/classes/dependency-resources</outputDirectory>
							<resources>
								<resource>
									<directory>
										${project.build.directory}/sapl/static</directory>
									<includes>
										<include>sapl-mode.js</include>
									</includes>
									<filtering>false</filtering>
								</resource>
							</resources>
						</configuration>
					</execution>
					<execution>
						<id>copy-files-coverage-report</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>
								${project.build.directory}/classes/dependency-resources</outputDirectory>
							<resources>
								<resource>
									<directory>
										${project.basedir}/node_modules</directory>
									<filtering>true</filtering>
									<includes>
										<include>
											**/@popperjs/core/dist/umd/popper.min.js</include>
										<include>
											**/bootstrap/dist/js/bootstrap.min.js</include>
										<include>
											**/bootstrap/dist/css/bootstrap.min.css</include>
										<include>
											**/codemirror/lib/codemirror.js</include>
										<include>
											**/codemirror/addon/mode/simple.js</include>
										<include>
											**/codemirror/lib/codemirror.css</include>
										<include>
											**/requirejs/require.js</include>
									</includes>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-clean-plugin</artifactId>
				<configuration>
					<filesets>
						<fileset>
							<directory>${project.basedir}</directory>
							<followSymlinks>false</followSymlinks>
							<includes>
								<include>node_modules/**</include>
								<include>package-lock.json</include>
							</includes>
						</fileset>
					</filesets>
				</configuration>
				<executions>
					<execution>
						<id>clean node modules</id>
						<phase>clean</phase>
						<goals>
							<goal>clean</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>