You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Pugh, Eric" <EP...@MuseumCompany.com> on 2001/09/18 17:26:11 UTC

RE: Passing in parameters (IF statement question)

I guess after reading and playing with some of the changes suggested, I am
getting closer to defining what i want!

I took Erik's suggestion, and created a batch file wrapper.  I have a task
called compare that invokes Beyond Compare to do a comparison of some file
directories.  My batch file takes in a "short name" for each enviroment.  In
other workds pl means production live.  ps means production stage.  I have
properties definied in my build.xml:
	${ps}  = \\production\stage
	${pl}  = \\production\live

These two parameters are passed into my ant compare task via the batch file.
Excellent so far, I can call bc.cmd ps pl and ant will get called with two
paramters set:  ant compare -Denviroment1=ps -Denviroment2=pl.  Then in my
ant task that exec's the BeyondCompare.exe I pass the two short names:
${enviroment1}.  However, what I am now discovering is that I am executing
this command:  
	c:\beyondcompare.exe pl ps.  
NOT
	c:\beyondcompare.exe \\production\live  \\production\stage

What I really want is to have some sort of IF statement that says
	IF ${enviroment1} = "ps" then
		${enviroment1} = ${ps}
	END if

This kind of scripting I know has been banned from ANT2, under the theory
that there are plenty of scripting tools.  So what have people done to make
this kind of functionality work?  Use the BSF stuff?

Eric

-----Original Message-----
From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com]
Sent: Tuesday, September 18, 2001 10:19 AM
To: ant-user@jakarta.apache.org
Subject: Re: Passing in parameters


If you truly mean "environment" variables in the operating system sense of
the term, you can set environment variables and access them via the Ant
property mechanism.   Check out the <property environment="...."/>
capability.

You have two options that I can suggest: 1) use the <property> task as
described above.  2) Write a custom wrapper script (this would be pretty
easy)

    Erik


----- Original Message -----
From: "Pugh, Eric" <EP...@MuseumCompany.com>
To: <an...@jakarta.apache.org>
Sent: Tuesday, September 18, 2001 6:30 AM
Subject: RE: Passing in parameters


> In response to the two earlier replys....:
>
> 1) I am trying to pass an enviroment variable into ANT.  I want to copy a
> series of images and files to a webserver, and want to pass the name of
the
> webserver into ANT.  What I have done is just tack on a ton of methods, so
> instead of:
> ant deployAllImages webserver1
>
> I have multiple methods
> ant deployAlllImages-webserver1
> ant deployAlllImages-webserver2
> ant deployAlllImages-webserver3
>
> 2) The reasons I don't want to use the -D method is because I want to turn
> over the build/deploy scripts to a less technical, non java developer.
And
> requireing things like -D I think is going to be weird.  I guess I could
> have ant deployAllImages -Dserver=webserver1, but that is a long command
> line to remember.  And with multiple parameters, say deploy -Dtype=images
> -Dserver=webserver1 seems clumsier.  I don't want to create wrappers
because
> that is more to maintain, but maybe it is worth it.
>
> Eric
>
> -----Original Message-----
> From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com]
> Sent: Monday, September 17, 2001 8:16 PM
> To: ant-user@jakarta.apache.org
> Subject: Re: Passing in parameters
>
>
> What's wrong with -D?
>
> And how do you propose for Ant to support multiple targets on the
> command-line if targets and parameters are specified the same way?
>
> How about writing your own wrapper script that does the "-D" under the
hood
> and only allows a single target to be specified?
>
>     Erik
>
>
> ----- Original Message -----
> From: "Pugh, Eric" <EP...@MuseumCompany.com>
> To: <an...@jakarta.apache.org>
> Sent: Monday, September 17, 2001 3:17 PM
> Subject: Passing in parameters
>
>
> > Is it possible to pass in parameters to ant?  Or is that completely
> against
> > the philosphy?
> >
> > I want to be able to pass in an enviroment parameter that does require
the
> > use of -Denviroment=stage.  Instead I want to be able to do:
> >
> > ant myproject stage
> > or
> > ant myproject live
> >
> > and so forth....
> >
> > I didn't seem to find anything directly related in the mail archives....
> >
> > ERic Pguh
> >
>

RE: Passing in parameters (IF statement question)

Posted by Diane Holt <ho...@yahoo.com>.
Eric,

It's a little hard to advise you, since you haven't given much detail on
what your build-file does (eg., what effect setting your "environmentN"
properties has on the build). I'm not sure why you need the batch-file or
what your in-house task does, but if you want to keep going with what you
have so far, the question is: Why are you going through ${environment1} in
your batch-file instead of just transforming the command-line "ps" to
"\\production\stage" to begin with? (My suspicion is you might be going a
long way around to do something that could be done more easily.) In any
case, if you're using Ant 1.4, you can use the <condition> task to set the
value of your "ps", "pl", etc. properties by using the <equal> tag to test
what ${environment1} is set to (although, again, I suspect you may be
going down a more convoluted path than you need to).

Diane

--- "Pugh, Eric" <EP...@MuseumCompany.com> wrote:
> I guess after reading and playing with some of the changes suggested, I
> am getting closer to defining what i want!
> 
> I took Erik's suggestion, and created a batch file wrapper.  I have a
> task called compare that invokes Beyond Compare to do a comparison of
> some file directories.  My batch file takes in a "short name" for each
> enviroment. In other workds pl means production live.  ps means
> production stage.  I have properties definied in my build.xml:
> 	${ps}  = \\production\stage
> 	${pl}  = \\production\live
> 
> These two parameters are passed into my ant compare task via the batch
> file. Excellent so far, I can call bc.cmd ps pl and ant will get called
> with two paramters set:  ant compare -Denviroment1=ps -Denviroment2=pl.
> Then in my ant task that exec's the BeyondCompare.exe I pass the two
> short names: ${enviroment1}.  However, what I am now discovering is that
> I am executing this command:  
> 	c:\beyondcompare.exe pl ps.  
> NOT
> 	c:\beyondcompare.exe \\production\live  \\production\stage
> 
> What I really want is to have some sort of IF statement that says
> 	IF ${enviroment1} = "ps" then
> 		${enviroment1} = ${ps}
> 	END if
> 
> This kind of scripting I know has been banned from ANT2, under the
> theory that there are plenty of scripting tools.  So what have people
> done to make this kind of functionality work?  Use the BSF stuff?
> 
> Eric


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



__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/