Macrodef和“本地属性”

时间:2011-11-28 06:56:26

标签: ant macrodef

我正在尝试将文件(由模式指定)移动到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>

这只会工作一次,因为${source_name}是不可变的。

一个选项是使用变量任务,但我没有找到将refid分配给var的方法。

有没有办法在macrodef中有类似于局部变量的东西?或者(XY问题)有更好的方法来解决我的问题吗?

1 个答案:

答案 0 :(得分:9)

从Ant 1.8开始,您可以使用local task。例如:

<local name="source_name"/>
<property name="source_name" refid="source_refid"/>

你的例子只是local的用途!

相关问题