- Compiling a swf for different environments (development, production, etc.)
- Copying files to web server
- Replacing tokens
- Running the app in the browser
I continually try to improve myself and my coding practices. So I decided to see if I could do some conditional stuff in Ant rather than forcing myself and users to choose specific tasks depending on the environment they are building from. One task to compile them all.
Ant to check if in FDT
<!-- Determine if FDT's special Ant commands are available. --> <condition property="isFDT"> <typefound name="fdt.loadProjectProperties" /> </condition>
The code above sets a property isFDT to true if Ant has found the fdt.loadProjectProperties task (I probably could have checked for any FDT Ant task, I just happened to choose this one). If the specified task is not available, then isFDT will not be set to true.
Conditional compiling
Now I want one task which will compile the swf using the FDT Ant task if building from FDT and use the mxmlc in all other cases. So here is my one task which will try to run both the FDT and mxmlc compile tasks:<target name="Compile"> <antcall target="Compile App MXMLC" /> <antcall target="Compile App FDT" /> </target>
Now I don't want both to run. The way to have one run and not the other is to use the if and unless attributes of the target tag:
<!-- Compile the app using the Flex mxmlc compiler --> <target name="Compile App MXMLC" unless="isFDT"> <!-- MXMLC stuff in here --> </target> <!-- Compile the app using the FDT compiler --> <target name="Compile App FDT" if="isFDT"> <!-- FDT stuff in here --> </target>
So the if basically says if the isFDT property is true then run this task. The unless is saying don't run this task if isFDT is set to true.
I don't know if this is the best way of doing this, but it seems rather simple and works very well.
No comments:
Post a Comment