我正在尝试将一个文件(由模式指定)移动到Ant宏中的给定位置:
<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>这将只工作一次,因为${source_name}是不可变的。
一种选择是使用变量task,但我没有找到将refid赋值给var的方法。
有没有办法在宏定义中拥有类似于局部变量的东西?或者(XY问题)有没有更好的方法来解决我的问题?
发布于 2011-11-28 15:17:24
从Ant1.8开始,你可以使用local task来做这件事。例如:
<local name="source_name"/>
<property name="source_name" refid="source_refid"/>您的示例就是local要做的事情!
https://stackoverflow.com/questions/8292414
复制相似问题