basic elements: istrue isfalse not and or xor available isset equals filesmatch
1、istrue isfalse:断言 真 假
<!-- istrue isfalse:断言 真 假 --> <target name="test"> <!-- 给scondition设定值,istrue,断言真--> <condition property="scondition"> <!-- istrue设为false,所以将scondition设为false--> <istrue value="false" /> </condition> <!-- 调用isTrue和isFalse这两个target--> <antcall target="isTrue"> </antcall> <antcall target="isFalse"> </antcall> </target> <!-- if条件判断,成立执行--> <target name="isTrue" if="scondition"> <echo>is ture</echo> </target> <!-- unless条件判断,不成立时执行--> <target name="isFalse" unless="scondition"> <echo>is false</echo> </target>
2、逻辑运算
2.1、not 逻辑非
<target name="test4"> <condition property="scondition"> <not> <istrue value="true" /> </not> </condition> <antcall target="isTrue"> </antcall> <antcall target="isFalse"> </antcall> </target>
2.2、and 逻辑与
2.3、or 逻辑或 xor异或 (语法上与and类似)
<!-- and,or中的条件相与,相或 --> <target name="test4"> <condition property="scondition"> <or> <istrue value="true" /> <istrue value="false" /> </or> </condition> <antcall target="isTrue"> </antcall> <antcall target="isFalse"> </antcall> </target>
3、available 是否可用
<project name="testCondition">
<path id="all.test.classes">
<pathelement location="bin"/>
</path>
<target name="test">
<condition property="scondition">
<!--在指定的classpath路径下是否存在资源 TestTest.class-->
<available resource="TestTest.class">
<classpath refid="all.test.classes" />
</available>
</condition>
<antcall target="isTrue"></antcall>
<antcall target="isFalse"></antcall>
</target>
<target name="isTrue" if="scondition">
<echo>is ture</echo>
</target>
<target name="isFalse" unless="scondition">
<echo>is false</echo>
</target>
</project>
4、isset 指定属性是否存在
<property name="name" value="this is name"/> <target name="test2"> <condition property="scondition"> <!--如果属性name不存在则返回false--> <isset property="name"/> </condition> <antcall target="isTrue"></antcall> <antcall target="isFalse"></antcall> </target>
5、equals 是否相等
<project name="testCondition">
<!--属性也可以通过ant参数-D来设置-->
<property name="name" value="this is name"/>
<target name="test">
<condition property="scondition">
<!--如果arg1的值与arg2的值相等返回true,否则为false-->
<equals arg1="${name}" arg2="this is name"/>
</condition>
<antcall target="isTrue"></antcall>
<antcall target="isFalse"></antcall>
</target>
<target name="isTrue" if="scondition">
<echo>is ture</echo>
</target>
<target name="isFalse" unless="scondition">
<echo>is false</echo>
</target>
</project>
6、filesmatch 比较文件
<project name="testCondition">
<target name="test">
<condition property="scondition">
<!--如果file1所代表的文件与file2所代表的文件相等返回true,否则为false-->
<filesmatch file1="testfile1.txt" file2="testfile2.txt"/>
</condition>
<antcall target="isTrue"></antcall>
<antcall target="isFalse"></antcall>
</target>
<target name="isTrue" if="scondition">
<echo>is ture</echo>
</target>
<target name="isFalse" unless="scondition">
<echo>is false</echo>
</target>
</project>
更多内容可以参考:http://ant.apache.org/manual/CoreTasks/conditions.html