我试图将文件(由模式指定)移动到Ant macrodef中的给定位置:
<macrodef name="extract">
<attribute name="package"/>
<sequential>
<!-- the path will contain the unique file in extracted regardless of the name -->
<path id="source_refid">
<dirset dir="${dep}/lib/@{package}/extracted/">
<include name="@{package}-*"/>
</dirset>
</path>
<!-- this is not working: properties are immutable -->
<property name="source_name" refid="source_refid"/>
<move
file="${source_name}"
tofile="${dep}/@{package}/"
overwrite="true"
/>
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)
这将只工作一次,因为它${source_name}是不可变的.
一个选项是使用变量任务,但我没有找到一种方法来为一个refid分配一个var.
有没有办法在macrodef中有类似于局部变量的东西?或者(XY问题)有更好的方法来解决我的问题吗?
从Ant 1.8开始,您可以使用此local任务.例如:
<local name="source_name"/>
<property name="source_name" refid="source_refid"/>
Run Code Online (Sandbox Code Playgroud)
你的例子就是那种东西local!