<!-- 
	This is intended to be a simple build file, created a suggestion for the necessary steps need to utilize the FlexUnit4 Ant task.
	For the most detail when running this build, call "ant -v clean package".  The build uses a simple lifecycle of: 
	
	init->compile->test->package
	
	The end goal is to produce a zip of a website you could deploy for your application.  This build is not intended to be an example
	for how to use Ant or the Flex SDK Ant tasks.  This is just one possible way to utilize the FlexUnit4 Ant task. 
 -->
<project name="FlexUnit4SampleProject" basedir="." default="test">
	<!-- setup a prefix for all environment variables -->
	<property environment="env" />
	
	<!-- Setup paths for build -->
	<property name="test.src.loc" location="${basedir}/src/" />
	<property name="lib.loc" location="${basedir}/libs" />
	<property name="output.loc" location="${basedir}/target" />
	<property name="bin.loc" location="${output.loc}/bin" />
	<property name="report.loc" location="${output.loc}/report" />
	<property name="dist.loc" location="${output.loc}/dist" />

	<!-- Setup Flex and FlexUnit ant tasks -->
	<!-- You can set this directly so mxmlc will work correctly, or set FLEX_HOME as an environment variable and use as below -->
	<property name="FLEX_HOME" location="${env.FLEX_HOME}" />
	<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
	<taskdef resource="flexUnitTasks.tasks">
	   <classpath>
	      <fileset dir="${lib.loc}">
	         <include name="flexUnitTasks*.jar" />
	      </fileset>
	   </classpath>
	</taskdef>

	<target name="clean">
		<!-- Remove all directories created during the build process -->
		<delete dir="${output.loc}" />
	</target>

	<target name="init">
		<!-- Create directories needed for the build process -->
		<mkdir dir="${output.loc}" />
		<mkdir dir="${bin.loc}" />
		<mkdir dir="${report.loc}" />
		<mkdir dir="${dist.loc}" />
	</target>

	<target name="test" depends="init">
		<!-- Execute FlexUnit tests and publish reports -->
		<flexunit 
			player="air"
		    workingDir="${bin.loc}"
		    toDir="${report.loc}" 
			haltonfailure="false" 
			verbose="true" 
			localTrusted="true">
	      <testSource dir="${test.src.loc}">
	         <include name="**/*Tests.as" />
	      </testSource>
	      <library dir="${lib.loc}" />
	   </flexunit>

		<!-- Generate readable JUnit-style reports -->
		<junitreport todir="${report.loc}">
			<fileset dir="${report.loc}">
				<include name="TEST-*.xml" />
			</fileset>
			<report format="frames" todir="${report.loc}/html" />
		</junitreport>
	</target>
	
</project>