ant control statements

来源:互联网 发布:淘宝网完美芦荟胶 编辑:程序博客网 时间:2024/05/21 10:46


Loop

The 'loop' task required ant-contrib package, please download from

http://ncu.dl.sourceforge.net/project/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip


Loop all .txt file in a folder, and take action on each file


    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />    <target name="loopfolder">        <for param="filename">            <path>=>                <fileset dir="${folder}" excludes="test.txt" includes="*.txt" />            </path>            <sequential>                <echo message="@{filename}"/>            </sequential>        </for>    </target>



Call Another Target


    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />    <target name="loopfolder">        <for param="filename">            <path>=>                <fileset dir="${folder}" excludes="test.txt" includes="*.txt" />            </path>            <sequential>                <echo message="@{filename}"/>                <antcall target="fileaction"/>            </sequential>        </for>    </target>    <target name="fileaction">        <property name="infile" value="${data.dir}/demo.txt"/>        <echo message="${infile}"/>    </target>


Call Another Target with parameters passing

    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />    <target name="loopfolder">        <for param="filename">            <path>=>                <fileset dir="${folder}" excludes="test.txt" includes="*.txt" />            </path>            <sequential>                <echo message="@{filename}"/>                <antcall target="fileaction">                    <param name="infile" value="@{filename}"/>                </antcall>            </sequential>        </for>    </target>    <target name="fileaction">        <property name="infile" value="${data.dir}/demo.txt"/>        <echo message="${infile}"/>    </target>


If-Then-Else

The 'if' task required ant-contrib package, please refer to 'Loop' task

        <taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />        <if>            <filesmatch file1="${infile}" file2="${outfile}"/>        <then>            <echo message="File ${infile} and file ${outfile} are same" />        </then>        <else>            <echo message="WARNING: File ${infile} and file ${outfile} are same" />        </else>        </if>


Failed a build

        <taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />        <if>            <filesmatch file1="${infile}" file2="${outfile}"/>        <then>            <echo message="File ${infile} and file ${outfile} are same" />        </then>        <else>            <fail message="Build failed because file ${infile} and file ${outfile} are not matched." />        </if>



ant.project.name

This is global project name, its value is define in 'project' element.



<project name="TestProject" default="compile" basedir=".">        <property name="yourprojectname"     value="${ant.project.name}"/>        ...</project>




0 0
原创粉丝点击