ant conditional judgment condition

basic elements: istrue isfalse not and or xor available isset equals  filesmatch
    1、istrue isfalse:断言 真 假

	<!-- istrue isfalse: assert true or false -->
	<target name="test">
		<!-- Set value to scondition, istrue, assert true -->
		<condition property="scondition">
			<!-- istrue is set to false, so set scondition to false-->
			<istrue value="false" />
		</condition>
		<!-- Call the two targets isTrue and isFalse-->
		<antcall target="isTrue">
		</antcall>
		<antcall target="isFalse">
		</antcall>
	</target>
	<!-- If conditional judgment, execution is established-->
	<target name="isTrue" if="scondition">
		<echo>is ture</echo>
	</target>
	<!-- unless conditional judgment, execute when not established -->
	<target name="isFalse" unless="scondition">
		<echo>is false</echo>
	</target>

 

    2. Logical operations
    2.1, not logical negation 

	<target name="test4">
		<condition property="scondition">
			<not>
				<istrue value="true" />
			</not>
		</condition>
		<antcall target="isTrue">
		</antcall>
		<antcall target="isFalse">
		</antcall>
	</target>

 
    2.2, and logical and
    2.3, or logical or xor exclusive or (similar to and in syntax)

	<!-- and, or the conditions in the 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">
            <!--If the property name does not exist, return false-->
            <isset property="name"/>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>

 
    5. Whether equals is equal
<project name="testCondition">
    <!--The property can also be set by ant parameter -D-->
    <property name="name" value="this is name"/>   
    <target name= "test">
        <condition property="scondition">
            <!--Return true if the value of arg1 is equal to the value of arg2, otherwise 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 compare files
<project name="testCondition">       
    <target name="test">
        <condition property="scondition">
            <!--If the file represented by file1 is equal to the file represented by file2 Returns true, otherwise 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>   


For more information, please refer to: http://ant.apache.org/manual/CoreTasks/conditions.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326987210&siteId=291194637