ANT如何在Ant 1.8中使用词法范围的属性?

时间:2011-04-19 13:02:56

标签: scripting ant

我有脚本,一旦设置变得不可写,就不起作用了。

<target name="test" >

    <fileset id="dir1" dir="./dir1"/>
    <fileset id="dir2" dir="./dir2"/>

    <pathconvert property="path.converted" refid="dir1"/>
    <echo message="${path.converted}"/>
    <property name="path.converted" value="set this property manually"/>
    <echo>${path.converted}</echo>
    <pathconvert property="path.converted" refid="dir2"/>
    <echo message="${path.converted}"/>
</target>

总是回应相同的结果,但我希望回音是不同的

我在Apache Ant 1.8.0版本中读到了

  

Lexically scoped当地物业,   即仅定义的属性   在目标内,顺序阻止或   类似的环境。这是非常的   在s里面有用的   宏现在可以定义一个临时的   财产将一旦消失   任务已经完成。

如何使用它们?

2 个答案:

答案 0 :(得分:4)

我找到了解决方案。使用local task

<target name="direct" depends="">

    <fileset id="dir1" dir="./dir1"/>
    <fileset id="dir2" dir="./dir2"/>

    <!--<property name="path.converted" value="0"/>-->
    <local name="path.converted"/>

    <pathconvert property="path.converted" refid="dir1"/>
    <echo message="${path.converted}"/>
    <local name="path.converted"/>
    <property name="path.converted" value="0"/>

    <echo>${path.converted}</echo>
    <local name="path.converted"/>
    <pathconvert property="path.converted" refid="dir2"/>
    <echo message="${path.converted}"/>

</target>

答案 1 :(得分:0)

对于上面的示例,我只是为path.converted使用不同的名称 path.converted.1,path.converted.2等。

如果您已经创建了一个macrodef,那么您一定要使用本地任务将该属性设为本地。