<project name="Eclipse SDK build" default="provisionSDKinDropins" basedir=".">
	<tstamp>
		<format property="timestamp" pattern="yyyyMMddHHmmss" />
	</tstamp>
	<record name="build_${timestamp}.log" />
	<echo message="Build log is available in build_${timestamp}.log" />
	
	<property environment="env"/>
	<property name="jhome" value="${env.JAVA_HOME}"/>
	<condition property="javaHomeExists">
		<resourceexists>
			<file file="${jhome}"/>
		</resourceexists>
	</condition>
	<fail unless="javaHomeExists" message="JAVA_HOME is not set properly"/>

	<property name="baseBuilder" value="${basedir}/bootstrap" />
	<property name="launcher" value="${basedir}/bootstrap/plugins/org.eclipse.equinox.launcher.jar" />
	<property name="eclipse.pdebuild.scripts" value="${basedir}/bootstrap/plugins/org.eclipse.pde.build/scripts" />

	<property file="build.properties" />

	<available file="eclipse-${label}-src.tar.bz2" property="sdkSourcePresent" value="true" />
	<available file="eclipse/plugins/org.eclipse.equinox.launcher/build.properties" property="extractedSdkSourcePresent" value="true" />

	<condition property="onlyExtractedSdkSourcePresent">
		<and>
			<isfalse value="${sdkSourcePresent}" />
			<istrue value="${extractedSdkSourcePresent}" />
		</and>
	</condition>
	<condition property="sdkSourceTarballPresent">
		<or>
			<isset property="sdkSourcePresent" />
			<isset property="extractedSdkSourcePresent" />
		</or>
	</condition>

	<available file="eclipse-build-generatedScripts.tar.bz2" property="scriptsPresent" value="true" />
	<available file="eclipse-sdktests-${label}-src.tar.bz2" property="testsSourcePresent" value="true" />
	<available file="eclipse-sdktests-${label}-scripts.tar.bz2" property="testsScriptsPresent" value="true" />

	<!-- Check what has already been done -->
	<available property="unpack.complete" file="unpack-stamp" value="true" />
	<uptodate property="buildId.complete" srcfile="unpack-stamp" targetfile="buildId-stamp" />
	<uptodate property="patch.complete" srcfile="unpack-stamp" targetfile="patch-stamp" />
	<uptodate property="symlinks.complete" srcfile="patch-stamp" targetfile="symlinks-stamp" />
	<uptodate property="compilelibs.complete" srcfile="unpack-stamp" targetfile="compilelibs-stamp" />
	<uptodate property="build.complete" srcfile="patch-stamp" targetfile="build-stamp" />
	<uptodate property="p2prep.complete" srcfile="build-stamp" targetfile="p2prep-stamp" />
	<uptodate property="provision.platform.complete" srcfile="build-stamp" targetfile="provision.platform-stamp" />
	<uptodate property="provision.cvs.complete" srcfile="build-stamp" targetfile="provision.cvs-stamp" />
	<uptodate property="provision.tests.complete" srcfile="testsbuild-stamp" targetfile="provision.tests-stamp" />
	<uptodate property="provisionSDKinDropins.complete" srcfile="build-stamp" targetfile="provisionSDKinDropins-stamp" />
	<available file="bootstrap/plugins" property="bootstrapped" value="true" />

	<property name="topBuildDir" value="${basedir}/build" />
	<property name="homeDir" value="${basedir}/home" />
	<property name="baseworkspace" value="${basedir}/baseworkspace" />
	<property name="buildworkspace" value="${basedir}/buildworkspace" />
	<property name="buildDirectory" value="${topBuildDir}/eclipse-${label}-src" />
	<property name="buildConfigs" value="${buildDirectory}/buildConfigs" />
	<property name="buildConfig" value="${buildConfigs}/eclipse-build-config" />
	<property name="productFiles" value="${buildConfig}/productFiles" />
	<property name="reposource" value="${buildDirectory}/reposource" />
	<property name="provisionDir" value="${buildDirectory}/installation" />

	<!-- Distros with alternative JUnit 4 JAR locations should pass this
	     parameter in to ant -->
	<property name="junit4JarLocation" value="/usr/share/java/junit4.jar" />

	<!-- Determine host architecture -->
	<exec executable="uname" outputproperty="uname-m">
		<arg line="-m" />
	</exec>
	<condition property="hostArch" value="arm">
		<matches pattern="^arm.*" string="${uname-m}" />
	</condition>
	<condition property="hostArch" value="x86">
		<matches pattern="i[0-9]*86" string="${uname-m}" />
	</condition>
	<condition property="hostArch" value="PA_RISC">
		<matches pattern="^parisc.*" string="${uname-m}" />
	</condition>
	<condition property="hostArch" value="sparc">
		<matches pattern="sparcv9" string="${uname-m}" />
	</condition>
	<condition property="hostArch" value="${uname-m}">
		<not>
			<isset property="hostArch" />
		</not>
	</condition>
	<condition property="buildArch" value="${hostArch}">
		<not>
			<isset property="buildArch" />
		</not>
	</condition>
	<echo message="uname -m: ${uname-m}. Build eclipse on ${hostArch} for ${buildArch}." />

	<property name="destDir" value="" />
	<property name="prefix" value="/usr/local" />
	<!-- Do we want /usr/lib64 if it's a 64-bit architecture? -->
	<property name="multilib" value="false" />
	<condition property="setLib64">
		<and>
			<istrue value="${multilib}" />
			<or>
				<!-- Is it a 64-bit architecture? -->
				<equals arg1="${buildArch}" arg2="x86_64" />
				<equals arg1="${buildArch}" arg2="ppc64" />
			</or>
		</and>
	</condition>

	<target name="setLib64Dir" if="setLib64">
		<property name="libDir" value="lib64" />
	</target>

	<target name="setLibDir" depends="setLib64Dir">
		<property name="libDir" value="lib" />
		<property name="installationDir" value="${destDir}${prefix}/${libDir}/eclipse" />
	</target>

	<target name="getInstallationDir" depends="setLibDir">
		<echo message="Installation directory will be ${destDir}/${prefix}/${libDir}" />
	</target>

	<target name="bootstrap" unless="bootstrapped">

		<!-- Some of the equinox plugins are required to use this environment, because their build will fail with full vm. Bootstrap needs to have this available.-->		
		<javac compiler="classic" srcdir="${buildDirectory}/environments/ee.minimum/src" destdir="${buildDirectory}/environments/ee.minimum" target="1.1" source="1.1" />
		<jar basedir="${buildDirectory}/environments/ee.minimum" destfile="bootstrap/environment/ee.minimum.jar"/>

		<ant inheritall="false" antfile="pdebuild.xml">
			<property name="buildId" value="${buildId}" />
			<property name="buildArch" value="${buildArch}" />
			<property name="buildDirectory" value="../../" />
		</ant>
	</target>

	<!-- Run this target with antRunner application -->
	<target name="generateBuildXmls" depends="unpack">
		<ant antfile="pdebuild.xml" target="generateScripts" />
	</target>

	<target name="fetch" unless="sdkSourceTarballPresent">
		<fail message="SDK source tarball eclipse-${label}-src.tar.bz2 is not present.  Please either download a file such as eclipse-${label}-src.tar.bz2 from http://download.eclipse.org/technology/linuxtools/eclipse-build/, generate one by running ./buildSDKSource.sh or update build.properties file to reflect your tarball version." />
	</target>

	<target name="extractBuildXmls" if="scriptsPresent">
		<untar compression="bzip2" dest="${basedir}/build/eclipse-${label}-src" src="${basedir}/eclipse-build-generatedScripts.tar.bz2" />
	<exec executable="${basedir}/jasper7.sh">
		<arg value="${label}"/>
	</exec>
		<!--
		<fail message="Build scripts to bootstrap PDE Build must be generated and present in eclipse-build-generatedScripts.tar.bz2.  See pdebuild.xml for details."/>
		-->
	</target>

	<target name="extractSource" unless="onlyExtractedSdkSourcePresent">
		<echo message="Extracting SDK source (tar jxf eclipse-${label}-src.tar.bz2)" />
		<untar dest="${topBuildDir}" src="${basedir}/eclipse-${label}-src.tar.bz2" compression="bzip2" />
	</target>

	<target name="copySource" unless="sdkSourcePresent">
		<echo message="Copy SDK source (cp -rd --not-target-directory eclipse ${buildDirectory})" />
		<exec executable="cp" failonerror="true">
			<arg value="-rd" />
			<arg value="--no-target-directory" />
			<arg value="eclipse" />
			<arg value="${buildDirectory}" />
		</exec>
	</target>

	<available file="${basedir}/eclipse-build-feature" property="buildFeaturePresent" value="true" />
	<target name="symlinkBuildFeature" unless="buildFeaturePresent">
	  <echo message="creating link to feature dir (../eclipse-build-feature)" />
	  <symlink link="${basedir}/eclipse-build-feature" resource="${basedir}/../eclipse-build-feature"/>
	</target>

	<available file="${basedir}/eclipse-build-config" property="buildConfigPresent" value="true" />
	<target name="symlinkBuildConfig" unless="buildConfigPresent">
	  <echo message="creating link to config dir (../eclipse-build-config)" />
	  <symlink link="${basedir}/eclipse-build-config" resource="${basedir}/../eclipse-build-config"/>
	</target>

	<target name="unpack" depends="fetch,setLibDir,symlinkBuildFeature,symlinkBuildConfig" unless="unpack.complete">
		<delete dir="${topBuildDir}" />
		<mkdir dir="${topBuildDir}" />

		<!-- User home used for build -->
		<delete dir="${homeDir}" />
		<mkdir dir="${homeDir}" />

		<!-- Workspaces used for build -->
		<delete dir="${baseworkspace}" />
		<mkdir dir="${baseworkspace}" />
		<delete dir="${buildworkspace}" />
		<mkdir dir="${buildworkspace}" />

		<antcall target="extractSource" />
		<antcall target="copySource" />
		<antcall target="extractBuildXmls" />

		<delete dir="${buildDirectory}/buildConfigs" />
		<mkdir dir="${buildDirectory}/buildConfigs" />

		<echo message="Copying eclipse-build main feature source" />
		<copy todir="${buildConfigs}/eclipse-build-config">
			<fileset dir="eclipse-build-config" />
		</copy>

		<echo message="Copying eclipse-build builder" />
		<copy todir="${buildDirectory}/features/eclipse-build-feature">
			<fileset dir="eclipse-build-feature" />
		</copy>
		<delete verbose="true">
			<fileset dir="${buildDirectory}/plugins" includes="**/ECLIPSEF.SF" />
			<fileset dir="${buildDirectory}/plugins" includes="**/ECLIPSEF.RSA" />
		</delete>
		
		<!-- add additional archs for org.eclipse.swt, org.eclipse.equinox.launcher & org.eclipse.core.filesystem -->
		<antcall target="generateSecondaryFragments"/>
		
		<!-- prepare ecf build tree -->
		<delete>
			<fileset dir="${buildDirectory}/plugins" includes="org.eclipse.ecf*" />
			<fileset dir="${buildDirectory}/plugins" includes="org.eclipse.jetty*" />
		</delete>
		<!--delete dir="${buildDirectory}/plugins/org.eclipse.equinox.http.jetty_1.1.100" /-->
		<!-- Create a stamp file -->
		<echo file="unpack-stamp" />
	</target>
	
	<target name="generateSecondaryFragments">
		<!-- TODO: replace the rename.sh with ant -->
		
		<copy file="additionalArchs/rename.sh" todir="${buildDirectory}/plugins" /> 
		
		<generateArch newArch="alpha" archBase="x86_64"/>
		<generateArch newArch="arm" archBase="x86"/>
		<generateArch newArch="ia64" archBase="x86_64"/>
		<generateArch newArch="mips" archBase="x86_64"/>
		<generateArch newArch="mipsel" archBase="x86_64"/>
		<generateArch newArch="PA_RISC" archBase="x86_64"/>
		<generateArch newArch="ppc" archBase="x86" />
		<generateArch newArch="ppc64" archBase="x86_64"/>
		<generateArch newArch="sparc" archBase="x86" />
                <generateArch newArch="sparc64" archBase="x86_64"/>

		<delete file="${buildDirectory}/plugins/rename.sh"/>
	</target>
	<macrodef name="copyPlugin">
		<attribute name="pluginName" />
		<attribute name="archBase" />
		<attribute name="newArch" />
		<sequential>
			<copy todir="${buildDirectory}/plugins/@{pluginName}.@{newArch}">
				<resources>
					<fileset dir="${buildDirectory}/plugins/@{pluginName}.@{archBase}">
						<include name="**" />
					</fileset>
				</resources>
			</copy>
		</sequential>
	</macrodef>

	<macrodef name="generateArch">
		<attribute name="archBase" />
		<attribute name="newArch" />
		<sequential>
			<copyPlugin pluginName="org.eclipse.swt.gtk.linux"
			            archBase="@{archBase}" newArch="@{newArch}" />
			<copyPlugin pluginName="org.eclipse.core.filesystem.linux"
			            archBase="@{archBase}" newArch="@{newArch}" />
			<copyPlugin pluginName="org.eclipse.core.net.linux"
			            archBase="@{archBase}" newArch="@{newArch}" />
			<copyPlugin pluginName="org.eclipse.equinox.launcher.gtk.linux"
			            archBase="@{archBase}" newArch="@{newArch}" />
			<exec dir="${buildDirectory}/plugins" executable="sh" failonerror="true">
				<arg line="rename.sh @{archBase} @{newArch}" />
			</exec>
			<replace dir="${buildDirectory}/plugins" value="@{newArch}" token="@{archBase}">
				<exclude name="rename.sh" />
				<include name="*@{newArch}/**/*.*" />
				<excludesfile name="${buildDirectory}/plugins/rename.sh" />
			</replace>
			<copy todir="${buildDirectory}/features/org.eclipse.platform/about_files/linux.gtk.@{newArch}/">
    				<fileset dir="${buildDirectory}/features/org.eclipse.platform/about_files/linux.gtk.@{archBase}"/>
 			</copy>
			<mkdir dir="${buildDirectory}/features/" />
		</sequential>
	</macrodef>

	<target name="clean-sdk">
		<delete dir="${homeDir}" />
		<delete dir="${baseworkspace}" />
		<delete dir="${buildworkspace}" />
		<delete dir="${topBuildDir}" />
		<delete dir="${testsBuildDir}" />
		<delete dir="configuration" />
		<delete dir="p2" />
		<delete dir="workspace" />
		<delete dir="${basedir}/task-bin" />
		<delete>
			<fileset dir="." includes="*-stamp" />
		</delete>
		<delete file="sdk-tests.properties" />
	</target>

	<target name="clean" depends="clean-sdk">
		<delete dir="bootstrap/configuration/org.eclipse.core.runtime" />
		<delete dir="bootstrap/configuration/org.eclipse.equinox.app" />
		<delete dir="bootstrap/configuration/org.eclipse.osgi" />
		<delete dir="bootstrap/p2" />
		<delete dir="bootstrap/plugins" />
		<delete dir="bootstrap/workspace" />
	</target>

	<target name="distclean" depends="clean">
		<delete>
			<fileset dir="." includes="*.log" />
		</delete>
		<delete includeemptydirs="true">
			<fileset dir="." includes="tests_*/**" />
		</delete>
	</target>

	<target name="insertBuildId" depends="unpack" unless="buildId.complete">
		<replace dir="${buildDirectory}/plugins" value="${buildId}" token="@build@">
			<include name="**/about.mappings" />
		</replace>
		<replace dir="${buildDirectory}" value="${buildId}" token="@build@">
			<include name="**/configuration/config.ini" />
		</replace>
		<echo file="buildId-stamp" />
	</target>

	<target name="applyPatches" depends="insertBuildId" unless="patch.complete">
		<!-- eclipse-build-only patches -->
		<patch patchfile="${basedir}/patches/eclipse-buildswtnatives.patch" dir="${buildDirectory}" strip="1" />
		<patch patchfile="${basedir}/patches/eclipse-addArchesAnd64bitSWT.patch" dir="${buildDirectory}" strip="1" />
		<patch patchfile="${basedir}/patches/eclipse-add-archs-filesystem.patch" dir="${buildDirectory}" strip="1" />
		<patch patchfile="${basedir}/patches/eclipse-add-archs-swt.patch" dir="${buildDirectory}" strip="1" />
		<patch patchfile="${basedir}/patches/eclipse-add-archs-executable.patch" dir="${buildDirectory}" strip="1" />
		<patch patchfile="${basedir}/patches/eclipse-add-ppc64-sparc64-s390-s390x.patch" dir="${buildDirectory}" strip="1" />
		
		<patch patchfile="${basedir}/patches/donotstorebuildlogsinfiles.patch" dir="${buildDirectory}" strip="1" />

		<patch patchfile="${basedir}/patches/eclipse-pde.build-add-package-build.patch" dir="${buildDirectory}" strip="1" />

		<!-- This one should be removed when Eclipse bug 369215 is fixed -->
		<patch patchfile="${basedir}/patches/gnomeproxy-makefile.patch" dir="${buildDirectory}" strip="1" />

		<patch patchfile="${basedir}/patches/eclipse-nosourcebundlesfordependencies.patch" dir="${buildDirectory}" strip="1" />

		<replace file="${buildDirectory}/plugins/org.eclipse.pde.build/templates/package-build/build.properties" token="/usr/share/eclipse" value="/usr/${libDir}/eclipse" />
		<chmod dir="${buildDirectory}/plugins/org.eclipse.pde.build/templates/package-build" includes="*.sh" perm="a+x" />
		<!-- end eclipse-build-only patches -->
		<!-- Only build for one target (bug #293952) -->
		<copy file="${buildConfigs}/eclipse-build-config/build.properties.in" tofile="${buildConfigs}/eclipse-build-config/build.properties" />
		<replace file="${buildConfigs}/eclipse-build-config/build.properties" token="@build_arch@" value="${buildArch}" />

		<!-- It would be good to remove those two entries, however, before you spent some time here, be warned that: -->		
		<!-- (1) Those plugins contain precompiled classes with source in zips -->
		<!-- (2) Those plugins have no source folders -->
		<!-- (3) Those plugins have dependencies -->
		<!-- Point (3) implies that you cannot have your own build.xml, because you need dependencies that only PDE can discover -->
		<!-- Point (2) implies that you cannot use PDE build.xml, because there is no source folder, so nothing will be compiled -->
		<!-- Point (1) implies that developers will not create a source folder, because they want to ship binaries -->
		<!-- So we have to live with those two patches -->
		<patch patchfile="${basedir}/patches/osgi-util.patch" dir="${buildDirectory}" strip="0" backups="true"/>
		<patch patchfile="${basedir}/patches/osgi-services-build.patch" dir="${buildDirectory}" strip="0" />

		<patch patchfile="${basedir}/patches/eclipse-help-feature-adjust-dependencies.patch" dir="${buildDirectory}" strip="1" />
		<patch patchfile="${basedir}/patches/eclipse-equinox-jsp-jasper.patch" dir="${buildDirectory}" strip="0" />
		<patch patchfile="${basedir}/patches/serverside-patch-additional-imports.patch" dir="${buildDirectory}" strip="0" />

		<patch patchfile="${basedir}/patches/nonRelativeLicense.patch" dir="${buildDirectory}" strip="0" />

		<patch patchfile="${basedir}/patches/swt-no-api-generation.patch" dir="${buildDirectory}" strip="0" />

		<patch patchfile="${basedir}/patches/add-plugin-version-of-arm-launcher-fragment.patch" dir="${buildDirectory}" strip="1" />
		<echo file="patch-stamp" />
	</target>

	<target name="buildHelperTask">
		<mkdir dir="task-bin" />
		<javac compiler="modern" target="1.5" source="1.5" debug="true" srcdir="${basedir}/task-src" destdir="${basedir}/task-bin" includeantruntime="true" >
			<compilerarg value="-Xlint:-options"/>
		</javac>
	</target>

	<target name="defineTasks" depends="buildHelperTask">
		<taskdef name="symlinkOSGiJars" classname="org.eclipse.linuxtools.eclipsebuild.SymlinkOSGiJars" classpath="${basedir}/task-bin" />
		<taskdef name="symlinkInstalledOSGiJars" classname="org.eclipse.linuxtools.eclipsebuild.SymlinkInstalledOSGiJars" classpath="${basedir}/task-bin" />
		<taskdef name="symlinkNonOSGiJars" classname="org.eclipse.linuxtools.eclipsebuild.SymlinkNonOSGiJars" classpath="${basedir}/task-bin" />
	</target>

	<target name="symlinkDeps" depends="applyPatches,defineTasks" unless="symlinks.complete">
		<symlinkOSGiJars dependencies="${basedir}/dependencies/dependencies.properties" topLevelDir="${buildDirectory}/plugins" manifests="${basedir}/dependencyManifests" copyFiles="${copyFiles}"/>
		<!-- delete all windows scripts and symlink linux ones -->
		<delete dir="${buildDirectory}/plugins/org.apache.ant_1.8.3.v20120316-1400/bin"/>
		<symlinkNonOSGiJars dependencies="${basedir}/dependencies/nonosgidependencies.properties" topLevelDir="${buildDirectory}/plugins"  copyFiles="${copyFiles}"/>
		<symlinkOSGiJars dependencies="${basedir}/dependencies/jdtdependencies.properties" topLevelDir="${buildDirectory}/plugins" manifests="${basedir}/dependencyManifests" copyFiles="${copyFiles}"/>
		<symlinkNonOSGiJars dependencies="${basedir}/dependencies/jdtnonosgidependencies.properties" topLevelDir="${buildDirectory}/plugins" copyFiles="${copyFiles}"/>
		<symlinkOSGiJars dependencies="${basedir}/dependencies/sdkdependencies.properties" topLevelDir="${buildDirectory}/plugins" manifests="${basedir}/dependencyManifests" copyFiles="${copyFiles}"/>
		<replaceregexp file="${buildDirectory}/plugins/org.apache.ant_1.8.3.v20120316-1400/META-INF/MANIFEST.MF" flags="m,g,s">
			<regexp pattern="^Name.*" />
			<substitution expression="" />
		</replaceregexp>
		<replaceregexp file="${buildDirectory}/plugins/org.apache.ant_1.8.3.v20120316-1400/META-INF/MANIFEST.MF" flags="m,g,s">
			<regexp pattern="^SHA1-Digest.*" />
			<substitution expression="" />
		</replaceregexp>
		<replaceregexp file="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/META-INF/MANIFEST.MF" flags="m,g,s">
			<regexp pattern="^Name.*" />
			<substitution expression="" />
		</replaceregexp>
		<replaceregexp file="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/META-INF/MANIFEST.MF" flags="m,g,s">
			<regexp pattern="^SHA1-Digest.*" />
			<substitution expression="" />
		</replaceregexp>
		<replaceregexp file="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/META-INF/MANIFEST.MF" flags="m,g,s">
			<regexp pattern="junit\.jar" />
			<substitution expression="\." />
		</replaceregexp>

		<jar destfile="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100.jar" manifest="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/META-INF/MANIFEST.MF">
			<fileset dir="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/"/>
			<zipfileset src="/usr/share/java/junit.jar"/>
		</jar>

		<delete dir="${buildDirectory}/plugins/org.junit_4.8.2.v4_8_2_v20110321-1705/"/>
		<delete dir="${buildDirectory}/plugins/org.junit_3.8.2.v3_8_2_v20100427-1100/"/>

		<!-- Create a stamp file -->
		<echo file="symlinks-stamp" />
	</target>

	<target name="copyDeps">
	  <antcall target="symlinkDeps">
	    <param name="copyFiles" value="true"/>
	  </antcall>
	</target>

	<target name="build" depends="applyPatches,symlinkDeps,bootstrap,compilelibs" unless="build.complete">

		<echo message="build.xml:  eclipse.pdebuild.scripts = ${eclipse.pdebuild.scripts}" />
		<echo message="${basedir}"/>
		<echo message="${buildConfig}"/>
		<java classname="org.eclipse.equinox.launcher.Main" fork="true" dir="${basedir}" failonerror="true">
			<classpath>
				<pathelement path="bootstrap/plugins/org.eclipse.equinox.launcher.jar" />
			</classpath>
			<arg line="-configuration configuration " />
			<arg line="-application org.eclipse.ant.core.antRunner " />
			<arg line="-buildfile ${eclipse.pdebuild.scripts}/build.xml" />
			<arg line="-propertyfile ${basedir}/build.properties" />
			<arg line="-Dbuilder=${buildConfig} " />
			<arg line="-DbuildDirectory=${buildDirectory} " />
			<!-- Setup this manually -->
			<arg line="-DOSGi/Minimum-1.1=${basedir}/bootstrap/environment/ee.minimum.jar" />
			<arg line="-DdontFetchBinaries=true" />
			<arg line="-consolelog " />
			<jvmarg value="-Xmx512M" />
		</java>



		
		<!-- build equinox initializer -->
		<echo message="build.xml: building equinox initializer"/>
		<mkdir dir="${buildDirectory}/home" />	
		<java classname="org.eclipse.core.launcher.Main" dir="${buildDirectory}/plugins/org.eclipse.equinox.initializer" fork="true">
			<classpath>
				<pathelement path="bootstrap/plugins/org.eclipse.equinox.launcher.jar" />
			</classpath>
			<arg line="-data ${buildworkspace} " />
			<arg line="-Duser.home=${buildDirectory}/home" />
			<arg line="-application org.eclipse.ant.core.antRunner" />
			<arg line="-f build.xml" />
			<arg line="build.update.jar" />
			<jvmarg value="-Xmx512M" />
		</java>

		<!--
		<ant antfile="build.xml" dir="${eclipse.pdebuild.scripts}">
			<property name="arch" value="${buildArch}"/>
			<property name="builder" value="${buildConfig}" />
		</ant>
-->
		<echo file="build-stamp" />
	</target>

	<target name="compile.libgnomeproxy">
		<!-- build libgnomeproxy -->
		<exec dir="${buildDirectory}/plugins/org.eclipse.core.net/natives/unix/linux" executable="make" failonerror="true" />
		<copy file="${buildDirectory}/plugins/org.eclipse.core.net/natives/unix/linux/libgnomeproxy-1.0.0.so" todir="${buildDirectory}/plugins/org.eclipse.core.net.linux.${buildArch}/" />
		<move file="${buildDirectory}/plugins/org.eclipse.core.net/natives/unix/linux/libgnomeproxy-1.0.0.so" todir="${buildDirectory}/plugins/org.eclipse.core.net/fragments/org.eclipse.core.net.linux.${buildArch}/" />
	</target>

	<target name="compilelibs" unless="compilelibs.complete">
		<delete verbose="true">
			<fileset dir="${buildDirectory}/features/org.eclipse.equinox.executable">
				<include name="eclipse" />
			</fileset>
			<fileset dir="${buildDirectory}">
				<include name="**/*.so" />
			</fileset>
		</delete>
		<ant antfile="build.xml" target="build.nativeLibraries" dir="${buildDirectory}/plugins/org.eclipse.swt.gtk.linux.${buildArch}" />

		<property name="launcherlibs" value="${buildDirectory}/features/org.eclipse.equinox.executable" />
		<exec dir="${launcherlibs}/library/gtk/" executable="sh" failonerror="true">
			<arg line="build.sh" />
		</exec>

		<property name="launcherfragment" value="org.eclipse.equinox.launcher.gtk.linux.${buildArch}" />

		<copy file="${launcherlibs}/library/gtk/eclipse" todir="${buildDirectory}/features/org.eclipse.equinox.executable/bin/gtk/linux/${buildArch}/" />
		<copy todir="${buildDirectory}/plugins/${launcherfragment}">
			<fileset dir="${launcherlibs}/library/gtk">
				<include name="**/*.so" />
			</fileset>
		</copy>

		<!-- build liblocalfile -->
		<exec dir="${buildDirectory}/plugins/org.eclipse.core.filesystem/natives/unix/linux" executable="make" failonerror="true" />
		<move file="${buildDirectory}/plugins/org.eclipse.core.filesystem/natives/unix/linux/libunixfile_1_0_0.so" todir="${buildDirectory}/plugins/org.eclipse.core.filesystem.linux.${buildArch}/os/linux/${buildArch}">
		</move>
		<!-- build libgnomeproxy -->
		<antcall target="compile.libgnomeproxy" />
		<!-- build libupdate -->
		<ant dir="${buildDirectory}/plugins/org.eclipse.update.core.linux/src" antfile="build.xml" />

		<echo file="compilelibs-stamp" />
	</target>

	<target name="p2prep" depends="build" unless="p2prep.complete">
		<!-- archiveName is set in the build config's customTargets.xml -->
		<!-- FIXME buildLabel should be used here but it's not defined so we cheat and use I.${buildId} instead. -->
		<property name="builtZip" value="${buildDirectory}/I.${buildId}/eclipse-SDK-${buildId}.zip" />
		<!--<property name="builtZip" value="${basedir}/eclipse-SDK-${buildId}.zip"/>-->
		<replace token="@qualifier@" file="${productFiles}/sdk/sdk.product" value="${buildId}" />
		<replace token="@qualifier@" file="${productFiles}/platform/platform.product" value="${buildId}" />
		<property name="tempexec" value="${buildDirectory}/tempexec" />

		<antcall target="createRepo" />
		<antcall target="extractLauncher" />
		<antcall target="publishLauncher" />
		<antcall target="createAndPublishLauncherFeature" />
		<antcall target="publishSDK" />
		<antcall target="publishPlatform" />

		<echo file="p2prep-stamp" />
	</target>

	<target name="createRepo">
		<delete dir="${reposource}" />
		<mkdir dir="${reposource}" />
		<echo message="Unzipping ${builtZip} into ${reposource}" />
		<unzip dest="${reposource}" src="${builtZip}" />
	</target>

	<target name="extractLauncher">
		<delete dir="${tempexec}" />
		<mkdir dir="${tempexec}" />

		<copy todir="${tempexec}">
			<fileset dir="${reposource}">
				<include name="features/org.eclipse.equinox.executable_*.jar" />
			</fileset>
		</copy>
		<unzip dest="${tempexec}">
			<fileset dir="${tempexec}/features">
				<include name="*.jar" />
			</fileset>
		</unzip>
	</target>

	<target name="publishLauncher">
		<!-- Do we need a full path for ${reposource}?
		<property name="buildDirectoryAbsoluteTemp" value="${buildDirectory}/absolutetemp.txt" />
		<echo message="${reposource}" file="${buildDirectoryAbsoluteTemp}" />
		<replaceregexp file="${buildDirectoryAbsoluteTemp}" match="org.eclipse.releng.eclipsebuilder/../src/" replace="src/" />
		<loadfile property="buildDirectoryAbsolute" srcFile="${buildDirectoryAbsoluteTemp}" failonerror="false" />
		<delete file="${buildDirectoryAbsoluteTemp}" />
		-->

		<!-- This next part merges metadata for the launcher binary into the rest of the metadata -->
		<java classname="org.eclipse.equinox.launcher.Main" fork="true" dir="${basedir}" failonerror="true">
			<classpath>
				<pathelement path="bootstrap/plugins/org.eclipse.equinox.launcher.jar" />
			</classpath>
			<arg line="-configuration configuration " />
			<arg line="-application org.eclipse.ant.core.antRunner " />
			<arg line="-buildfile ${tempexec}/build.xml" />
			<arg line="-propertyfile ${basedir}/build.properties " />
			<arg line="-Dbuilder=${buildConfig} " />
			<arg line="-DbuildDirectory=${buildDirectory} " />
			<arg line="-Dp2.gathering=true " />
			<arg line="-Dp2.build.repo=file:/${reposource} " />
			<arg line="-consolelog " />
			<arg line="publish.bin.parts " />
			<jvmarg value="-Xmx512M" />
		</java>
	</target>

	<target name="createAndPublishLauncherFeature">
		<!--
			<jvmarg value="-Xdebug"/>
			<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=40000"/>

			<jvmarg value="-Xdebug"/>
			<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=40001"/>
		-->

		<!-- This next part creates and publishs a feature including the binary launcher -->
		<java classname="org.eclipse.equinox.launcher.Main" fork="true" dir="${productFiles}/rcpConfig" failonerror="true">
			<classpath>
				<pathelement path="bootstrap/plugins/org.eclipse.equinox.launcher.jar" />
			</classpath>
			<arg line="-configuration configuration " />
			<arg line="-application org.eclipse.ant.core.antRunner " />
			<arg line="-buildfile buildConfiguration.xml" />
			<arg line="-propertyfile ${basedir}/build.properties " />
			<arg line="-Dconfigs=linux,gtk,${buildArch} " />
			<arg line="-Dreposource=${reposource} " />
			<arg line="-Dbasedir=${productFiles}/rcpConfig" />
			<arg line="-DbuildId=${buildId} " />
			<arg line="-DbaseBuildPath=${buildDirectory} " />
			<arg line="-DbaseLocation=${buildDirectory} " />
			<arg line="-Declipse.pdebuild.scripts=${eclipse.pdebuild.scripts} " />
			<arg line="-consolelog " />
			<jvmarg value="-Xmx512M" />
		</java>

		<!--
		<ant target="main" antfile="buildConfiguration.xml" dir="${productFiles}/rcpConfig" />
		-->
	</target>

	<target name="publishPlatform">
		<antcall target="publishProduct">
			<param name="productFile" value="${productFiles}/platform/platform.product" />
		</antcall>
	</target>

	<target name="publishSDK">
		<antcall target="publishProduct">
			<param name="productFile" value="${productFiles}/sdk/sdk.product" />
		</antcall>
	</target>

	<target name="publishProduct">
		<!-- http://wiki.eclipse.org/Equinox/p2/Publisher -->
		<java classname="org.eclipse.equinox.launcher.Main" fork="true" dir="${basedir}" failonerror="true">
			<classpath>
				<pathelement path="${launcher}" />
			</classpath>
			<arg line="-configuration configuration " />
			<arg line="-application org.eclipse.ant.core.antRunner " />
			<arg line="-buildfile publishProduct.xml" />
			<arg line="-propertyfile ${basedir}/build.properties " />
			<arg line="-DbuildArch=${buildArch} " />
			<arg line="-Dreposource=${reposource} " />
			<arg line="-DbuildConfig=${buildConfig} " />
			<arg line="-DproductFile=${productFile} " />
			<arg line="-DbuildDirectory=${buildDirectory} " />
			<arg line="-consolelog " />
			<jvmarg value="-Xmx512M" />
		</java>
		<!-- The following (using the app. instead of the ant task) doesn't work
		     as of 2010-08-11 -->
		<!--
		<java classname="org.eclipse.equinox.launcher.Main" fork="true" dir="${basedir}" failonerror="true">
			<classpath>
				<pathelement path="bootstrap/plugins/org.eclipse.equinox.launcher.jar" />
			</classpath>
			<arg line="-configuration configuration " />
		                 <arg line="-consoleLog" />
			<arg line="-application org.eclipse.equinox.p2.publisher.ProductPublisher " />
		                 <arg line="-flavor tooling" />
		                 <arg line="-configs gtk.linux.${buildArch}" />
		                 <arg line="-productFile ${productFile}" />
		                 <arg line="-metadataRepository file:${reposource}" />
		                 <arg line="-artifactRepository file:${reposource}" />
		                 <arg line="-compress" />
			<arg line="-featureVersions ${buildDirectory}/finalFeaturesVersions.properties" />
		                 <arg line="-pluginVersions ${buildDirectory}/finalPluginsVersions.properties" />
		</java>
		-->
	</target>

	<target name="provision.platform" depends="p2prep" unless="provision.platform.complete">
		<echo message="Installing into:  ${provisionDir}" />
		<antcall target="provision">
			<param name="p2.director.installIU" value="org.eclipse.platform.ide" />
			<param name="profileName" value="PlatformProfile" />
		</antcall>

		<!-- Re-symlink system JARs -->
		<symlinkInstalledOSGiJars dependencies="${basedir}/dependencies/dependencies.properties" topLevelDir="${provisionDir}/plugins" />
		<symlinkNonOSGiJars dependencies="${basedir}/dependencies/nonosgidependencies.properties" topLevelDir="${provisionDir}/plugins" />
		<echo file="provision.platform-stamp" />
	</target>

	<!-- This is here as a convenience task for distributions which want
	     CVS functionality to be present in "platform" installations. -->
	<target name="provision.cvs" depends="p2prep" unless="provision.cvs.complete">
		<echo message="Installing into:  ${provisionDir}" />
		<antcall target="provision">
			<param name="p2.director.installIU" value="org.eclipse.platform.ide,org.eclipse.cvs.feature.group,org.eclipse.equinox.initializer" />
			<param name="profileName" value="PlatformProfile" />
		</antcall>

		<!-- Re-symlink system JARs -->
		<symlinkInstalledOSGiJars dependencies="${basedir}/dependencies/dependencies.properties" topLevelDir="${provisionDir}/plugins" />
		<symlinkNonOSGiJars dependencies="${basedir}/dependencies/nonosgidependencies.properties" topLevelDir="${provisionDir}/plugins" />
		<echo file="provision.cvs-stamp" />
	</target>

	<target name="provision" depends="p2prep">
		<echo message="Installing into:  ${provisionDir}" />
		<antcall target="run.director">
			<param name="p2.director.installIU" value="${p2.director.installIU}" />
			<param name="p2.director.version" value="${p2.director.version}" />
			<param name="p2.director.profile" value="${profileName}" />
			<param name="p2.director.install.path" value="${provisionDir}" />
			<param name="p2.director.extraArgs" value="-profileProperties org.eclipse.update.install.features=true" />
			<param name="p2.os" value="linux" />
			<param name="p2.ws" value="gtk" />
			<param name="p2.arch" value="${buildArch}" />
			<param name="p2.repo" value="${reposource}" />
		</antcall>
	</target>

	<target name="provision.installed" depends="p2prep">
		<echo message="Installing into:  ${provisionDir}" />
		<property name="directorToRun" value="${provisionDir}/eclipse" />
		<antcall target="run.installed.director">
			<param name="p2.director.installIU" value="${p2.director.installIU}" />
			<param name="p2.director.version" value="${p2.director.version}" />
			<param name="p2.director.profile" value="${profileName}" />
			<param name="p2.director.install.path" value="${provisionDir}" />
			<param name="p2.director.extraArgs" value="-profileProperties org.eclipse.update.install.features=true" />
			<param name="p2.os" value="linux" />
			<param name="p2.ws" value="gtk" />
			<param name="p2.arch" value="${buildArch}" />
			<param name="p2.repo" value="${reposource}" />
		</antcall>
	</target>

	<target name="run.director">
		<property name="baseBuilderConfig" value="${baseBuilder}/p2" />
		<!-- FIXME:  When we move to bootstrap by default, investigate using <exec> on the bootstrapped launcher
		     like in eclipsebuilder's equinox.prov/run.xml -->
		<java classname="org.eclipse.equinox.launcher.Main" fork="true" dir="${baseBuilder}" failonerror="true">
			<classpath>
				<pathelement location="${launcher}" />
			</classpath>
			<arg line="-data ${buildworkspace} " />
			<arg line="-application org.eclipse.equinox.p2.director " />
			<arg line="-consoleLog" />
			<!--<arg line="-help" />-->
			<arg line="-flavor ${p2.flavor}" />
			<arg line="-installIU ${p2.director.installIU}" />
			<arg line="-p2.os ${p2.os}" />
			<arg line="-p2.ws ${p2.ws}" />
			<arg line="-p2.arch ${p2.arch}" />
			<arg line="-roaming" />
			<arg line="-profile ${p2.director.profile}" />
			<arg line="${p2.director.extraArgs}" />
			<arg line="-metadatarepository file:${p2.repo}" />
			<arg line="-artifactrepository file:${p2.repo}" />
			<arg line="-destination ${p2.director.install.path}" />
			<arg line="-bundlepool ${p2.director.install.path}" />
			<arg line="-vmargs" />
			<arg line="-Declipse.p2.data.area=${p2.director.install.path}/p2" />
			<arg line="-Declipse.p2.MD5Check=false" />
			<arg line="-Declipse.p2.profile=@none" />
			<arg line="-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=" />
			<arg line="-propertyfile ${basedir}/build.properties " />
			<!--
			<jvmarg value="-Xms512M" />
			<jvmarg value="-Xmx2048M" />
			<jvmarg value="-XX:MaxPermSize=512M" />
			-->
			<jvmarg value="-Declipse.p2.data.area=${p2.director.install.path}/p2" />
			<jvmarg value="-Xmx512M" />
		</java>
	</target>

	<target name="run.installed.director">
		<chmod perm="ugo+rx" file="${directorToRun}" />
		<exec executable="${directorToRun}" failonerror="true">
			<arg line="-nosplash " />
			<arg line="-consoleLog" />
			<arg line="-data ${buildworkspace} " />
			<arg line="-application org.eclipse.equinox.p2.director " />
			<arg line="-flavor ${p2.flavor}" />
			<arg line="-installIU ${p2.director.installIU}" />
			<arg line="-profile ${p2.director.profile}" />
			<arg line="-destination ${p2.director.install.path}" />
			<arg line="-p2.os ${p2.os}" />
			<arg line="-p2.ws ${p2.ws}" />
			<arg line="-p2.arch ${p2.arch}" />
			<arg line="${p2.director.extraArgs}" />
			<arg line="-metadatarepository file:${p2.repo}" />
			<arg line="-artifactrepository file:${p2.repo}" />
		</exec>
	</target>

	<target name="run.installed.director.uninstall">
                <chmod perm="ugo+rx" file="${directorToRun}" />
                <exec executable="${directorToRun}" failonerror="true">
                        <arg line="-nosplash " />
                        <arg line="-consoleLog" />
                        <arg line="-data ${buildworkspace} " />
                        <arg line="-application org.eclipse.equinox.p2.director " />
                        <arg line="-flavor ${p2.flavor}" />
                        <arg line="-uninstallIU ${p2.director.uninstallIU}" />
                        <arg line="-profile ${p2.director.profile}" />
                       	<arg line="-destination ${p2.director.install.path}" />
                        <arg line="-p2.os ${p2.os}" />
                        <arg line="-p2.ws ${p2.ws}" />
                        <arg line="-p2.arch ${p2.arch}" />
                        <arg line="${p2.director.extraArgs}" />
                        <arg line="-metadatarepository file:${p2.repo}" />
                        <arg line="-artifactrepository file:${p2.repo}" />
                </exec>
        </target>

	<target name="installSDKinDropins" depends="provisionSDKinDropins">
		<antcall target="installIntoDestDir">
			<param name="profile" value="PlatformProfile" />
		</antcall>
	</target>

	<target name="extractSos" unless="dontExtractSos">
	  <java classname="org.eclipse.core.launcher.Main" fork="true" failonerror="true" dir="${destDir}">
	    <classpath>
	      <fileset dir="${installationDir}/plugins">
		<include name="org.eclipse.equinox.launcher_*.jar" />
	      </fileset>
	    </classpath>
	    <arg value="-application" />
	    <arg value="org.eclipse.equinox.initializer.configInitializer" />
	    <arg value="-debug" />
	    <arg value="-consolelog" />
	    <arg value="-metadataRepository" />
	    <arg value="file:${installationDir}/metadata/" />
	    <arg value="-artifactRepository" />
	    <arg value="file:${installationDir}/metadata/" />
	    <arg value="-data" />
	    <arg value="${buildworkspace}" />
	    <arg value="-fileInitializer" />
	    <arg value="${basedir}/extract_patterns.txt" />
	    <jvmarg value="-Dosgi.sharedConfiguration.area=${installationDir}/configuration" />
	  </java>
	</target>

	<target name="installIntoDestDir">
		<mkdir dir="${installationDir}" />
                <exec executable="rsync" failonerror="true">
                       <arg value="-vrpl" />
                       <arg value="--exclude=dropins" />
                       <arg value="${provisionDir}/" />
                       <arg value="${installationDir}/" />
                </exec>

		<!-- install desktop file -->
		<copy file="eclipse.desktop" todir="${destDir}${prefix}/share/applications" />
		<!-- install Eclipse Java code formatter launcher -->
		<property name="efj" value="${destDir}${prefix}/bin/efj"/>
		<copy file="efj.sh" tofile="${efj}" />
	    <fileset id="equinoxLauncher" dir="${installationDir}/plugins">
	      <include name="org.eclipse.equinox.launcher_*.jar" />
	    </fileset>
	    <property name="launcherJar" refid="equinoxLauncher"/>
		<replace file="${efj}" token="@LAUNCHER@" value="${prefix}/${libDir}/eclipse/plugins/${launcherJar}"/>
		<!-- install icons -->
		<copy file="${buildDirectory}/plugins/org.eclipse.platform/eclipse.png" tofile="${destDir}${prefix}/share/icons/hicolor/16x16/apps/eclipse.png" />
		<copy file="${buildDirectory}/plugins/org.eclipse.platform/eclipse32.png" tofile="${destDir}${prefix}/share/icons/hicolor/32x32/apps/eclipse.png" />
		<copy file="${buildDirectory}/plugins/org.eclipse.platform/eclipse48.png" tofile="${destDir}${prefix}/share/icons/hicolor/48x48/apps/eclipse.png" />
		<mkdir dir="${destDir}${prefix}/share/pixmaps" />
		<symlink link="${destDir}${prefix}/share/pixmaps/eclipse.png" resource="../icons/hicolor/48x48/apps/eclipse.png" overwrite="true"/>
		<!--shared dropins folder for architecture-independent plugins-->
		<mkdir dir="${destDir}${prefix}/share/eclipse/dropins" />
		<!-- eclipse binary -->
		<mkdir dir="${destDir}${prefix}/bin" />
		<symlink link="${destDir}${prefix}/bin/eclipse" resource="../${libDir}/eclipse/eclipse" overwrite="true"/>
		<!-- Create the "swt.jar" and friends symlinks  -->
		<fileset dir="${installationDir}/plugins" includes="org.eclipse.swt.gtk.linux.${buildArch}_*" id="swtjar" />
		<property name="swtjarpath" refid="swtjar" />
		<symlink link="${installationDir}/swt-gtk-${label}.jar" resource="plugins/${swtjarpath}" overwrite="true"/>
		<symlink link="${installationDir}/swt-gtk.jar" resource="plugins/${swtjarpath}" overwrite="true"/>
		<symlink link="${installationDir}/swt.jar" resource="plugins/${swtjarpath}" overwrite="true"/>

		<echo append="true" file="${installationDir}/eclipse.ini" message="-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${prefix}/share/eclipse/dropins" />

		<!-- Extract SWT JNI .so files -->
		<antcall target="extractSos">
		</antcall>

		<!-- remove the initializer -->
		<property name="directorToRun" value="${installationDir}/eclipse" />
                <antcall target="run.installed.director.uninstall">
                        <param name="p2.director.uninstallIU" value="org.eclipse.equinox.initializer" />
                        <param name="p2.director.profile" value="PlatformProfile" />
                        <param name="p2.director.install.path" value="${installationDir}" />
                        <param name="p2.director.extraArgs" value="-purgeHistory" />
			<param name="p2.os" value="linux" />
                        <param name="p2.ws" value="gtk" />
                        <param name="p2.arch" value="${buildArch}" />
                        <param name="p2.repo" value="${installationDir}" />
                </antcall>

		<!-- copy PDE and JDT to dropins -->
                <exec executable="rsync" failonerror="true">
                       <arg value="-vrpl" />
                       <arg value="${provisionDir}/dropins/" />
                       <arg value="${installationDir}/dropins/" />
                </exec>

		<!-- Remove unnecessary configuration data -->
		<delete dir="${installationDir}/configuration/org.eclipse.core.runtime" />
		<delete dir="${installationDir}/configuration/org.eclipse.equinox.app" />
		<delete includeemptydirs="true" verbose="true">
			<fileset dir="${installationDir}/configuration" includes="*.log" />
			<fileset dir="${installationDir}/configuration" includes="**/data/**" />
			<fileset dir="${installationDir}/configuration" includes="org.eclipse.update/**" />
		</delete>
		
		<!-- Fix paths in p2 data -->
		<delete includeemptydirs="true" failonerror="false">
			<fileset dir="${installationDir}/p2/org.eclipse.equinox.p2.core" includes="cache/**" />
		</delete>

		<property name="profileDir" value="p2/org.eclipse.equinox.p2.engine/profileRegistry/${profile}.profile" />
		
		<!-- Strip some build artifacts from installation -->
		<exec executable="sed" inputstring="${destDir}" outputproperty="destDirWithUnderscores" failonerror="true">
			<arg value="s@/@_@g" />
		</exec>

		<exec executable="sed" inputstring="${reposource}" outputproperty="reposourceWithUnderscores" failonerror="true">
			<arg value="s@/@_@g" />
		</exec>
		<exec executable="sed" inputstring="${provisionDir}" outputproperty="provisionDirWithUnderscores" failonerror="true">
			<arg value="s@/@_@g" />
		</exec>
		<apply executable="sed" failonerror="true" verbose="true">
			<arg value="-i" />
			<arg value="\@${destDir}@d;\@${destDirWithUnderscores}@d;\@${reposourceWithUnderscores}@d;\@${provisionDirWithUnderscores}@d" />
			<srcfile />
			<fileset dir="${installationDir}">
				<include name="metadata/content.xml" />
				<include name="p2/org.eclipse.equinox.p2.engine/.settings/org.eclipse.equinox.p2.metadata.repository.prefs" />
				<include name="p2/org.eclipse.equinox.p2.engine/.settings/org.eclipse.equinox.p2.artifact.repository.prefs" />
				<include name="${profileDir}/.data/.settings/org.eclipse.equinox.p2.metadata.repository.prefs" />
				<include name="${profileDir}/.data/.settings/org.eclipse.equinox.p2.artifact.repository.prefs" />
				<include name="eclipse.ini" />
			</fileset>
		</apply>

		<!-- Clean up profile files -->
		<echo message="${provisionDir}"/>
		<apply executable="gunzip" failonerror="true" verbose="true">
			<srcfile />
			<fileset dir="${installationDir}/${profileDir}">
				<include name="*.gz" />
			</fileset>
		</apply>
		<apply executable="sed" failonerror="true" verbose="true">
			<arg value="-i" />
			<arg value="s@${provisionDir}@${installationDir}@g;s@${installationDir}@${prefix}/${libDir}/eclipse@g" />
			<srcfile />
			<fileset dir="${installationDir}/${profileDir}">
				<include name="*.profile" />
			</fileset>
		</apply>
		<apply executable="gzip" failonerror="true" verbose="true">
			<srcfile />
			<fileset dir="${installationDir}/${profileDir}">
				<include name="*.profile" />
			</fileset>
		</apply>
		
		<!-- Move config file to /etc -->
		<mkdir dir="${destDir}/etc" />
		<move file="${installationDir}/eclipse.ini" tofile="${destDir}/etc/eclipse.ini" />
		<symlink link="${installationDir}/eclipse.ini" resource="/etc/eclipse.ini" overwrite="true"/>

	</target>

	<target name="provisionSDKinDropins" depends="provision.cvs" unless="provisionSDKinDropins.complete" >
		<property name="platformAndCVSInstallation" value="${provisionDir}.cvs"/>
		
		<property name="jdtDropinsName" value="jdt"/>
		<property name="sdkDropinsName" value="sdk"/>

		<property name="jdtDropinsDir" value="${provisionDir}/dropins/${jdtDropinsName}"/>
		<property name="sdkDropinsDir" value="${provisionDir}/dropins/${sdkDropinsName}"/>

		<!-- make a copy of the clean platform+CVS installation -->
		<exec executable="cp" failonerror="true">
			<arg value="-rd" />
			<arg value="--no-target-directory" />
			<arg value="${provisionDir}" />
			<arg value="${platformAndCVSInstallation}" />
		</exec>

		<!-- Install JDT -->
		<property name="jdtInstallation" value="${provisionDir}.jdt"/>
		<antcall target="provision.installed">
			<param name="p2.director.installIU" value="org.eclipse.jdt.feature.group" />
			<param name="profileName" value="PlatformProfile" />
		</antcall>
		<!-- rename the JDT installation -->
		<move file="${provisionDir}"
			tofile="${jdtInstallation}"/>
		<!-- make a second copy of the clean JDT installation -->
		<exec executable="cp" failonerror="true">
			<arg value="-rd" />
			<arg value="--no-target-directory" />
			<arg value="${jdtInstallation}" />
			<arg value="${jdtInstallation}.orig" />
		</exec>
		
		<!-- restore clean platform+CVS installation -->
		<exec executable="cp" failonerror="true">
			<arg value="-rd" />
			<arg value="--no-target-directory" />
			<arg value="${platformAndCVSInstallation}" />
			<arg value="${provisionDir}" />
		</exec>
		
		<!-- Install SDK -->
		<property name="sdkInstallation" value="${provisionDir}.sdk"/>
		<antcall target="provision.installed">
			<param name="p2.director.installIU" value="org.eclipse.sdk.feature.group,org.eclipse.license.feature.group" />
			<param name="profileName" value="PlatformProfile" />
		</antcall>
		<!-- rename the entire SDK installation -->
		<move file="${provisionDir}"
			tofile="${sdkInstallation}"/>
		
		<!-- restore clean platform+CVS installation -->
		<exec executable="cp" failonerror="true">
			<arg value="-rd" />
			<arg value="--no-target-directory" />
			<arg value="${platformAndCVSInstallation}" />
			<arg value="${provisionDir}" />
		</exec>
		
		<!-- diff of platform+CVS and JDT goes into platform+CVS/dropins/jdt -->
		<antcall target="moveNewStuffToDropins">
			<param name="orig" value="${provisionDir}" />
			<param name="new" value="${jdtInstallation}" />
			<param name="dropinsDir" value="${jdtDropinsName}" />
		</antcall>
		
		<!-- restore clean JDT installation for comparison -->
		<delete dir="${jdtInstallation}" />
		<move file="${jdtInstallation}.orig"
			tofile="${jdtInstallation}"/>
		
		<!-- diff of JDT and SDK ... -->
		<antcall target="moveNewStuffToDropins">
			<param name="orig" value="${jdtInstallation}" />
			<param name="new" value="${sdkInstallation}" />
			<param name="dropinsDir" value="${sdkDropinsName}" />
		</antcall>
		<!-- ... goes into platform+CVS/dropins/pde -->
		<move file="${jdtInstallation}/dropins/${sdkDropinsName}"
			todir="${provisionDir}/dropins"/>
		
		<!-- Re-symlink system JARs -->
		<fileset id="junit4.jar" dir="${jdtDropinsDir}/plugins">
			<include name="**/org.junit4_**/junit.jar" />
		</fileset>
		<property name="junit4jar.path" refid="junit4.jar" />

		<delete file="${jdtDropinsDir}/plugins/${junit4jar.path}" />
		<symlink link="${jdtDropinsDir}/plugins/${junit4jar.path}" resource="${junit4JarLocation}" />

		<symlinkInstalledOSGiJars dependencies="${basedir}/dependencies/dependencies.properties" topLevelDir="${provisionDir}/plugins" />
		<symlinkNonOSGiJars dependencies="${basedir}/dependencies/nonosgidependencies.properties" topLevelDir="${provisionDir}/plugins" />
		
		<symlinkInstalledOSGiJars dependencies="${basedir}/dependencies/jdtdependencies.properties" topLevelDir="${jdtDropinsDir}/plugins" />
		<symlinkNonOSGiJars dependencies="${basedir}/dependencies/jdtnonosgidependencies.properties" topLevelDir="${jdtDropinsDir}/plugins" />
		
		<symlinkInstalledOSGiJars dependencies="${basedir}/dependencies/sdkdependencies.properties" topLevelDir="${sdkDropinsDir}/plugins" />
		
		<delete dir="${platformAndCVSInstallation}" />
		<delete dir="${jdtInstallation}" />
		<delete dir="${sdkInstallation}" />

		<echo file="provisionSDKinDropins-stamp" />
	</target>

	<target name="moveNewStuffToDropins">
		<property name="dropinsDirectory" value="${orig}/dropins/${dropinsDir}" />		
                <move todir="${dropinsDirectory}/features" includeemptydirs="true">
                        <fileset dir="${new}/features" id="newFeatures.fileset">
                                <present present="srconly" targetdir="${orig}/features"/>
                        </fileset>
                </move>
		<move todir="${dropinsDirectory}/plugins" includeemptydirs="true">
			<fileset dir="${new}/plugins" id="newPlugins.fileset">
				<present present="srconly" targetdir="${orig}/plugins"/>
			</fileset>
		</move>
	</target>

	<target name="package.extract.swt">
		<exec executable="./swt_bundle.sh" failOnError="true">
			<arg value="${eclipse.rcp.package.root}" />
			<arg value="${eclipse.swt.package.root}" />
			<arg value="${prefix}" />
			<arg value="${libdir}" />
		</exec>
	</target>

</project>
