<?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>1.4.1</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>Heiko Klare</name>
			<email>heiko.klare@kit.edu</email>
			<organization>Karlsruhe Institute of Technology (KIT), Germany</organization>
			<organizationUrl>http://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>http://github.com/vitruv-tools/Maven-Build-Parent/tree/master</url>
	</scm>

	<properties>
		<mwe.version>1.6.1</mwe.version>
		<mwe2.version>2.12.1</mwe2.version>
		<tycho.version>2.5.0</tycho.version>
		<xtext.version>2.25.0</xtext.version>
		<emf-codegen.version>2.22.0</emf-codegen.version>
		<ecore-codegen.version>2.26.0</ecore-codegen.version>
		<maven-clean.version>3.1.0</maven-clean.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<maven-compiler.version>3.8.1</maven-compiler.version>
		<maven-surefire.version>2.22.2</maven-surefire.version>
		<junit-jupiter.version>5.8.2</junit-jupiter.version>
		<maven.compiler.target>11</maven.compiler.target>
		<maven.compiler.source>11</maven.compiler.source>
		<eclipse.updatesite>https://download.eclipse.org/releases/2021-12</eclipse.updatesite>
		<macos-jvm-swt-flags/> <!-- flag for SWT workaround on macOS -->
	</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>

	<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.eclipse.tycho</groupId>
				<artifactId>tycho-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>
						</environments>
					</configuration>
				</plugin>

				<!-- Consider Xtend in cleanup -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-clean-plugin</artifactId>
					<version>${maven-clean.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>3.0.0</version>
					<dependencies>
						<dependency>
							<groupId>org.eclipse.emf</groupId>
							<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
							<version>${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.version}</version>
					<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>

				<!-- Run tests with Tycho surefire -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-surefire-plugin</artifactId>
					<version>${tycho.version}</version>
					<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>

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

	<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>1.6</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>1.6.8</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>${mwe.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>${mwe2.version}</version>
							</dependency>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.codegen</artifactId>
								<version>${emf-codegen.version}</version>
							</dependency>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.codegen.ecore</artifactId>
								<version>${ecore-codegen.version}</version>
							</dependency>
							<dependency>
								<groupId>org.eclipse.emf</groupId>
								<artifactId>org.eclipse.emf.mwe.utils</artifactId>
								<version>${mwe.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>

		<!-- Builds the aggregated updatesite "updatesite.aggr", if existing, with the CBI aggregator -->
		<profile>
			<id>aggregated-updatesite</id>
			<activation>
				<file>
					<exists>updatesite.aggr</exists>
				</file>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-clean-plugin</artifactId>
						<version>${maven-clean.version}</version>
						<executions>
							<execution>
								<id>workspace-clean</id>
								<phase>clean</phase>
								<goals>
									<goal>clean</goal>
								</goals>
								<configuration>
									<filesets>
										<fileset>
											<directory>workspace</directory>
										</fileset>
									</filesets>
								</configuration>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.eclipse.tycho.extras</groupId>
						<artifactId>tycho-eclipserun-plugin</artifactId>
						<version>${tycho.version}</version>
						<configuration>
							<repositories>
								<repository>
									<id>Eclipse</id>
									<layout>p2</layout>
									<url>${eclipse.updatesite}</url>
								</repository>
								<repository>
									<id>Eclipse CBI Aggregator</id>
									<layout>p2</layout>
									<url>http://download.eclipse.org/cbi/updates/aggregator/ide/4.13/</url>
								</repository>
							</repositories>
							<jvmArgs>
								<args>-Xmx1024m</args>
							</jvmArgs>
							<applicationsArgs>
								<args>-application</args>
								<args>org.eclipse.cbi.p2repo.cli.headless</args>
								<args>aggregate</args>
								<args>--buildModel</args>
								<args>updatesite.aggr</args>
								<args>--action</args>
								<args>BUILD</args>
							</applicationsArgs>
							<dependencies>
								<dependency>
									<artifactId>org.eclipse.equinox.p2.core.feature</artifactId>
									<type>eclipse-feature</type>
								</dependency>
								<dependency>
									<artifactId>org.eclipse.e4.rcp</artifactId>
									<type>eclipse-feature</type>
								</dependency>
								<dependency>
									<artifactId>org.eclipse.cbi.p2repo.aggregator.editor.feature</artifactId>
									<type>eclipse-feature</type>
								</dependency>
							</dependencies>
						</configuration>
						<executions>
							<execution>
								<goals>
									<goal>eclipse-run</goal>
								</goals>
								<phase>package</phase>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- Uses maven-surefire instead of tycho-surefire to run tests that do not require an Equinox platform -->
		<profile>
			<id>standalone-test</id>
			<activation>
				<file>
					<exists>.tests-without-platform</exists>
				</file>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.junit.jupiter</groupId>
					<artifactId>junit-jupiter-engine</artifactId>
				</dependency>
			</dependencies>
			<build>
				<plugins>
					<plugin>
						<groupId>org.eclipse.tycho</groupId>
						<artifactId>tycho-surefire-plugin</artifactId>
						<executions>
							<execution>
								<id>default-test</id>
								<phase>none</phase>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-surefire-plugin</artifactId>
						<executions>
							<execution>
								<id>test</id>
								<phase>test</phase>
								<goals>
									<goal>test</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>

		<!-- Configure tycho-surefire to run tests in a full Eclipse workbench with UI -->
		<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>
						<configuration>
							<useUIHarness>true</useUIHarness>
							<useUIThread>false</useUIThread>
							<argLine>${macos-jvm-swt-flags}</argLine>
						</configuration>
					</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>
