我的问题是;
当我多次调用一个antcallback函数时,它总是返回相同的值。查看下面的代码:
<project name="AntCallBack" default="testFnc" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<target name="acbFnc" description="Sub Function" >
<echo message="[acbFnc] started"/>
<property name="out.file" value="${in.file}"/>
<echo message="[acbFnc] ended."/>
</target>
<target name="testFnc" description="Main" >
<antcallback target="acbFnc" return="out.file" >
<param name="in.file" value="TEST-1" />
</antcallback>
<echo message="CALL - 1 : out.file : ${out.file}" />
<antcallback target="acbFnc" return="out.file" >
<param name="in.file" value="TEST-2" />
</antcallback>
<echo message="CALL - 2 : out.file : ${out.file}" />
</target>
</project>
结果是:
$ /home/apache-ant-1.9.4/bin/ant -f AntCallBackTest.xml
Buildfile: AntCallBackTest.xml
testFnc:
acbFnc:
[echo] [acbFnc] started
[echo] [acbFnc] ended.
[echo] CALL - 1 : out.file : TEST-1
acbFnc:
[echo] [acbFnc] started
[echo] [acbFnc] ended.
[echo] CALL - 2 : out.file : TEST-1
BUILD SUCCESSFUL
Total time: 0 seconds
如你所见,我发送了"param name="in。文件" value="TEST-1" "第一次调用,
然后我输入param name=。文件" value="TEST-2" "在第二次调用,
但是它总是返回第一个值:
CALL - 1: out。file: TEST-1
CALL - 2: out。file: TEST-1
我做错了什么?
提前感谢
我找到了解决方案:
我必须在第二次调用之前取消变量设置:
<var name="out.file" unset="true"/>
我的意思是,它应该是这样的:
<target name="testFnc" description="Main" >
<antcallback target="acbFnc" return="out.file" >
<param name="in.file" value="TEST-1" />
</antcallback>
<echo message="CALL - 1 : out.file : ${out.file}" />
<var name="out.file" unset="true"/>
<antcallback target="acbFnc" return="out.file" >
<param name="in.file" value="TEST-2" />
</antcallback>
<echo message="CALL - 2 : out.file : ${out.file}" />
</target>