ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Weintraub" <qazw...@gmail.com>
Subject Re: conditional statements
Date Thu, 14 Feb 2008 22:07:25 GMT
In standard Ant, you use the <condition> task to set a property, then
you can use <antcall> to call a task.

<task name="if_else_task">
    <condition
         property="x.is.true">
         <istrue value="${x}"/>
    </condition>
    <antcall target="do_if_x_is_true"/>
    <antcall target="do_if_x_is_false"/>
    <echo>Yadda...</echo>
    <echo>Yadda...</echo>
    <echo>Yadda...</echo>
</target>

<target name="do_if_x_is_true"
    if="x.is.true">
    <echo>X is True!</echo>
</target>

<target name="do_if_x_is_false"
   unless="x.is.true">
   <echo>X is False!</echo>
</target>

A little complex, but that's how it's done.

AntContrib (as others have pointed out) has an <if> task:

<if>
    <istrue value="${x}"/>
    <then>
          <echo>X is True!</echo>
    </then>
    <else>
         <echo>X is False</echo>
    </else>
</if>


This is simpler, but you must include the ant-contrib-xxx.jar file in
your Ant's classpath, and include a <taskdef> task in your build.xml
file. See the AntContrib website for more information.

On Thu, Feb 14, 2008 at 2:42 PM, jonese <gigado@gmail.com> wrote:
> How would i do something like
>
>  if x = true{
>   stuff
>  }else{
>   other stuff
>  }
>
>  in ant? basically i want to see if a property is true and if it is do
>  x instructions, if it's false do y.
>
>  jonese
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>  For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

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


Mime
View raw message