ant——condition
2012-12-25 18:18
183 查看
ant condition的常用用法
basic elements: istrue isfalse not and or xor available isset equals filesmatch
1. isset指定属性是否存在
<property file="${basedir}/javaConfig/user.properties"/>
<condition property="fppcondition">
<isset property="FPP"/>
</condition>
<antcall target="isFPPTrue"></antcall>
<antcall target="isFPPFalse"></antcall>
又如:
<project name="testCondition">
<!--属性也可以通过ant参数-D来设置-->
<property name="name" value="this is name"/>
<target name="test">
<condition property="scondition">
<!--如果属性name不存在则返回false-->
<isset property="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>
2. istrue isfalse: 断言真假
<project name="testCondition">
<target name="test">
<condition property="scondition">
<istrue value="true"/>
</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>
3. 逻辑运算
3.1 not 逻辑非
<project name="testCondition">
<target name="test">
<condition property="scondition">
<not>
<istrue value="true"/>
</not>
</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>
3.2 and 逻辑与
<project name="testCondition">
<target name="test">
<condition property="scondition">
<and>
<istrue value="true"/>
<istrue value="false"/>
</and>
</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>
3.3 or逻辑或
xor 异或(语法上与and类似)
4. 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>
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>
basic elements: istrue isfalse not and or xor available isset equals filesmatch
1. isset指定属性是否存在
<property file="${basedir}/javaConfig/user.properties"/>
<condition property="fppcondition">
<isset property="FPP"/>
</condition>
<antcall target="isFPPTrue"></antcall>
<antcall target="isFPPFalse"></antcall>
<target name="isFPPTrue" if="fppcondition"> <echo>FPP is ture</echo> </target> <target name="isFPPFalse" unless="fppcondition"> <echo>FPP is false</echo> </target>
又如:
<project name="testCondition">
<!--属性也可以通过ant参数-D来设置-->
<property name="name" value="this is name"/>
<target name="test">
<condition property="scondition">
<!--如果属性name不存在则返回false-->
<isset property="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>
2. istrue isfalse: 断言真假
<project name="testCondition">
<target name="test">
<condition property="scondition">
<istrue value="true"/>
</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>
3. 逻辑运算
3.1 not 逻辑非
<project name="testCondition">
<target name="test">
<condition property="scondition">
<not>
<istrue value="true"/>
</not>
</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>
3.2 and 逻辑与
<project name="testCondition">
<target name="test">
<condition property="scondition">
<and>
<istrue value="true"/>
<istrue value="false"/>
</and>
</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>
3.3 or逻辑或
xor 异或(语法上与and类似)
4. 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>
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>
相关文章推荐
- 实习杂记(23):ant里面condition属性测试
- ant的condition使用总结
- Ant内置任务之condition
- ant的condition任务
- Ant unless 和condition的用法
- Ant 条件判断 condition
- 在Ant中使用逻辑判断 Condition
- ant 条件判断 condition
- Ant 条件判断 condition
- Ant 脚本的condition标签
- ant 条件判断 condition
- ant常用task之condition
- ant的condition任务
- ant学习
- UVA-10161 Ant on a Chessboard
- Ant的安装
- ant安装和ant的环境配置
- Ant学习总结(1)对exec的理解
- ant简述
- 解决ant编译中出现“includeantruntime was not set”警告的问题