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

    Copyright © 2017-2021 Dominic Heutelbeck (dominic@heutelbeck.com)

    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 http://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>2.0.0</version>
	</parent>
	<name>SAPL Language</name>
	<artifactId>sapl-lang</artifactId>
	<packaging>jar</packaging>

	<dependencies>
		<!-- SAPL APIs implemented or used by the SAPL language core -->
		<dependency>
			<groupId>io.sapl</groupId>
			<artifactId>sapl-pdp-api</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>io.sapl</groupId>
			<artifactId>sapl-extensions-api</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>io.sapl</groupId>
			<artifactId>sapl-generator</artifactId>
			<version>${project.version}</version>
			<optional>true</optional>
		</dependency>

		<!-- XText -->
		<!-- 
			XText introduces transitive dependencies on log4j 1.2.x 
			these introduce CVE-2019-17571. Therefore log4j is excluded 
			as a transitive dependency and log4j 2 is explicitly added to
			provide the functionality. 
		-->
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext</artifactId>
			<version>${xtext.version}</version>
			<exclusions>
				<exclusion>
					<groupId>log4j</groupId>
					<artifactId>log4j</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext.xbase</artifactId>
			<version>${xtext.version}</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext.xtext.generator</artifactId>
			<version>${xtext.version}</version>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.eclipse.emf</groupId>
			<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
			<optional>true</optional>
			<exclusions>
				<exclusion>
					<groupId>log4j</groupId>
					<artifactId>log4j</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>xtext-antlr-generator</artifactId>
			<optional>true</optional>
			<exclusions>
				<exclusion>
					<groupId>log4j</groupId>
					<artifactId>log4j</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		
		<!-- Logging -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
		</dependency><!-- Replacement APIs for logging to remove vulnerable dependencies -->
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-1.2-api</artifactId>
		</dependency>		
		
		<!-- Utility -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>

		<!-- Testing -->
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-params</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>io.sapl</groupId>
			<artifactId>sapl-hamcrest</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>io.projectreactor</groupId>
			<artifactId>reactor-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.hamcrest</groupId>
			<artifactId>hamcrest</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.spotify</groupId>
			<artifactId>hamcrest-pojo</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.spotify</groupId>
			<artifactId>hamcrest-optional</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.spotify</groupId>
			<artifactId>hamcrest-jackson</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext.testing</artifactId>
			<version>${xtext.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.eclipse.xtext</groupId>
			<artifactId>org.eclipse.xtext.xbase.testing</artifactId>
			<version>${xtext.version}</version>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>junit</groupId>
					<artifactId>junit</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-inline</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.reflections</groupId>
			<artifactId>reflections</artifactId>
			<version>0.10.2</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<!-- override xtext guice for JDK16+ compatibility -->
			<groupId>com.google.inject</groupId>
			<artifactId>guice</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<version>3.3.1</version>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<verbose>false</verbose>
					<doclint>none</doclint>
					<tags>
						<tag>
							<name>generated</name>
							<placement>a</placement>
							<head>Generated Code</head>
						</tag>
						<tag>
							<name>ordered</name>
							<placement>a</placement>
							<head>EMF Ordered</head>
						</tag>
						<tag>
							<name>model</name>
							<placement>a</placement>
							<head>EMF Model</head>
						</tag>
						<tag>
							<name>returns</name>
							<placement>a</placement>
							<head>EMF Returns:</head>
						</tag>
					</tags>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>exec-maven-plugin</artifactId>
				<version>3.0.0</version>
				<dependencies>
					<!-- Harmonize SLF4J dependencies during build -->
					<dependency>
						<groupId>org.slf4j</groupId>
						<artifactId>slf4j-api</artifactId>
						<version>1.7.32</version>
					</dependency>
				</dependencies>
				<executions>
					<execution>
						<!-- 
							Attention: the ?m2e annotations may break validation of release packages 
							being pushed to maven central.
						-->
                        <!-- <?m2e ignore?> -->
						<id>mwe2GenerateEMFClasses</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>java</goal>
						</goals>
						<configuration>
							<mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
							<arguments>
								<argument>/${project.basedir}/src/main/java/io/sapl/grammar/GenerateSAPLModel.mwe2
								</argument>
								<argument>-p</argument>
								<argument>rootPath=/${project.basedir}/..</argument>
							</arguments>
							<classpathScope>compile</classpathScope>
							<includePluginDependencies>true</includePluginDependencies>
							<cleanupDaemonThreads>false
							</cleanupDaemonThreads><!-- see https://bugs.eclipse.org/bugs/show_bug.cgi?id=475098#c3 -->
							<systemProperties>
								<!-- Use custom logger configuration to make logs look like default 
									maven logs. Attention: Setting this here spills over into the mwe2Launcher 
									execution below. -->
								<systemProperty>
									<key>log4j.configuration</key>
									<value>file:${project.basedir}/plugin-log4j.properties</value>
								</systemProperty>
							</systemProperties>
						</configuration>
					</execution>
					<execution>
                        <!-- <?m2e ignore?> -->
						<id>mwe2Launcher</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>java</goal>
						</goals>
						<configuration>
							<mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
							<arguments>
								<argument>/${project.basedir}/src/main/java/io/sapl/grammar/GenerateSAPL.mwe2</argument>
								<argument>-p</argument>
								<argument>rootPath=/${project.basedir}/..</argument>
							</arguments>
							<classpathScope>compile</classpathScope>
							<includePluginDependencies>true</includePluginDependencies>
							<cleanupDaemonThreads>false
							</cleanupDaemonThreads><!-- see https://bugs.eclipse.org/bugs/show_bug.cgi?id=475098#c3 -->
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.eclipse.xtend</groupId>
				<artifactId>xtend-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-clean-plugin</artifactId>
				<configuration>
					<filesets combine.children="append">
						<fileset>
							<directory>${basedir}/../sapl-lang/src/main/xtext-gen/</directory>
							<includes>
								<include>**/*</include>
							</includes>
						</fileset>
						<fileset>
							<directory>${basedir}/../sapl-lang/src/main/emf-gen/</directory>
							<includes>
								<include>**/*</include>
							</includes>
						</fileset>
						<fileset>
							<directory>${basedir}/../sapl-lang/src/test/xtext-gen/</directory>
							<includes>
								<include>**/*</include>
							</includes>
						</fileset>
						<fileset>
							<directory>${basedir}/../sapl-ide/src/main/xtext-gen/</directory>
							<includes>
								<include>**/*</include>
							</includes>
						</fileset>
						<fileset>
							<directory>${basedir}/../sapl-web/src/main/xtext-gen/</directory>
							<includes>
								<include>**/*</include>
							</includes>
						</fileset>
						<fileset>
							<directory>${basedir}/model/generated/</directory>
						</fileset>
					</filesets>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>1.9.1</version>
				<executions>
					<execution>
                      	<!-- <?m2e execute onConfiguration,onIncremental?>  -->
						<id>add-source</id>
						<phase>initialize</phase>
						<goals>
							<goal>add-source</goal>
							<goal>add-resource</goal>
						</goals>
						<configuration>
							<sources>
								<source>src/main/xtext-gen</source>
								<source>src/main/emf-gen</source>
								<source>src/main/xtend-gen</source>
							</sources>
							<resources>
								<resource>
									<directory>src/main/xtext-gen</directory>
									<excludes>
										<exclude>**/*.java</exclude>
										<exclude>**/*.g</exclude>
									</excludes>
								</resource>
							</resources>
						</configuration>
					</execution>
					<execution>
                        <!-- <?m2e execute onConfiguration,onIncremental?> -->
						<id>add-test-source</id>
						<phase>initialize</phase>
						<goals>
							<goal>add-test-source</goal>
							<goal>add-test-resource</goal>
						</goals>
						<configuration>
							<sources>
								<source>src/test/xtext-gen</source>
							</sources>
							<resources>
								<resource>
									<directory>src/test/xtext-gen</directory>
									<excludes>
										<exclude>**/*.java</exclude>
									</excludes>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>3.3.0</version>
				<configuration>
					<descriptors>
						<descriptor>jar-with-ecore-model.xml</descriptor>
					</descriptors>
					<appendAssemblyId>false</appendAssemblyId>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>