<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.umlet</groupId>
		<artifactId>umlet-parent</artifactId>
		<version>15.1</version>
	</parent>

	<artifactId>com.umlet.plugin</artifactId>
	<packaging>eclipse-plugin</packaging>

	<repositories>
		<repository>
			<id>eclipse-mars</id>
			<url>http://download.eclipse.org/releases/mars</url> <!-- update to e.g. photon works but only with tyco v2.3.0 (which requires java11) otherwise animal-sniffer-plugin fails -->
			<layout>p2</layout>
		</repository>
	</repositories>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<!-- unpack all dependencies from umlet-eclipse-plugin-deps and umlet-res -->
					<execution>
						<id>unpack</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>unpack</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.basedir}</outputDirectory>
							<stripVersion>true</stripVersion>
							<excludes>META-INF/**</excludes>
							<artifactItems>
								<artifactItem>
									<groupId>com.umlet</groupId>
									<artifactId>umlet-eclipse-plugin-deps</artifactId>
									<version>${project.version}</version>
								</artifactItem>
								<artifactItem>
									<groupId>com.umlet</groupId>
									<artifactId>umlet-res</artifactId>
									<version>${project.version}</version>
								</artifactItem>
							</artifactItems>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<!-- update Bundle-Version of MANIFEST.MF with current pom.xml version (replace the -<qualifier> with ".qualifier" to be compatible with OSGI versioning; ".qualifier" will be replaced by tycho with a timestamp, other qualifier values are not supported) -->
					<execution>
						<id>updateManifestVersion</id>
						<!-- this goal must be called explicitly at the same time the mvn version is updated (otherwise tycho would still use the old version) -->
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<property name="newVersionTemp" value="${newVersion}" />
								<loadresource property="newVersionOsgi">
									<propertyresource name="newVersionTemp" />
									<filterchain>
										<tokenfilter>
											<replaceregex pattern="-.*" replace=".qualifier" />
										</tokenfilter>
									</filterchain>
								</loadresource>
								<manifest file="${project.build.directory}/../META-INF/MANIFEST.MF" mode="update">
									<attribute name="Bundle-Version" value="${newVersionOsgi}" />
								</manifest>
								<echo message="Updated MANIFEST.MF Bundle-Version to ${newVersionOsgi} (derived from VM Argument: ${newVersion})" />
							</target>
						</configuration>
					</execution>
					<!-- update Bundle-ClassPath of MANIFEST.MF with all libraries -->
					<execution>
						<id>updateManifestClasspath</id>
						<phase>process-resources</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<loadfile property="bundle.classpath" srcFile="${project.basedir}/classPath.txt" />
								<echo message="Updating MANIFEST Bundle-ClassPath to: ${bundle.classpath}" />
								<manifest file="${project.build.directory}/../META-INF/MANIFEST.MF" mode="update">
									<attribute name="Bundle-ClassPath" value=".,${bundle.classpath}" />
								</manifest>
								<delete file="${project.basedir}/classPath.txt" />
								<echo message="Updated MANIFEST.MF Bundle-ClassPath to content of lib directory and deleted classPath.txt file" />
							</target>
						</configuration>
					</execution>
					<!-- move umlet-elements and umlet-swing to target/classes (because in Eclipse they are source dirs, the jars are only necessary for the build) -->
					<execution>
						<id>move-umlet-jars</id>
						<phase>process-resources</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<move file="${project.basedir}/lib/umlet-elements.jar" todir="${project.build.outputDirectory}/lib" />
								<move file="${project.basedir}/lib/umlet-swing.jar" todir="${project.build.outputDirectory}/lib" />
								<echo message="Moved jar files of linked src folders to ${project.build.outputDirectory}/lib" />
							</target>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-maven-plugin</artifactId>
				<version>${tycho.version}</version>
				<extensions>true</extensions>
			</plugin>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-compiler-plugin</artifactId>
				<version>${tycho.version}</version>
				<configuration>
					<extraClasspathElements>
						<extraClasspathElement>
							<groupId>com.umlet</groupId>
							<artifactId>umlet-swing</artifactId>
							<version>${project.version}</version>
						</extraClasspathElement>
					</extraClasspathElements>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>target-platform-configuration</artifactId>
				<version>${tycho.version}</version>
				<configuration>
					<environments>
						<environment>
							<os>linux</os>
							<ws>gtk</ws>
							<arch>x86</arch>
						</environment>
						<environment>
							<os>linux</os>
							<ws>gtk</ws>
							<arch>x86_64</arch>
						</environment>
						<environment>
							<os>win32</os>
							<ws>win32</ws>
							<arch>x86</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>
			<plugin>
				<artifactId>maven-clean-plugin</artifactId>
				<version>3.0.0</version>
				<configuration>
					<filesets>
						<fileset>
							<directory>${basedir}</directory>
							<includes>
								<include>lib/**/*</include>
								<include>custom_elements/**/*</include>
								<include>palettes/**/*</include>
							</includes>
							<followSymlinks>false</followSymlinks>
						</fileset>
					</filesets>
				</configuration>
			</plugin>
		</plugins>
		<pluginManagement>
			<plugins>
				<!-- disable version checking because the ant script with the id updateManifestVersion will replace the version correctly -->
				<plugin>
					<groupId>org.eclipse.tycho</groupId>
					<artifactId>tycho-packaging-plugin</artifactId>
					<version>${tycho.version}</version>
					<configuration>
						<strictVersions>false</strictVersions>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>
