Ant 条件判断 if

简介: 用ant写个build.xml,用到condition,作笔记如下: basic elements: istrue isfalse not and or xor available isset equals  filesmatch 1、istrue isfalse:断言 真 假  <project name="testCondition">       <t
用ant写个build.xml,用到condition,作笔记如下: 
basic elements: istrue isfalse not and or xor available isset equals  filesmatch 
1、istrue isfalse:断言 真 假 
  1. <project name="testCondition">  
  2.     <target name="test">  
  3.         <condition property="scondition">  
  4.             <istrue value="true"/>  
  5.         </condition>  
  6.         <antcall target="isTrue">  
  7.         </antcall>  
  8.         <antcall target="isFalse">  
  9.         </antcall>  
  10.     </target>  
  11.     <target name="isTrue" if="scondition">  
  12.         <echo>is ture</echo>  
  13.     </target>  
  14.     <target name="isFalse" unless="scondition">  
  15.         <echo>is false</echo>  
  16.     </target>  
  17. </project>  


2、逻辑运算 
2.1、not 逻辑非 
  1. <project name="testCondition">  
  2.     <target name="test">  
  3.         <condition property="scondition">  
  4.             <not>  
  5.                 <istrue value="true"/>  
  6.             </not>  
  7.         </condition>  
  8.         <antcall target="isTrue">  
  9.         </antcall>  
  10.         <antcall target="isFalse">  
  11.         </antcall>  
  12.     </target>  
  13.     <target name="isTrue" if="scondition">  
  14.         <echo>is ture</echo>  
  15.     </target>  
  16.     <target name="isFalse" unless="scondition">  
  17.         <echo>is false</echo>  
  18.     </target>  
  19. </project>  

2.2、and 逻辑与 
  1. <project name="testCondition">  
  2.     <target name="test">  
  3.         <condition property="scondition">  
  4.             <and>  
  5.                 <istrue value="true"/>  
  6.                 <istrue value="false"/>  
  7.             </and>  
  8.         </condition>  
  9.         <antcall target="isTrue">  
  10.         </antcall>  
  11.         <antcall target="isFalse">  
  12.         </antcall>  
  13.     </target>  
  14.     <target name="isTrue" if="scondition">  
  15.         <echo>is ture</echo>  
  16.     </target>  
  17.     <target name="isFalse" unless="scondition">  
  18.         <echo>is false</echo>  
  19.     </target>  
  20. </project>  

2.3、or 逻辑或 xor异或 (语法上与and类似) 
3、available 是否可用 
  1. <project name="testCondition">  
  2.     <path id="all.test.classes">  
  3.         <pathelement location="bin"/>  
  4.     </path>  
  5.     <target name="test">  
  6.         <condition property="scondition">  
  7.             <!--在指定的classpath路径下是否存在资源 TestTest.class-->  
  8.             <available resource="TestTest.class">  
  9.                 <classpath refid="all.test.classes" />  
  10.             </available>  
  11.         </condition>  
  12.         <antcall target="isTrue">  
  13.         </antcall>  
  14.         <antcall target="isFalse">  
  15.         </antcall>  
  16.     </target>  
  17.     <target name="isTrue" if="scondition">  
  18.         <echo>is ture</echo>  
  19.     </target>  
  20.     <target name="isFalse" unless="scondition">  
  21.         <echo>is false</echo>  
  22.     </target>  
  23. </project>  

4、isset 指定属性是否存在 
  1. <project name="testCondition">  
  2.     <!--属性也可以通过ant参数-D来设置-->  
  3.     <property name="name" value="this is name" />  
  4.     <target name="test">  
  5.         <condition property="scondition">  
  6.             <!--如果属性name不存在则返回false-->  
  7.             <isset property="name" />  
  8.         </condition>  
  9.         <antcall target="isTrue">  
  10.         </antcall>  
  11.         <antcall target="isFalse">  
  12.         </antcall>  
  13.     </target>  
  14.     <target name="isTrue" if="scondition">  
  15.         <echo>is ture</echo>  
  16.     </target>  
  17.     <target name="isFalse" unless="scondition">  
  18.         <echo>is false</echo>  
  19.     </target>  
  20. </project>  

5、equals 是否相等 
  1. <project name="testCondition">  
  2.     <!--属性也可以通过ant参数-D来设置-->  
  3.     <property name="name" value="this is name" />  
  4.     <target name="test">  
  5.         <condition property="scondition">  
  6.             <!--如果arg1的值与arg2的值相等返回true,否则为false-->  
  7.             <equals arg1="${name}" arg2="this is name" />  
  8.         </condition>  
  9.         <antcall target="isTrue">  
  10.         </antcall>  
  11.         <antcall target="isFalse">  
  12.         </antcall>  
  13.     </target>  
  14.     <target name="isTrue" if="scondition">  
  15.         <echo>is ture</echo>  
  16.     </target>  
  17.     <target name="isFalse" unless="scondition">  
  18.         <echo>is false</echo>  
  19.     </target>  
  20. </project>  

6、filesmatch 比较文件 
  1. <project name="testCondition">  
  2.     <target name="test">  
  3.         <condition property="scondition">  
  4.             <!--如果file1所代表的文件与file2所代表的文件相等返回true,否则为false-->  
  5.             <filesmatch file1="testfile1.txt" file2="testfile2.txt" />  
  6.         </condition>  
  7.         <antcall target="isTrue">  
  8.         </antcall>  
  9.         <antcall target="isFalse">  
  10.         </antcall>  
  11.     </target>  
  12.     <target name="isTrue" if="scondition">  
  13.         <echo>is ture</echo>  
  14.     </target>  
  15.     <target name="isFalse" unless="scondition">  
  16.         <echo>is false</echo>  
  17.     </target>  
  18. </project>  
相关文章
|
11月前
Makefile基础教程(条件判断语句)
Makefile基础教程(条件判断语句)
188 0
|
11月前
|
Python
python之if语句的单分支,双分支,多分支,if逻辑运算符or,if逻辑运算符and,if语句的嵌套的定义及其使用方法
python之if语句的单分支,双分支,多分支,if逻辑运算符or,if逻辑运算符and,if语句的嵌套的定义及其使用方法
172 0
|
3月前
|
Kotlin
Kotlin流程控制、循环
Kotlin流程控制、循环
|
4月前
|
编译器 C语言
Makefile条件判断
Makefile条件判断
31 0
|
9月前
|
Apache
hooks为什么不能在条件语句中使用,如果修改源码,怎么能让它支持条件语句?
hooks为什么不能在条件语句中使用,如果修改源码,怎么能让它支持条件语句?
69 1
|
4月前
|
前端开发 JavaScript
if else条件判断里使用hooks有什么问题
if else条件判断里使用hooks有什么问题
|
11月前
makefile 条件判断语句
makefile 条件判断语句
72 0
|
Java Shell
Shell基础学习---2、运算符、条件判断、流程控制
Shell基础学习---2、运算符、条件判断、流程控制
|
前端开发 JavaScript
web前端-JavaScript流程控制语句(条件判断,条件分支和循环语句)
web前端-JavaScript流程控制语句(条件判断,条件分支和循环语句)
144 0