【问题标题】:Ant - multiple conditions to drive a property valueAnt - 驱动属性值的多个条件
【发布时间】:2016-03-08 13:00:22
【问题描述】:

我正在尝试在 Ant 检查目标中添加多个 AND 条件来设置属性。我想根据设置的属性执行某些操作。

<target name="checkVal">
    <condition property="val.present">
        <and>
            <available file="${srcDir}/somefile"/>
            <matches pattern="MyClass.java" string="${pathString}"/>
        </and>
    </condition>
    <fail message="Failing the condition."/>
</target>

<target name="doSomething" depends="checkVal" if="val.present">
    ...
</target>

如果val.present 属性由&lt;and&gt; 块中的两个条件设置,则意图是执行“doSomething”。一个条件检查文件是否可用,另一个条件检查路径字符串是否包含特定的源文件。

我总是收到失败消息。

以下是可行的:

<target name="checkVal">
    <available file="${srcDir}/somefile" property="val.present"/>
</target>

<target name="doSomething" depends="checkVal" if="val.present">
    ...
</target>

有人能告诉我如何才能正确吗?

【问题讨论】:

    标签: ant properties conditional-statements multiple-conditions


    【解决方案1】:

    在我将 matches 任务替换为 contains 任务后,它起作用了。

    <target name="checkVal">
        <condition property="val.present">
            <and>
                <available file="${srcDir}/somefile"/>
                <contains substring="MyClass.java" string="${srcDir}"/>
            </and>
        </condition>    
    </target>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-11
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多