<?xml version="1.0" encoding="UTF-8"?>
<project name="com.nokia.s60tools.imaker.tests" default="build.jars" basedir=".">
	<property file="../common.properties"/>

	<property name="basews" value="${ws}"/>
	<property name="baseos" value="${os}"/>
	<property name="basearch" value="${arch}"/>
	<property name="basenl" value="${nl}"/>
	<property name="bundleId" value="com.nokia.s60tools.imaker.tests"/>

	<!-- Compiler settings. -->
	<property name="javacFailOnError" value="true"/>
	<property name="logExtension" value=".log"/>
	<property name="compilerArg" value=""/>

	<target name="init" depends="properties">
		<property name="pluginTemp" value="${basedir}"/>
		<property name="build.result.folder" value="${basedir}"/>
		<property name="temp.folder" value="${basedir}/temp.folder"/>
		<property name="plugin.destination" value="${basedir}"/>
	</target>

	<target name="properties" if="eclipse.running">
		<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>

	</target>

	<target name="build.update.jar" depends="init" description="Build the plug-in: com.nokia.s60tools.imaker.tests for an update site.">
		<delete dir="${temp.folder}"/>
		<mkdir dir="${temp.folder}"/>
		<antcall target="build.jars"/>
		<antcall target="gather.bin.parts">
			<param name="destination.temp.folder" value="${temp.folder}/"/>
		</antcall>
		<jar destfile="${plugin.destination}/com.nokia.s60tools.imaker.tests_${plugin.version}.jar" basedir="${temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}" filesetmanifest="merge"/>
		<copy todir="../${plugin.lib}" file="${plugin.destination}/com.nokia.s60tools.imaker.tests_${plugin.version}.jar" failonerror="true" overwrite="true" />
		<delete dir="${temp.folder}"/>
	</target>

	<target name="@dot" depends="init" unless="@dot" description="Create jar: com.nokia.s60tools.imaker.tests @dot.">
		<delete dir="${temp.folder}/@dot.bin"/>
		<mkdir dir="${temp.folder}/@dot.bin"/>
		<path id="@dot.classpath">
			<fileset dir="${eclipse.home}/plugins">
		    	<include name="**/*.jar"/>
				<exclude name="com.nokia.s60tools.imaker*"/>
		   	</fileset>
		      <fileset dir="../com.nokia.s60tools.imaker">
		        <include name="**/*.jar"/>
		      </fileset>
		</path>
		<!-- compile the source code -->
		<javac destdir="${temp.folder}/@dot.bin" failonerror="${javacFailOnError}" source="${common.javac-source}" target="${common.javac-target}">
		<!--
			<compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
			<compilerarg value="@${basedir}/javaCompiler...args" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
			<compilerarg line="-log '${temp.folder}/@dot.bin${logExtension}'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
		-->
			<classpath refid="@dot.classpath" />
			<src path="src/"			/>
		</javac>
		<!-- Copy necessary resources -->
		<copy todir="${temp.folder}/@dot.bin" failonerror="true" overwrite="false">
			<fileset dir="src/">
				<exclude name="**/*.java"/>
				<exclude name="**/package.htm*"/>
			</fileset>
		</copy>
		<mkdir dir="${build.result.folder}"/>
		<copy todir="${build.result.folder}/@dot" failonerror="true" overwrite="false">
			<fileset dir="${temp.folder}/@dot.bin">
			</fileset>
		</copy>
		<delete dir="${temp.folder}/@dot.bin"/>
	</target>

	<target name="src.zip" depends="init" unless="src.zip">
		<mkdir dir="${build.result.folder}"/>
		<zip destfile="${build.result.folder}/src.zip" filesonly="false" whenempty="skip" update="false">
			<fileset dir="src/">
				<include name="**/*.java"/>
			</fileset>
		</zip>
	</target>

	<target name="build.jars" depends="init" description="Compile classes and build nested jars for the plug-in: com.nokia.s60tools.imaker.tests.">
		<available property="@dot" file="${build.result.folder}/@dot"/>
		<antcall target="@dot"/>
	</target>

	<target name="build.sources" depends="init">
		<available property="src.zip" file="${build.result.folder}/src.zip"/>
		<antcall target="src.zip"/>
	</target>

	<target name="gather.bin.parts" depends="init" if="destination.temp.folder">
		<mkdir dir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}"/>
		<copy todir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}" failonerror="true" overwrite="false">
			<fileset dir="${build.result.folder}/@dot">
				<include name="**"/>
			</fileset>
		</copy>
		<copy todir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}" failonerror="true" overwrite="false">
			<fileset dir="${basedir}">
				<include name="META-INF/"/>
				<include name="tools/"/>
			</fileset>
		</copy>
	</target>

	<target name="build.zips" depends="init">
	</target>

	<target name="gather.sources" depends="init" if="destination.temp.folder">
		<mkdir dir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}"/>
		<copy file="${build.result.folder}/src.zip" todir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}" failonerror="false" overwrite="false"/>
	</target>

	<target name="gather.logs" depends="init" if="destination.temp.folder">
		<mkdir dir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}"/>
		<copy todir="${destination.temp.folder}/com.nokia.s60tools.imaker.tests_${plugin.version}" failonerror="false" overwrite="false">
			<fileset dir="${temp.folder}">
				<include name="@dot.bin${logExtension}"/>
			</fileset>
		</copy>
	</target>

	<target name="clean" depends="init" description="Clean the plug-in: com.nokia.s60tools.imaker.tests of all the zips, jars and logs created.">
		<delete dir="${build.result.folder}/@dot"/>
		<delete file="${build.result.folder}/src.zip"/>
		<delete file="${plugin.destination}/com.nokia.s60tools.imaker.tests_${plugin.version}.jar"/>
		<delete file="${plugin.destination}/com.nokia.s60tools.imaker.tests_${plugin.version}.zip"/>
		<delete dir="${temp.folder}"/>
	</target>

	<target name="refresh" depends="init" if="eclipse.running" description="Refresh this folder.">
		<eclipse.convertPath fileSystemPath="C:/dev/workspaces/eclipse-3.3.2/com.nokia.s60tools.imaker.tests" property="resourcePath"/>
		<eclipse.refreshLocal resource="${resourcePath}" depth="infinite"/>
	</target>

	<target name="zip.plugin" depends="init" description="Create a zip containing all the elements for the plug-in: com.nokia.s60tools.imaker.tests.">
		<delete dir="${temp.folder}"/>
		<mkdir dir="${temp.folder}"/>
		<antcall target="build.jars"/>
		<antcall target="build.sources"/>
		<antcall target="gather.bin.parts">
			<param name="destination.temp.folder" value="${temp.folder}/"/>
		</antcall>
		<antcall target="gather.sources">
			<param name="destination.temp.folder" value="${temp.folder}/"/>
		</antcall>
		<delete>
			<fileset dir="${temp.folder}">
				<include name="**/*.bin${logExtension}"/>
			</fileset>
		</delete>
		<zip destfile="${plugin.destination}/com.nokia.s60tools.imaker.tests_${plugin.version}.zip" basedir="${temp.folder}" filesonly="true" whenempty="skip" update="false"/>
		<delete dir="${temp.folder}"/>
	</target>

</project>
