ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <qazw...@gmail.com>
Subject Re: how to do conditional processing in ant
Date Fri, 17 Jul 2009 16:55:56 GMT
There are two general ways to do conditional processing. One is to use
the "if" or "unless" parameters on the task themselves:

<task name="copy">

    <!-- Common Copying -->
    <...>

    <!-- Test Which Environment -->
    <condition property="dev">
        <equals arg1="${envv}" = "dev"/>
    </condition>

    <condition property="uat">
        <equals arg1="${envv}" = "uat"/>
    </condition>

    <condition property="prod">
        <equals arg1="${envv}" = "prod"/>
    </condition>

   <!-- Call Each Environment and Attempt an Execution -->
   <antcall target="copy.dev"/>
   <antcall target="copy.uat"/>
   <antcall target="copy.prod"/>
</target>

<target name="copy.dev"
   if="dev">
   <...>
</target>

<target name="copy.uat"
   if="uat">
   <...>
</target>

<target name="copy.prod"
   if="prod">
   <...>
</target>


The above would execute the "correct" type of copying based upon the
value of the envv property.

If you use AntContrib
<http://ant-contrib.sourceforge.net/tasks/tasks/index.html>, you can
simplify the logic quite a bit:

<if>
    <equals arg1="${envv}" arg2="dev"/>
    <then>
       <copy.../>
    </then>
    <elseif>
        <equals arg1="${envv}" arg2="prod"/>
        <then>
           <copy .../>
       </then>
   </elseif>
        <equals arg1="${envv}" arg2="uat"/>
        <then>
            <copy .../>
        </then>
   </elseif>
</if>

-- 
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