ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <>
Subject RE: Perform a task according to property value
Date Mon, 08 Apr 2002 04:42:17 GMT
--- "Rahamim, Zvi (Zvi)" <> 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

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

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

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

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

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

(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 value="b">
        <echo>Put "b" tasks here...</echo>
      <case value="c">
        <echo>Put "c" tasks here...</echo>

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.



Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message