<project default="run">
	<target name="init">

		<echo message="Set compilerArgs = '-enableJavadoc -encoding ISO-8859-1 -warn:-serial,nls,unused,unchecked,raw'"/>
		<property name="compilerArg" value="-enableJavadoc -encoding ISO-8859-1 -warn:-serial,nls,unused,unchecked,raw" />

		<!-- TODO: set correct source and target levels here -->
		<echo message="Set javacSource and javacTarget = 1.4"/>
		<property name="javacSource" value="1.4" />
		<property name="javacTarget" value="1.4" />
		
		<path id="bc">
			<fileset dir="${java.home}/lib">
				<include name="*.jar" />
			</fileset>
		</path>
		<property name="bootclasspath" refid="bc" />

		<!-- TODO: if using JDK1.4, comment out these lines -->
		<!--
		<echo message="Set J2SE-1.5 = ${bootclasspath}"/>
		<property name="J2SE-1.5" value="${bootclasspath}"/>
		<condition property="bundleBootClasspath" value="${J2SE-1.5}"><isset property="J2SE-1.5"/></condition>
		<condition property="bundleJavacSource" value="1.5"><isset property="J2SE-1.5"/></condition>
		<condition property="bundleJavacTarget" value="1.5"><isset property="J2SE-1.5"/></condition>
		-->
		
		<property name="buildingOSGi" value="true" />
		<property name="collectingFolder" value="eclipse" />
		<property name="archivePrefix" value="eclipse" />

		<!-- Reduce the amount of info in the build log -->
		<property name="javacVerbose" value="false" />

		<property name="buildDirectory" location="${basedir}/../src/eclipse" />
		<property file="${basedir}/repoInfo.properties" />
		<property name="testBase" location="${buildDirectory}/../testing" />
		<available file="${buildDirectory}/label.properties" property="label.properties.exists" />
		<antcall target="create.label.properties" />
		<property file="${buildDirectory}/label.properties" />
		
		<echo message="buildAll.xml properties:"/>
		<echo message="basedir = ${basedir}"/>

		<!-- load a value for ${subprojectName}, among other variables, from build.cfg -->
		<property name="buildConfigFile" value="${basedir}/../build.cfg"/>
		<available file="${buildConfigFile}" type="file" property="buildConfigIsAvailable" />
		<fail message="Can't load build properties from ${buildConfigFile}" unless="buildConfigIsAvailable"/>
		<!-- TODO: set any special build-related properties here by echoing them into ${buildConfigFile}:
		<echo file="${buildConfigFile}" append="true">

