需要检查<target> </target>中的两个属性

时间:2014-08-13 12:33:08

标签: xml ant

我使用的是ant,我有两个属性:testA和testB,都接受true或false。

在目标中我需要检查两者是否都是真的,但<target>只接受一个if属性。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用<condition>任务根据其他属性是否为真来创建新属性。

的build.xml

<project name="ant-target-multi-conditional" default="run">
    <target name="init">
        <property name="testA" value="true"/>
        <property name="testB" value="true"/>
    </target>

    <target name="condition-check">
        <condition property="both-are-true">
            <and>
                <istrue value="${testA}"/>
                <istrue value="${testB}"/>
            </and>
        </condition>
    </target>

    <target name="run" depends="init,condition-check" if="both-are-true">
        <echo>Both testA and testB are true.</echo>
    </target>
</project>

输出

init:

condition-check:

run:
     [echo] Both testA and testB are true.