ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harkness, David" <>
Subject RE: How to execute task depending on input from command line
Date Mon, 24 Nov 2003 22:16:47 GMT
Jhon wrote:
> I want to execute certain task depending upon which option
> has selected by user during execution of build.xml.
> for eg. if user inputs "dev", then I want to do dev
> deployment by calling corresponding task. if user inputs
> "stage", then I want to do stage deployment by calling corr. task.
> I know I can use <input> task to get user input. But not able
> to understand how can I check the condition if user input is equal 
> to "dev" or "stage". 
> Can any body tell me how can I call targets depending on
> specific conditions ?

First, the user can specify the property through the command line by
using -D: "ant ... -Denv=dev". Now, to execute different targets, you
can use a mix of the "if" condition on targets and the <condition> task:

  <target name="build" depends="init, build-dev"> ... </target>

  <target name="init" ...>
    <condition property="">
      <equals arg1="${env}" arg2="dev"/>

  <target name="build-dev" if=""> ... </target>

Another option is to use <antcall> and the "env" property to call the
correct target:

  <antcall target="build-${env}"/>

I haven't tried either of these completely -- just various pieces. Our
build process only reads in different properties files based on the
environment, and that's easy:

  <property file="build-${env}.properties"/>

So, YMMV. Good luck!

David Harkness
Sr. Software Engineer
Sony Pictures Digital Networks
(310) 482-4756

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

View raw message