I love ANTs
I’m a ANT lover. By ANT I mean http://ant.apache.org/ and not http://en.wikipedia.org/wiki/Ant
ANT is a task automation script written in Java you can write in XML and add different script languages (Javascript, Java, Ruby, Beanshell, etc) and also shell command line and other tasks really useful to development.
I use a lot of ANT because it comes bundled in Eclipse.
There’s alternatives for this in other languages and platforms, so this may be interesting for people using other dev environments to imagine how you can save development time.
You can find below a list of some useful ANT tricks and Flash debugging I use.
And there’s lot more I can add on this and also for other applications where I use javascript for Adobe IDEs (Photoshop, Flash, AfterEffects) and some other useful scripts I have in Python, but overall what I want to say with this is to be creative when coding, use the advantage that you’re an developer and create some tools that will save your time regardless the platform.
Executing scripts
<project name=”TestProject” default=”Some task”>
<target name=”Some task”>
<script language=”javascript”>
<![CDATA[
echo = project.createTask("echo");
echo.setMessage("Hello from JS");
echo.perform();
]]>
</script>
</target>
</project>
Just a simple example using javascript to output a message. As I said, you can use different scripts and access project properties.
<project name=”TestProject” default=”Some task”>
<target name=”Some task”>
<exec executable=”say”>
<arg value=”hello”/>
</exec>
</target>
</project>
You can run any executable, in this example running “say” command line app in OSX.
<target name=”Upload to TestFlight”>
<input message=”Release note” addproperty=”releaseNote” />
<fail message=”Release note is empty”>
<condition>
<not>
<and>
<isset property=”releaseNote” />
<length string=”${releaseNote}” when=”greater” length=”0″ />
</and>
</not>
</condition>
</fail>
<exec executable=”curl”>
<arg value=”-F file=@${project.bin}/${project.name}.ipa” />
<arg value=”-F api_token=${tf.apiToken}” />
<arg value=”-F team_token=${tf.teamToken}” />
<arg value=”-F notes=${releaseNote}” />
<arg value=”-F distribution_list=’${tf.distributionList}’” />
<arg value=”-F notify=True” />
<arg value=”http://testflightapp.com/api/builds.json” />
</exec>
</target>
Another example of running executable files, this time uploading a file to TestFlight automatically when compiling the app as release.
There’s different tasks for manipulating files, such FTP, SVN, ZIP, Rename, etc.
Sound task
<project name=”TestProject” default=”Some task”>
<sound>
<success source=”/System/Library/Sounds/Glass.aiff” />
<fail source=”/System/Library/Sounds/Ping.aiff” />
</sound>
<target name=”Some task”>
…
</target>
</project>
Sound task plays a sound when a task is executed and you can define which sound to play when a task is successful or it raises some error.
The sound task is useful for time consuming tasks, like compiling a whole project.
Usually when I’m compiling AIR projects to iOS takes about a minute, so I can execute the task and go browsing the internet or check emails and it’ll let me know when it’s finished compiling.
UpToDate
<target name=”Check Changed” id=”CheckChanged”>
<uptodate property=”notchanged” targetfile=”">
<srcfiles dir=”${basedir}” includes=”**/*.as” />
<srcfiles dir=”${basedir}” includes=”**/*.mxml” />
</uptodate>
</target>
<target name=”Compile” depends=”Check Changed” unless=”notchanged”>
<echo message=”Compiling” />
</target>
Uptodate task checks whether a file has changed from last execution.
So, when running Compile task, it first checks if any file in the project with *.as *.mxml has changed, and it executes the task only if there’s any file changed.
Versioning
<script language=”javascript”>
<![CDATA[
var versionArr = String(project.getProperty("project.version")).split(".");
versionArr[versionArr.length - 1] = Number(versionArr[versionArr.length - 1]) + 1;
project.setProperty(“version”, versionArr.join(“.”));
]]>
</script>
<propertyfile file=”${basedir}/build_project.properties”>
<entry key=”project.version” value=”${version}” />
</propertyfile>
Just a simple javascript for auto-incrementing a version number and writing the new version number in a properties file. Usually the *.properties file is used for defining variables in ANT.
Versioning SWF
******FLASH DEVELOPERS READ THIS!!!!!!******
The Flex mxmlc compiler has a parameter you can pass to define a namespace and variable that will exist in your SWF when compiled.
> mxmlc … -define+\=CONFIG\:\:VERSION,${version} …
This is really useful when debugging the app and you’re not sure if your browser is caching your SWF file.
In AS3 you can call CONFIG::VERSION anywhere and it’ll return the value you set in the compiler argument. So I use it together with the Versioning task and UpToDate task above and each time I compile it assigns a new version number to my SWF.
And I do:
/*FDT_IGNORE*/
trace(“VERSION:”, CONFIG::VERSION);
/*FDT_IGNORE*/
FDT_IGNORE is another trick for FDT users, it won’t raise any syntax error anything within this block comment.
So, I know which is the most recent version and the version my browser is running, you can also print it on screen if it makes easier for other non-techie people are checking.
Also, if you Google for Flex mxmlc define, there’s loads of examples showing how to use it with CONFIG::DEBUG,true / false, so when compiling you can use it as well to show/hide the version number on screen, and other scripts you use for debugging.
