【问题标题】:ANT How to use the lexically scoped properties in Ant 1.8?ANT 如何在 Ant 1.8 中使用词法范围的属性?
【发布时间】:2011-04-19 13:02:55
【问题描述】:

我的脚本不起作用,因为属性一旦设置就变得不可写

<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 版本中看到,

词法范围的本地属性, 即仅定义的属性 在目标、顺序块或 类似的环境。这是非常 在 s 内部有用 宏现在可以定义一个临时 财产一旦消失就会消失 任务完成。

如何使用它们?

【问题讨论】:

    标签: scripting ant


    【解决方案1】:

    我找到了解决方案。使用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>
    

    【讨论】:

    • stackoverflow 消息:您可以在 2 天内接受自己的答案
    【解决方案2】:

    对于上面的示例,我会简单地为 path.converted 使用不同的名称。
    path.converted.1、path.converted.2 等

    如果您要创建宏定义,则绝对应该使用 local 任务将属性设为本地。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 2014-06-07
      • 2011-07-26
      • 2016-09-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多