<project name="P2 related tasks">

	<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="../lib/ant-contrib-1.0b3.jar" />

	<target name="p2.director">
		<echo message="Installing ${p2.installIU} in version ${p2.version} from ${p2.artifact.repo} into ${p2.install.path}" />

		<!-- see if a version was specified or not -->
		<var name="installIU" value="${p2.installIU}"/>
		<if>
			<and>
				<isset property="p2.version" />
				<not>
					<equals arg1="${p2.version}" arg2="" />
				</not>
			</and>
			<then>
				<echo message="Setting install IU to ${p2.installIU}/${p2.version}." />
				<var name="installIU" value="${p2.installIU}/${p2.version}" />
			</then>
		</if>

		<exec executable="${p2.builder}/eclipse" dir="${p2.builder}" failonerror="true">
			<!--<arg line="-vm ${JavaSE-1.6-dir}/bin/java" />-->
			<arg line="-application org.eclipse.equinox.p2.director" />
			<arg line="-data ${p2.builder.workspace}" />
			<arg line="-clean" />
			<arg line="-nosplash" />
			<arg line="-debug" />
			<arg line="-consoleLog" />
			<arg line="--launcher.suppressErrors" />
			<arg line="-installIU ${installIU}" />
			<arg line="-profile ${p2.profile}" />
			<arg line="-profileProperties org.eclipse.update.install.features=true" />
			<arg line="-p2.os ${p2.os}" />
			<arg line="-p2.ws ${p2.ws}" />
			<arg line="-p2.arch ${p2.arch}" />
			<arg line="-metadataRepository ${p2.metadata.repo}" />
			<arg line="-artifactRepository ${p2.artifact.repo}" />
			<arg line="-destination ${p2.install.path}" />
			<arg line="-bundlepool ${p2.install.path}" />
			<arg line="-roaming" />
			<arg line="-vmargs" />
			<arg line="-Xms256m -Xmx1024m -XX:MaxPermSize=256m" />
			<!--<arg line="-Declipse.p2.data.area=${p2.install.path}/p2" />-->
			<arg line="-Declipse.p2.MD5Check=false" />
		</exec>

		<!-- delete the metadata cache as well as the artifacts for unzipped bundles -->
		<delete failonerror="false" includeEmptyDirs="true" dir="${p2.install.path}/p2/org.eclipse.equinox.p2.core/cache" />

		<delete dir="${p2.builder.workspace}" />
		<echo message="done." />
	</target>


	<target name="p2.metadata.generator">
		<echo message="Generating P2 meta data from ${p2.generator.source} into ${p2.generator.repository}" />

		<property name="p2.generator.workspace" value="${p2.builder.workspace}" />
		<mkdir dir="${p2.generator.workspace}" />

		<exec executable="${p2.builder}/eclipse" dir="${p2.builder}" failonerror="true">
			<!--<arg line="-vm ${JavaSE-1.6-dir}/bin/java" />-->
			<arg line="-application org.eclipse.equinox.p2.metadata.generator.EclipseGenerator" />
			<arg line="-data ${p2.generator.workspace}" />
			<arg line="-clean" />
			<arg line="-nosplash" />
			<arg line="-debug" />
			<arg line="-consoleLog" />
			<arg line="--launcher.suppressErrors" />
			<arg line="-source ${p2.generator.source}" />
			<arg line="-publishArtifacts" />
			<arg line="-metadataRepository ${p2.generator.repository}" />
			<arg line="-artifactRepository ${p2.generator.repository}" />
			<arg line="-vmargs" />
			<arg line="-Xms256m -Xmx1024m -XX:MaxPermSize=256m" />
		</exec>

		<delete dir="${p2.generator.workspace}" />
		<echo message="done." />
	</target>
</project>