Ant 条件判断 condition

转载自ant 条件判断 condition

 

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"></antcall>  
  7.         <antcall target="isFalse"></antcall>          
  8.     </target>  
  9.     <target name="isTrue" if="scondition">  
  10.         <echo>is ture</echo>  
  11.     </target>  
  12.     <target name="isFalse" unless="scondition">  
  13.         <echo>is false</echo>  
  14.     </target>  
  15. </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"></antcall>  
  9.         <antcall target="isFalse"></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、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"></antcall>  
  10.         <antcall target="isFalse"></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>  

    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"></antcall>  
  13.         <antcall target="isFalse"></antcall>          
  14.     </target>  
  15.     <target name="isTrue" if="scondition">  
  16.         <echo>is ture</echo>  
  17.     </target>  
  18.     <target name="isFalse" unless="scondition">  
  19.         <echo>is false</echo>  
  20.     </target>  
  21. </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"></antcall>  
  10.         <antcall target="isFalse"></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>  

    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"></antcall>  
  10.         <antcall target="isFalse"></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>   

   
    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"></antcall>  
  8.         <antcall target="isFalse"></antcall>          
  9.     </target>  
  10.     <target name="isTrue" if="scondition">  
  11.         <echo>is ture</echo>  
  12.     </target>  
  13.     <target name="isFalse" unless="scondition">  
  14.         <echo>is false</echo>  
  15.     </target>  
  16. </project> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lincy521

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值