ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier Gies <olivier.g...@bull.net>
Subject Re: Use of the "If else" condition in ANT
Date Tue, 05 Feb 2008 07:37:42 GMT
Hi Uday,

Here are 2 solutions for an if-else in Ant:

1) Using you just use plain Ant 1.7, you can use the <condition> task, 
combining 'if' and 'unless' target attributes with target dependencies, 
as follows:

<target name="main" depends="A, B"/>

<target name="A" if="condition.ok" depends="eval.condition">
    ...
</target>

<target name="B" unless="condition.ok" depends="eval.condition">
    ...
</target>

<target name="eval.condition">
    <condition property="condition.ok">
        <resourcecount count="1" when="ge">
            <fileset file="text_file.txt">
                <contains text="String to search" casesensitive="false"/>
            </fileset>
        </resourcecount>
    </condition>
</target>

2) The way I do it: just use ant-contrib's implementation of 
<if><then><else> :) (see: http://ant-contrib.sourceforge.net/)

Olivier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message