# extra properties specific to just this build
propertyName=propertyValue
</echo>	-->

		<property file="${buildConfigFile}" />

		<echo message="buildVer = ${buildVer}"/>
		<echo message="subprojectName = ${subprojectName}"/>

		<!-- <echo message="Base OS: ${baseos}; Base Window System: ${basews}"/> -->
		<condition property="isWindows">
			<equals arg1="${baseos}.${basews}" arg2="win32.win32" />
		</condition>
		<condition property="isLinuxGTK">
			<equals arg1="${baseos}.${basews}" arg2="linux.gtk" />
		</condition>
		<condition property="isLinuxMotif">
			<equals arg1="${baseos}.${basews}" arg2="linux.motif" />
		</condition>

	</target>

	<target name="create.label.properties" unless="label.properties.exists">
		<mkdir dir="${buildDirectory}" />
		<tstamp />
		<property name="date" value="${DSTAMP}" />
		<property name="time" value="${TSTAMP}" />
		<property name="timestamp" value="${date}${time}" />
		<property name="buildType" value="I" />

		<!--this naming convention used by php scripts on download server-->
		<property name="buildLabel" value="${buildType}${timestamp}" />

		<property name="buildAlias" value="${buildLabel}" />
		<property name="buildId" value="${buildAlias}" />
		<!-- <property name="forceContextQualifier" value="v${timestamp}"/> -->

		<!--store the build label information in a file-->
		<echo file="${buildDirectory}/label.properties" append="true" >
		buildType=${buildType}
		</echo>
		<echo file="${buildDirectory}/label.properties" append="true">
		buildId=${buildId}
		</echo>
		<echo file="${buildDirectory}/label.properties" append="true">
		timestamp=${timestamp}
		</echo>
		<echo file="${buildDirectory}/label.properties" append="true">
		buildLabel=${buildLabel}
		</echo>
		<echo file="${buildDirectory}/label.properties" append="true">
		buildAlias=${buildAlias}
		</echo>
		<!--
		<echo file="${buildDirectory}/label.properties" append="true" >
		forceContextQualifier=${forceContextQualifier}
		</echo>
		-->
	</target>

	<target name="run" depends="init">
		<antcall target="buildAll" />
		<antcall target="test" />
		<antcall target="publish" />
		<antcall target="cleanUp" />
	</target>

	<target name="runTestsOnly" depends="init">
		<delete dir="${buildDirectory}" />
		<mkdir dir="${buildDirectory}/${buildLabel}" />
		<copy todir="${buildDirectory}/${buildLabel}">
			<fileset dir="${buildDirectory}/..">
				<include name="**/*.zip" />
			</fileset>
		</copy>
		<antcall target="test" />
		<antcall target="publish" />
		<antcall target="cleanUp" />
	</target>

	<target name="runWithoutTest" depends="init">
		<antcall target="buildAll" />
		<antcall target="publish" />
		<antcall target="cleanUp" />
	</target>

	<target name="buildOnly" depends="init">
		<antcall target="buildAll" />
		<antcall target="cleanUp" />
	</target>

	<target name="buildAll">
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/terminal" />
		</ant>
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/sdk" />
		</ant>
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/runtime" />
		</ant>
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/examples" />
		</ant>
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/discovery" />
		</ant>
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/tests" />
		</ant>

		<!-- doc must be the last execution -->
		<!-- we dont have a separate doc feature for TM/RSE, so leave that out for now
		<ant antfile="build.xml" target="main">
			<property name="component" value="builder/doc" />
		</ant>
		-->

		<!-- TODO: if necessary, you can copy files from the SDK into the runtime or examples zips here  -->
		<!-- for example, see validation/buildAll.xml or cdo/buildAll.xml -->
			
		<!-- TODO: if necessary, you can remove 3rd party jars used at build time from the zips here -->
		<!-- for example, see cdo's buildAll.xml -->

		<!-- TODO: you can run extra build scripts here, like for building additional zip bundles -->
			
		<!-- md5 files generation -->
		<exec executable="bash" dir="${buildDirectory}/${buildLabel}">
			<arg line="${basedir}/../org.eclipse.modeling.common.releng/scripts/createZipCheckSum.sh" />
		</exec>
	</target>

	<target name="cleanUp">
		<echo message="** Copying generated zips to drop folder... **" />
		<copy todir="${buildDirectory}/.." failonerror="false" overwrite="true">
			<fileset dir="${buildDirectory}/${buildLabel}" />
		</copy>
	</target>

	<target name="test">
		
		<property name="test.xml" value="../org.eclipse.releng.basebuilder/plugins/org.eclipse.build.tools/scripts/test.xml" />
		<antcall target="test-win32-local" />
		<antcall target="test-linux-gtk-local" />
		<antcall target="test-linux-motif-local" />
	</target>

	<target name="test-win32-local" if="isWindows">
		<ant antfile="${test.xml}">
			<property name="shell" value="relengbuildwin2.bat" />
			<property name="tester" value="${basedir}/builder/tests/configs/local" />
		</ant>
	</target>

	<target name="test-linux-gtk-local" if="isLinuxGTK">
		<ant antfile="${test.xml}">
			<property name="shell" value="relengbuildgtk.sh" />
			<property name="tester" value="${basedir}/builder/tests/configs/local" />
		</ant>
	</target>

	<target name="test-linux-motif-local" if="isLinuxMotif">
		<ant antfile="${test.xml}">
			<property name="shell" value="relengbuildmotif.sh" />
			<property name="tester" value="${basedir}/builder/tests/configs/local" />
		</ant>
	</target>

	<target name="publish">
		<copy todir="${buildDirectory}/${buildLabel}" overwrite="true">
			<fileset
				dir="${buildDirectory}/../org.eclipse.modeling.common.releng/staticDropFiles" />
		</copy>
	</target>
	
</project>
