2005-11-23

Macro in Ant

When you write an ant macro, the main problem is inabillity to define temporary property.
    <macrodef name="sample">
<sequential>
<java resultproperty="java.result">
</sequential>
</macrodef>
Property can be set only once, and later nobody can change its value. It is good behaviour,
elsewere we can run into troubles depends on order of target calls.

So, if we call the above macro second time, the value of ${java.result} stays unchanged.

But we can overcome this:
   <macrodef name="sample">
<attribute name="workDir">
<sequential>
<antcall target="internal.java">
<param name="dir" value="@{workDir}">
</antcall>
</sequential>
</macrodef>

<target name="internal.java">
<java dir="${dir}" resultproperty="java.result"/>
</target>
That macro can be called more than one time, and will be works correctly.

No comments:

Post a Comment