ANT parameter passing by reference
I feel I have some basic understanding problem with the antcall/target concept. Especially when antcall is made with parameter, Like C++, is there a way to call target will parameter as pass by reference? so that value changed in the target can be retrieved by the caller?
In the below example, I want to check if two files are same and display the result, but for the below example, I would get the output as
Are Same Files : ${isFileName}
Example:
< target name="checkFileAreSame">
< condition property="isFileSame">
< filesmatch file1="a.txt" file2="b.txt"/>
< /condition >
< /target >
< target name="Maintask">
< antcall target="checkFileAreSame">
< param name="isFileSame" value="false">
< /antcall >
< echo message="Are files Same : ${isFileSame}"/>
&开发者_如何学Golt; /target >
Thanks for your input in advance.
Ant properties are immutable - once set, their values cannot be changed.
When using the antcall
task note that:
The called target(s) are run in a new project; be aware that this means properties, references, etc. set by called targets will not persist back to the calling project.
But also note that the properties that you pass to the called target using 'antcall' param
attributes are immutable in the called target.
That means that in the 'condition' task example given:
<condition property="isFileSame">
<filesmatch file1="a.txt" file2="b.txt"/>
</condition>
the isFileSame
property is already set to false
by the caller, and so will remain false regardless of the file comparison.
It's more common to declare dependencies between targets in this sort of way:
<target name="checkFileAreSame">
<condition property="isFileSame">
<filesmatch file1="a.txt" file2="b.txt"/>
</condition>
</target>
<target name="Maintask" depends="checkFileAreSame">
<echo message="Are files Same : ${isFileSame}"/>
</target>
Ant will determine the call graph for 'Maintask' requires that 'checkFileAreSame' be run first.
It sounds like you need AntCallBack task from ant-contrib package (separate from core Ant).
Ant-contrib is a very useful library if you aren't happy (like many) with Ant's "declarative" flow style.
See here:
http://ant-contrib.sourceforge.net/
http://ant-contrib.sourceforge.net/tasks/tasks/index.html
http://ant-contrib.sourceforge.net/tasks/tasks/antcallback_task.html
精彩评论