<?xml version="1.0" encoding="UTF-8"?>
<project name="dojo-build" default="build-and-copy">

	<target name="init">
		<property file="build.properties"/>
		<property name="target.dir" value="${basedir}/target"/>
		<property name="source.dir" value="${target.dir}/dojo-release-${dojo.version}-src"/>
		<property name="buildscripts.dir" value="${source.dir}/util/buildscripts"/>
		<property name="build.dir" value="${target.dir}/dojo-build"/>
	</target>

	<target name="clean" depends="init">
		<delete dir="${target.dir}"/>
	</target>
	
	<target name="download" depends="init" description="Download and unzip the Dojo Toolkit">

		<mkdir dir="${target.dir}"/>

		<get src="${dojo.download.url}" usetimestamp="true"
			dest="${target.dir}/dojo-release-${dojo.version}-src.zip" />

		<unzip src="${target.dir}/dojo-release-${dojo.version}-src.zip" dest="${source.dir}">
			<mapper type="glob" from="dojo-release-${dojo.version}-src/*" to="*"/>
		</unzip>

	</target>

	<target name="build-and-copy" depends="download" description="Prepare Dojo build optimized for use with spring-js">

		<chmod file="${buildscripts.dir}/build.sh" perm="ugo+rx"/>

		<exec executable="${buildscripts.dir}/build.sh" dir="${buildscripts.dir}/">
		   <arg line="releaseDir=${build.dir}"/>
		   <arg line="profileFile=${basedir}/${dojo.profile}"/>
		   <arg line="releaseName="/>
		   <arg line="copyTests=false"/>
		   <arg line="action=release"/>
		   <arg line="optimize=shrinksafe.keepLines"/>
		   <arg line="cssOptimize=comments.keepLines"/>
		   <arg line="cssImportIgnore=../dijit.css"/>
		</exec>
		
		<zip destfile="${target.dir}/dojo-build.zip" basedir="${build.dir}"/>

		<copy file="${target.dir}/dojo-build.zip" 
			toFile="${basedir}/../../../spring-js/dojo-build/dojo-build.zip" />

	</target>
	
</project>
