You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jo...@mail.sprint.com on 2001/03/14 17:10:41 UTC
conditional execution on tasks
Is there any way to specify "only execute this *task* if the following
property is set"? It's like the if= and unless= attributes of target
fame, but it allows a finer grained control without forcing the
developer to write separate targets for each conditional...
Also, is there a conditional that will only execute a target(or task)
if a property equals _a_certain_value_? If not, this might be
worthwhile to have. The following situation makes me say so:
We are using a different set of properties for builds for each
environment we build for. Some of these environments are heterogenous
enough to require us to do additional processing. One option around
this would be to set properties unique to each environment, like
DEVELOPER_ENV=true
PRODUCTION_ENV=true
etc.
It still seems a little ugly to have all of these things floating
around. Is there a better way?
Thanks in advance,
John Casey
Re: conditional execution on tasks
Posted by Stefan Bodewig <bo...@apache.org>.
John D. Casey <Jo...@mail.sprint.com> wrote:
> Is there any way to specify "only execute this *task* if the
> following property is set"?
No - at least not for the built in tasks, you could add something like
this for your own tasks of course. Want me to add this to the Ant2
wish list?
> Also, is there a conditional that will only execute a target(or
> task) if a property equals _a_certain_value_?
No, but it has been asked for before. It has been declined by the
committers because we feared, this would open the door to
unmaintainable complexity too far. After test for equality we'd get
set inclusion, substring tests and so on.
You can achieve this test differently by doing something like this -
I'm testing whether property foo has the value bar:
<property name="dummy.${foo}" value="1" />
<target ... if="dummy.bar">
> We are using a different set of properties for builds for each
> environment we build for.
Maybe you can load your properties from a file? Something like
<property file="${env}.properties" />
where env would take the values production and developer on the
command line?
This could then include something like
do.deploy=1
in production.properties, but no line for this property in
developer.properties at all.
Just a random thought - but I think an approach like this would scale
to more than two types of environments better than testing for
property values.
Stefan