ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject RE: Perform a task according to property value
Date Mon, 08 Apr 2002 04:42:17 GMT
--- "Rahamim, Zvi (Zvi)" <zrahamim@avaya.com> wrote:
> The situation is like this:
> I have a property: p that its value can be a, b or c.
> If it is a, I want to call to target "A"
> If it is b, I want to call to target "B"
> If it is c, I want to call to target "C"
> How can I do it?

If you're running Ant1.4.1 (or 1.4), use the <condition> task. For
example:

  <target name="doTargs" depends="chkP,A,B,C"/>

  <target name="chkP">
    <condition property="runA">
      <equals arg1="${p}" arg2="a"/>
    </condition>
    <condition property="runB">
      <equals arg1="${p}" arg2="b"/>
    </condition>
    <condition property="runC">
      <equals arg1="${p}" arg2="c"/>
    </condition>
  </target>

  <target name="A" if="runA">
    <echo>Running target A...</echo>
  </target>

  <target name="B" if="runB">
    <echo>Running target B...</echo>
  </target>

  <target name="C" if="runC">
    <echo>Running target C...</echo>
  </target>

(Note: For better logging output for this sort of setup, I recommend you
use NoBannerLogger, so you don't get all those empty targetname-colon's.)

If you're running (or can run) Ant1.5alpha, and don't mind using a task
from ant-contrib (namely, <switch>), you can trim all that down
considerably. For example, if you don't really need separate "A", "B", and
"C" targets (ie., you don't need to ever run them directly), you can just
put the tasks that constitute what would be targets "A", "B", and "C"
directly under the <case> elements:

  <target name="whatever">
    <switch value="${p}">
      <case value="a">
        <echo>Put "a" tasks here...</echo>
      </case>
      <case value="b">
        <echo>Put "b" tasks here...</echo>
      </case>
      <case value="c">
        <echo>Put "c" tasks here...</echo>
      </case>
    </switch>
  </target>

Additionally, if one of "a", "b", or "c" is the default value, you can
eliminate one of the <case>'s and put in a <default> instead.

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

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


Mime
View raw message