<?xml version="1.0" encoding="UTF-8"?>
<!--
	This Maven setup mirrors the nu.psnet.quickimage update site (using site.xml) to a local p2 repository. This makes 
	the repository consumable by Tycho, and detaches our build process from external servers. The mirroring process 
	always fetches the latest version from the remote update site.

	Call "mvn clean package" in this directory to run the mirroring.
-->
<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>

	<groupId>de.rcenvironment.thirdparty</groupId>
	<artifactId>nu.psnet.quickimage-p2-mirror</artifactId>
	<version>1.0.0</version>
	<packaging>pom</packaging>
	
	<properties>
		<!-- TODO upgrade; also, inherit this from a common parent POM instead? --> 
		<internal.tycho.version>0.23.1</internal.tycho.version>
		<mirror.sourceUrl>http://psnet.nu/eclipse/updates/</mirror.sourceUrl>
		<mirror.outputDir>${project.basedir}/../../p2/nu.psnet.quickimage</mirror.outputDir>
	</properties>
	
	<build>
		<!-- TODO add "clean" rule for the out-of-tree mirror directory -->
		<plugins>
			<plugin>
				<groupId>org.eclipse.tycho.extras</groupId>
				<artifactId>tycho-p2-extras-plugin</artifactId>
				<version>${internal.tycho.version}</version>
				<executions>
					<!-- step 1: mirror -->
					<execution>
						<id>mirror</id>
						<phase>process-resources</phase>
						<goals>
							<goal>mirror</goal>
						</goals>
						<configuration>
							<source>
								<repository>
									<url>${mirror.sourceUrl}</url>
								</repository>
							</source>
							<latestVersionOnly>true</latestVersionOnly>
							<destination>${mirror.outputDir}</destination>
						</configuration>
					</execution>
					<!-- step 3: generate the full p2 metadata for the mirrored artifacts -->
					<!-- note: this is necessary as the external repository is an old-style update site - misc_ro, Oct 2015 -->
					<execution>
						<id>generate-metadata</id>
						<phase>package</phase>
						<goals>
							<goal>publish-features-and-bundles</goal>
						</goals>
						<configuration>
							<!-- input -->
							<sourceLocation>${mirror.outputDir}</sourceLocation>
							<!-- output -->
							<artifactRepositoryLocation>${mirror.outputDir}</artifactRepositoryLocation>
							<metadataRepositoryLocation>${mirror.outputDir}</metadataRepositoryLocation>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>1.7</version>
				<executions>
					<execution>
						<!-- step 2: strip the p2 metadata that contains the "partial IUs" that which be used for dependency resolution in Tycho -->
						<id>remove-incomplete-metadata</id>
						<phase>process-resources</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<delete file="${mirror.outputDir}/content.jar" />
								<delete file="${mirror.outputDir}/artifacts.jar" />
							</target>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	
</project>
