I am writing an ant file for compiling a flex project (but this question may apply to non-flex ant scripts as well).
I had several targets there that look like this:
<target name="first">
<mxmlc file="${src.dir}/FirstClass.as" output="${output.dir}/First.swf" ...identical_compiler_attributes...>
...identical_compiler_inner_elements...
<compiler.define name="AN_ATTRIBUTE" value="A_VALUE" />
</mxmlc>
</target>
<target name="second">
<mxmlc file="${src.dir}/SecondClass.as" output="${output.dir}/Second.swf" ...identical_compiler_attributes...>
...identical_compiler_inner_elements...
<!-- no additional compiler.define calls needed -->
</mxmlc>
</target>
I wanted to avoid duplication of common mxmlc attributes and inner element by using the <antcall>
ant task, so I came up with something like this:
<target name="first">
<antcall target="helper_target">
<param name="src.file" value="FirstClass.as"/>
<param name="output.file" value="First.swf"/>
</antcall>
</target>
<target name="second">
<antcall target="helper_target">
<param name="src.file" value="SecondClass.as"/>
<param name="output.file" value="Second.swf"/>
</antcall>
</target>
<target name="helper_target">
<mxmlc file="${src.dir}/${src.file}" output="${output.dir}/${output.file}" ...identical_compiler_attributes...>
...identical_compiler_inner_elements...
<!-- WHAT DO I DO ABOUT THE compiler.define?? -->
</mxmlc>
</target>
This solves most duplication nicely. But what do I do about the <compiler.define>
and other inner elements that differ between the mxmlc calls? The builtin if
mechanism of ant doesn't help me here - i can't invoke a target in the middle of an mxmlc element....
Any ideas? (I know ant-contrib has some kind of if mechanism. Would rather have a pure-ant solution, and not even sure if ant-contrib's if will help here).