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

	<modelVersion>4.0.0</modelVersion>
	<groupId>tools.vitruv</groupId>
	<artifactId>parent</artifactId>
	<version>2.0.2</version>
	<name>${project.artifactId}</name>
	<description>A common parent POM for all builds of vitruv.tools</description>
	<url>http://vitruv.tools</url>
	<packaging>pom</packaging>

	<licenses>
		<license>
			<name>Eclipse Public License - v 2.0</name>
			<url>https://www.eclipse.org/legal/epl-2.0/</url>
		</license>
	</licenses>

	<developers>
		<developer>
			<name>Vitruvius Developers</name>
			<email>vitruv-dev@lists.kit.edu</email>
			<organization>Karlsruhe Institute of Technology (KIT), Germany</organization>
			<organizationUrl>https://kit.edu</organizationUrl>
		</developer>
	</developers>

	<scm>
		<connection>scm:git:git://github.com/vitruv-tools/Maven-Build-Parent.git</connection>
		<developerConnection>scm:git:ssh://github.com/vitruv-tools/Maven-Build-Parent.git</developerConnection>
		<url>https://github.com/vitruv-tools/Maven-Build-Parent</url>
	</scm>

	<properties>
		<eclipse.updatesite>https://download.eclipse.org/releases/2022-06</eclipse.updatesite>
		<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version> <!-- https://search.maven.org/artifact/org.codehaus.mojo/exec-maven-plugin/ -->
		<junit-jupiter.version>5.8.1</junit-jupiter.version> <!-- https://search.maven.org/artifact/org.junit.jupiter/junit-jupiter -->
		<maven-clean-plugin.version>3.2.0</maven-clean-plugin.version> <!-- https://search.maven.org/artifact/org.apache.maven.plugins/maven-clean-plugin -->
		<maven-compiler.version>3.10.1</maven-compiler.version> <!-- https://search.maven.org/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
		<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version> <!-- https://search.maven.org/artifact/org.apache.maven.plugins/maven-gpg-plugin -->
		<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> <!-- https://search.maven.org/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
		<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version> <!-- https://search.maven.org/artifact/org.sonatype.plugins/nexus-staging-maven-plugin -->
		<org.eclipse.emf.codegen.version>2.22.0</org.eclipse.emf.codegen.version> <!-- https://search.maven.org/artifact/org.eclipse.emf/org.eclipse.emf.codegen -->
		<org.eclipse.emf.codegen.ecore.version>2.30.0</org.eclipse.emf.codegen.ecore.version> <!-- https://search.maven.org/artifact/org.eclipse.emf/org.eclipse.emf.codegen.ecore -->
		<org.eclipse.emf.mwe.utils.version>1.7.0</org.eclipse.emf.mwe.utils.version><!-- https://search.maven.org/artifact/org.eclipse.emf/org.eclipse.emf.mwe.utils -->
		<org.eclipse.emf.mwe2.version>2.13.0</org.eclipse.emf.mwe2.version> <!-- https://search.maven.org/artifact/org.eclipse.emf/org.eclipse.emf.mwe2.lib -->
		<tycho.version>2.7.4</tycho.version> <!-- https://search.maven.org/artifact/org.eclipse.tycho/tycho-maven-plugin -->
		<xtext.version>2.27.0</xtext.version> <!-- https://search.maven.org/artifact/org.eclipse.xtext/org.eclipse.xtext.common.types -->
		<macos-jvm-swt-flags/> <!-- flag for SWT workaround on macOS -->
		<maven.compiler.target>11</maven.compiler.target>
		<maven.compiler.source>11</maven.compiler.source>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	</properties>

	<repositories>
		<repository>
			<id>Eclipse</id>
			<layout>p2</layout>
			<url>${eclipse.updatesite}</url>
		</repository>
		<repository>
			<id>Vitruv License</id>
			<layout>p2</layout>
			<url>https://vitruv-tools.github.io/updatesite/release/license</url>
		</repository>
	</repositories>

	<dependencies>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-engine</artifactId>
			<version>${junit-jupiter.version}</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- Tycho target platform -->
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>target-platform-configuration</artifactId>
			</plugin>

			<!-- Cleanup -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-clean-plugin</artifactId>
			</plugin>

			<!-- Build (Xtend) -->
			<plugin>
				<groupId>org.eclipse.xtend</groupId>
				<artifactId>xtend-maven-plugin</artifactId>
			</plugin>

			<!-- Build (Tycho) -->
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-source-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-p2-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-maven-plugin</artifactId>
				<extensions>true</extensions>
			</plugin>

			<!-- Tests -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
			</plugin>
		</plugins>

		<pluginManagement>
			<plugins>
				<!--- Use Tycho -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-maven-plugin</artifactId>
					<version>${tycho.version}</version>
					<extensions>true</extensions>
				</plugin>

				<!-- Target platform configuration -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>target-platform-configuration</artifactId>
					<version>${tycho.version}</version>
					<configuration>
						<pomDependencies>consider</pomDependencies>
						<environments>
							<environment>
								<os>linux</os>
								<ws>gtk</ws>
								<arch>x86_64</arch>
							</environment>
							<environment>
								<os>win32</os>
								<ws>win32</ws>
								<arch>x86_64</arch>
							</environment>
							<environment>
								<os>macosx</os>
								<ws>cocoa</ws>
								<arch>x86_64</arch>
							</environment>
							<environment>
								<os>macosx</os>
								<ws>cocoa</ws>
								<arch>aarch64</arch>
							</environment>
						</environments>
					</configuration>
				</plugin>

				<!-- Consider Xtend in cleanup -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-clean-plugin</artifactId>
					<version>${maven-clean-plugin.version}</version>
					<executions>
						<execution>
							<id>gen-clean</id>
							<phase>clean</phase>
							<goals>
								<goal>clean</goal>
							</goals>
							<configuration>
								<filesets>
									<fileset>
										<directory>xtend-gen</directory>
									</fileset>
								</filesets>
							</configuration>
						</execution>
					</executions>
				</plugin>

				<!-- Configure exec-maven-plugin for launching MWE2 -->
				<plugin>
					<groupId>org.codehaus.mojo</groupId>
					<artifactId>exec-maven-plugin</artifactId>
					<version>${exec-maven-plugin.version}</version>
					<dependencies>
						<dependency>
							<groupId>org.eclipse.emf</groupId>
							<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
							<version>${org.eclipse.emf.mwe2.version}</version>
						</dependency>
						<dependency>
							<groupId>org.eclipse.xtext</groupId>
							<artifactId>org.eclipse.xtext.common.types</artifactId>
							<version>${xtext.version}</version>
						</dependency>
					</dependencies>
				</plugin>

				<!-- Use Xtend -->
				<plugin>
					<groupId>org.eclipse.xtend</groupId>
					<artifactId>xtend-maven-plugin</artifactId>
					<version>${xtext.version}</version>
					<executions>
						<execution>
							<phase>generate-sources</phase>
							<goals>
								<goal>compile</goal>
							</goals>
							<configuration>
								<outputDirectory>xtend-gen</outputDirectory>
							</configuration>
						</execution>
					</executions>
				</plugin>

				<!-- Use Tycho compiler without project-specific settings -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-compiler-plugin</artifactId>
					<version>${tycho.version}</version>
					<configuration>
						<useProjectSettings>false</useProjectSettings>
					</configuration>
				</plugin>

				<!-- Run test with normal surefire -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-surefire-plugin</artifactId>
					<version>${maven-surefire-plugin.version}</version>
					<executions>
						<execution>
							<id>test</id>
							<phase>test</phase>
							<goals>
								<goal>test</goal>
							</goals>
						</execution>
					</executions>
					<configuration>
						<redirectTestOutputToFile>true</redirectTestOutputToFile>
						<!-- We do not (need to) mark the source folder in eclipse-test-plugins as a test source folder, so classes are compiled into the ordinary output directory -->
						<testClassesDirectory>${project.build.outputDirectory}</testClassesDirectory>
						<trimStackTrace>false</trimStackTrace>
					</configuration>
				</plugin>

				<!-- Do not run tests with Tycho surefire by default-->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-surefire-plugin</artifactId>
					<version>${tycho.version}</version>
					<executions>
						<execution>
							<id>default-test</id>
							<phase>none</phase>
						</execution>
					</executions>
					<configuration>
						<failIfNoTests>true</failIfNoTests>
						<trimStackTrace>false</trimStackTrace>
					</configuration>
				</plugin>

				<!-- Creates source versions of bundles and features -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-source-plugin</artifactId>
					<version>${tycho.version}</version>
					<executions>
						<execution>
							<id>plugin-source</id>
							<goals>
								<goal>plugin-source</goal>
							</goals>
						</execution>
						<execution>
							<id>feature-source</id>
							<goals>
								<goal>feature-source</goal>
							</goals>
						</execution>
					</executions>
				</plugin>

				<!-- Correctly handles source features on p2 update site -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-p2-plugin</artifactId>
					<version>${tycho.version}</version>
					<executions>
						<execution>
							<id>attach-p2-metadata</id>
							<phase>package</phase>
							<goals>
								<goal>p2-metadata</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

	<profiles>
		<!-- Build configuration of parent POM itself -->
		<profile>
			<id>local-build</id>
			<activation>
				<file>
					<exists>.maven_local-build</exists>
				</file>
			</activation>
			<distributionManagement>
				<snapshotRepository>
					<id>ossrh</id>
					<url>https://oss.sonatype.org/content/repositories/snapshots</url>
				</snapshotRepository>
				<repository>
					<id>ossrh</id>
					<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
				</repository>
			</distributionManagement>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-gpg-plugin</artifactId>
						<version>${maven-gpg-plugin.version}</version>
						<executions>
							<execution>
								<id>sign-artifacts</id>
								<phase>verify</phase>
								<goals>
									<goal>sign</goal>
								</goals>
							</execution>
						</executions>
						<configuration>
							<gpgArguments>
								<arg>--pinentry-mode</arg>
								<arg>loopback</arg>
							</gpgArguments>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- Run "mvn clean deploy -P release" to a release with this profile -->
		<profile>
			<id>release</id>
			<activation>
				<property>
					<name>release</name>
				</property>
			</activation>
			<build>
				<plugins>
					<!-- To release to Maven central -->
					<plugin>
						<groupId>org.sonatype.plugins</groupId>
						<artifactId>nexus-staging-maven-plugin</artifactId>
						<version>${nexus-staging-maven-plugin.version}</version>
						<extensions>true</extensions>
						<configuration>
							<serverId>ossrh</serverId>
							<nexusUrl>https://oss.sonatype.org/</nexusUrl>
							<autoReleaseAfterClose>false</autoReleaseAfterClose>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- Runs "workflow/clean.mwe2" workflow in clean phase, if existing -->
		<profile>
			<id>mwe2-cleanup</id>
			<activation>
				<file>
					<exists>workflow/clean.mwe2</exists>
				</file>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>exec-maven-plugin</artifactId>
						<executions>
							<execution>
								<id>clean-mwe2</id>
								<phase>clean</phase>
								<goals>
									<goal>java</goal>
								</goals>
								<configuration>
									<mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
									<arguments>
										<argument>/${project.basedir}/workflow/clean.mwe2</argument>
										<argument>-p</argument>
										<argument>workspaceRoot=${maven.multiModuleProjectDirectory}</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>
						<dependencies>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.mwe.utils</artifactId>
								<version>${org.eclipse.emf.mwe.utils.version}</version>
							</dependency>
						</dependencies>
					</plugin>

					<!-- Define Xtend here to ensure that it is always executed after exec-maven-plugin when occuring in same phase -->
					<plugin>
						<groupId>org.eclipse.xtend</groupId>
						<artifactId>xtend-maven-plugin</artifactId>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- Runs "workflow/generate.mwe2" workflow in generate-source phase, if existing, with dependencies for Ecore
			metamodel code generation. If further dependencies are required, e.g., for Xtext language builds, add them
			to the plugin via pluginManagement -->
		<profile>
			<id>mwe2-execution</id>
			<activation>
				<file>
					<exists>workflow/generate.mwe2</exists>
				</file>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>exec-maven-plugin</artifactId>
						<executions>
							<execution>
								<id>execute-mwe2</id>
								<phase>generate-sources</phase>
								<goals>
									<goal>java</goal>
								</goals>
								<configuration>
									<mainClass>org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher</mainClass>
									<arguments>
										<argument>/${project.basedir}/workflow/generate.mwe2</argument>
										<argument>-p</argument>
										<argument>workspaceRoot=${maven.multiModuleProjectDirectory}</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>
						<dependencies>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.mwe2.lib</artifactId>
								<version>${org.eclipse.emf.mwe2.version}</version>
							</dependency>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.codegen</artifactId>
								<version>${org.eclipse.emf.codegen.version}</version>
							</dependency>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.codegen.ecore</artifactId>
								<version>${org.eclipse.emf.codegen.ecore.version}</version>
							</dependency>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.mwe.utils</artifactId>
								<version>${org.eclipse.emf.mwe.utils.version}</version>
							</dependency>
						</dependencies>
					</plugin>

					<!-- Define Xtend here to ensure that it is always executed after exec-maven-plugin when occuring in same phase -->
					<plugin>
						<groupId>org.eclipse.xtend</groupId>
						<artifactId>xtend-maven-plugin</artifactId>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- Run test with tycho-surefire in a full Eclipse workbench with UI if marker file is present -->
		<profile>
			<id>workbench-test</id>
			<activation>
				<file>
					<exists>.tests-need-workbench</exists>
				</file>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.eclipse.tycho</groupId>
						<artifactId>tycho-surefire-plugin</artifactId>
						<executions>
							<execution>
								<id>default-test</id>
								<phase>integration-test</phase>
							</execution>
						</executions>
						<configuration>
							<useUIHarness>true</useUIHarness>
							<useUIThread>false</useUIThread>
							<argLine>${macos-jvm-swt-flags}</argLine>
						</configuration>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-surefire-plugin</artifactId>
						<executions>
							<execution>
								<id>test</id>
								<phase>none</phase>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- macOS requires UI work to be executed on the main thread only -->
		<profile>
			<id>macos-jvm-swt-flags</id>
			<activation>
				<os>
					<family>mac</family>
				</os>
			</activation>
			<properties>
				<macos-jvm-swt-flags>-XstartOnFirstThread</macos-jvm-swt-flags>
			</properties>
		</profile>
	</profiles>
</project>
