2011-02-15 94 views
2


我对ANT脚本非常陌生,并且正在使用它来自动化我的项目中的日常构建。我从脚本(XML文件)的意义上更多地使用它,并聚合预先存在的功能,并提出构建流程。通过引用传递的ANT参数

我觉得我对antcall/target概念有一些基本的理解问题。特别是当antcall使用参数创建时,像C++一样,有没有一种方法可以将target参数作为参考传递?因此调用者可以检索目标中改变的值吗?

在下面的例子中,我要检查,如果两个文件是相同的,显示的结果,但对于下面的例子,我会得到的输出作为


相同文件:$ {isFileName}


实施例:

< 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}"/>
</target>


感谢您的提前意见。

回答

2

蚂蚁properties are immutable - 一旦设置,它们的值不能改变。

当使用antcall task需要注意的是:

被叫目标(S)的一个新的 项目运行;请注意,这意味着 属性,引用等由 设置的目标将不会持续返回到调用项目的 。

但还要注意,使用'antcall'param属性在被调用目标中传递给被调用目标的属性是不可变的。 这意味着,在“条件”任务为例进行说明:

<condition property="isFileSame"> 
    <filesmatch file1="a.txt" file2="b.txt"/> 
</condition> 

isFileSame属性已经由主叫方设置为false,因此仍将虚假不管文件比较的。

这是更常见的declare dependencies between targets在这种方式:

<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> 

蚂蚁将决定“MainTask的”调用图要求“checkFileAreSame”先运行。

+0

+1你的建议使用的依赖,而不是[``(http://ant.apache.org /manual/Tasks/antcall.html) – 2011-02-15 18:22:50