Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

<target name="compile">
<exec executable="C:/sdk/flex/4.1/bin/mxmlc.exe" dir="${basedir}">
<arg line="${basedir}/Project.as"/>
<arg line="-output=${basedir}/bin/project.swf"/>
<arg line="-source-path+=${basedir}/src"/>
<arg line="-library-path+=${basedir}/lib"/>
</exec>
</target>
<!-- identify properties file -->
<property file="build.properties" />
<!-- identify environment variables -->
<property environment="env" />
<!-- Add the ant-contrib tasks -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${resources.dir}/ant-contrib.jar" />
<!-- Set up FlexUnit Ant tasks -->
<!-- Builds the project -->
<target name="build" depends="run-test,compile-swf">
<echo>Build complete.</echo>
</target>
<!-- Build and deploy the project to testing context -->
<target name="deploy-testing" depends="build">
<echo>SWF compiled and ready for deployment to a testing environment.</echo>
</target>
<taskdef resource="flexTasks.tasks" classpath="${basedir}/ant/flexTasks.jar"/>
<target name="compile">
<mxmlc file="${basedir}/src/Project.as" output="${basedir}/bin/Project.swf" debug="true">
<source-path path-element="${basedir}/src" />
<compiler.library-path dir="${basedir}/lib" append="true">
<include name="*.*"/>
</compiler.library-path>
</mxmlc>
</target>
<!-- Set's the FLEX_HOME property based on a command line parameter or environment variable. -->
<target name="init">
<if>
<equals arg1="${FLEX_HOME}" arg2="$${FLEX_HOME}" />
<then>
<if>
<equals arg1="${env.FLEX_HOME}" arg2="$${env.FLEX_HOME}" />
<then>
<fail message="Variable FLEX_HOME does not exist. Set an environment variable or pass Ant a parameter like so: ant -DFLEX_HOME='/sdk/flex/4.1' compile-swf" />
</then>
<!-- Cleans up the project compile output. -->
<target name="clean-bin">
<delete dir="${bin.dir}" failonerror="false" includeemptydirs="true" />
<mkdir dir="${bin.dir}" />
</target>
<!-- Cleans up the test output. -->
<target name="clean-test">
<delete dir="${test.bin.dir}" failonerror="false" includeemptydirs="true" />
<mkdir dir="${test.bin.dir}" />
<!-- Compiles the project into a SWF. -->
<target name="compile-swf" depends="init,clean-bin">
<java jar="${env.FLEX_HOME}/lib/mxmlc.jar" dir="${env.FLEX_HOME}/frameworks" fork="true" failonerror="true">
<arg value="${debug.compile.target}" />
<arg value="-output=${debug.compile.output}" />
<arg value="-source-path=${src.dir}" />
<arg value="-library-path+=${lib.dir}" />
<arg value="-static-link-runtime-shared-libraries=true" />
<arg value="-incremental=true" />
<arg value="-verbose-stacktraces=true" />
<!-- Runs the FlexUnit task on the compiled test output. -->
<target name="run-flexunit" depends="compile-test">
<flexunit swf="${test.compile.output}"
toDir="${test.bin.dir}"
haltonfailure="false"
verbose="true"
localTrusted="true"
failureproperty="flexunit.failed"
timeout="5000" />
</target>
<!-- Compiles the SWF and launches a browser for debugging. -->
<target name="run-debug" depends="compile-swf">
<if>
<equals arg1="${os.name}" arg2="Mac OS X" />
<then>
<exec executable="open" spawn="true">
<arg line="-a ${env.DEFAULT_BROWSER} ${debug.compile.output}" />
</exec>
</then>
<else>
<!-- Compiles the unit tests and runs the FlexUnit task to analyze the results. -->
<target name="run-test" depends="init,run-flexunit">
<if>
<equals arg1="${flexunit.failed}" arg2="true" />
<then>
<fail message="Unit tests failed." />
</then>
</if>
</target>