You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Frank W. Zammetti" <fz...@omnytex.com> on 2005/02/28 18:56:58 UTC
Conditionals
This might be the last Ant question I ever have to ask (now, where is the
deed to that bridge in Brooklyn?!?)...
Is it possible, and if so how, to do conditionals? I'd like to have a way
basically on each task to say "if property A=value1, then run this task,
otherwise don't". I'm looking through the manual now but haven't come
across what seems to fit the bill.
Thank you once again!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by Mark Lundquist <ml...@comcast.net>.
Hi Frank,
On Feb 28, 2005, at 9:56 AM, Frank W. Zammetti wrote:
> This might be the last Ant question I ever have to ask (now, where is
> the
> deed to that bridge in Brooklyn?!?)...
>
> Is it possible, and if so how, to do conditionals? I'd like to have a
> way
> basically on each task to say "if property A=value1, then run this
> task,
> otherwise don't". I'm looking through the manual now but haven't come
> across what seems to fit the bill.
>
<target name="foo" if="some-property">
HTH,
—ml—
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Thanks Matt, I certainly see the problem.
I decided to take the path of least resistance, but I left myself an note
to revisit it later... I had a need to copy in certain files when doing a
production build, and certain others for a development build. So all I
wound up doing was have a set_development and set_production target, and
the set_production target on executes if the is_production property is
defined (set_development always executes). I put the comment in the
build.xml file, rather than the properties file.
Not perfect, but it was quick and easy and does what I need. It was only
three files, so not a nightmare in any case. I'll make it more elegant
later :)
Thanks to everyone that responded!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Mon, February 28, 2005 1:33 pm, Matt Benson said:
> --- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
> [SNIP]
>> So, is there a way to get this task...
>>
>> <propertyfile file="build.properties">
>> <entry key="build_number" default="0" type="int"
>> operation="+" value="1"
>> pattern="0000" />
>> </propertyfile>
>>
>> To NOT wipe out my comments? Thanks again, I'm
>> learning alot :)
>
> According to its doc, this task makes no effort to
> preserve comments. If you are familiar with the
> javadoc on the Properties class it doesn't take much
> of a leap to conclude that these are the facilities
> being used "under the hood", as it were. So the
> propertyfile task will inherit the limitations of the
> Properties class. You could implement this yourself
> in Ant... I would think you might find yourself using
> ant-contrib's math task as well as one of the several
> text replacement approaches available in Ant (my
> favorite is filterchains). Or you could always
> implement in Java or a compatible scripting language.
>
> -Matt
>
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>> On Mon, February 28, 2005 1:07 pm, Matt Benson said:
>> >
>> > --- "Frank W. Zammetti" <fz...@omnytex.com>
>> wrote:
>> >> Is it possible, and if so how, to do
>> conditionals?
>> >> I'd like to have a way
>> >> basically on each task to say "if property
>> A=value1,
>> >> then run this task,
>> >> otherwise don't". I'm looking through the manual
>> >> now but haven't come
>> >> across what seems to fit the bill.
>> >
>> > As others have suggested, you can use
>> ant-contrib's if
>> > task. However, the "Ant way" to do this is
>> described
>> > in the manual:
>> > http://ant.apache.org/manual/using.html#buildfile
>> >
>> > HTH,
>> > Matt
>> >
>> > __________________________________________________
>> > Do You Yahoo!?
>> > Tired of spam? Yahoo! Mail has the best spam
>> protection around
>> > http://mail.yahoo.com
>> >
>> >
>>
> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail:
>> user-unsubscribe@ant.apache.org
>> > For additional commands, e-mail:
>> user-help@ant.apache.org
>> >
>> >
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> user-unsubscribe@ant.apache.org
>> For additional commands, e-mail:
>> user-help@ant.apache.org
>>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by Matt Benson <gu...@yahoo.com>.
--- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
[SNIP]
> So, is there a way to get this task...
>
> <propertyfile file="build.properties">
> <entry key="build_number" default="0" type="int"
> operation="+" value="1"
> pattern="0000" />
> </propertyfile>
>
> To NOT wipe out my comments? Thanks again, I'm
> learning alot :)
According to its doc, this task makes no effort to
preserve comments. If you are familiar with the
javadoc on the Properties class it doesn't take much
of a leap to conclude that these are the facilities
being used "under the hood", as it were. So the
propertyfile task will inherit the limitations of the
Properties class. You could implement this yourself
in Ant... I would think you might find yourself using
ant-contrib's math task as well as one of the several
text replacement approaches available in Ant (my
favorite is filterchains). Or you could always
implement in Java or a compatible scripting language.
-Matt
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> On Mon, February 28, 2005 1:07 pm, Matt Benson said:
> >
> > --- "Frank W. Zammetti" <fz...@omnytex.com>
> wrote:
> >> Is it possible, and if so how, to do
> conditionals?
> >> I'd like to have a way
> >> basically on each task to say "if property
> A=value1,
> >> then run this task,
> >> otherwise don't". I'm looking through the manual
> >> now but haven't come
> >> across what seems to fit the bill.
> >
> > As others have suggested, you can use
> ant-contrib's if
> > task. However, the "Ant way" to do this is
> described
> > in the manual:
> > http://ant.apache.org/manual/using.html#buildfile
> >
> > HTH,
> > Matt
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> > For additional commands, e-mail:
> user-help@ant.apache.org
> >
> >
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Regarding the Ant way...
I could do what I want just by not defining a given property in my
properties file, that would be acceptable. However, I encountered a
problem doing that...
The first task in my build bumps up a build number in the properties file.
In doing so, it seems that any comments in the properties file are wiped
out. I wouldn't want to do conditionals this way unles I could have a
comment that says "uncomment this for build type A, comment it for type
B".
So, is there a way to get this task...
<propertyfile file="build.properties">
<entry key="build_number" default="0" type="int" operation="+" value="1"
pattern="0000" />
</propertyfile>
To NOT wipe out my comments? Thanks again, I'm learning alot :)
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Mon, February 28, 2005 1:07 pm, Matt Benson said:
>
> --- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
>> Is it possible, and if so how, to do conditionals?
>> I'd like to have a way
>> basically on each task to say "if property A=value1,
>> then run this task,
>> otherwise don't". I'm looking through the manual
>> now but haven't come
>> across what seems to fit the bill.
>
> As others have suggested, you can use ant-contrib's if
> task. However, the "Ant way" to do this is described
> in the manual:
> http://ant.apache.org/manual/using.html#buildfile
>
> HTH,
> Matt
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Can you point me at some doc for "conditional targets"? I'm not familiar
with that (I'm still relatively new to Ant). Thanks Jeffrey!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Mon, February 28, 2005 1:04 pm, Jeffrey E Care said:
> You can conditionally run targets, so one way would be to use conditional
> targets & antcall.
>
> Another way would be to use ant-contrib: it has support for conditional
> task execution.
>
> JEC
> --
> Jeffrey E. Care (carej@us.ibm.com)
> WebSphere Build SWAT Team Lead
> WebSphere Build Tooling Lead (Project Mantis)
> https://w3.opensource.ibm.com/projects/mantis
>
>
> "Frank W. Zammetti" <fz...@omnytex.com> wrote on 02/28/2005 12:56:58 PM:
>
>> This might be the last Ant question I ever have to ask (now, where is
> the
>> deed to that bridge in Brooklyn?!?)...
>>
>> Is it possible, and if so how, to do conditionals? I'd like to have a
> way
>> basically on each task to say "if property A=value1, then run this task,
>> otherwise don't". I'm looking through the manual now but haven't come
>> across what seems to fit the bill.
>>
>> Thank you once again!
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by Matt Benson <gu...@yahoo.com>.
--- "Frank W. Zammetti" <fz...@omnytex.com> wrote:
> Is it possible, and if so how, to do conditionals?
> I'd like to have a way
> basically on each task to say "if property A=value1,
> then run this task,
> otherwise don't". I'm looking through the manual
> now but haven't come
> across what seems to fit the bill.
As others have suggested, you can use ant-contrib's if
task. However, the "Ant way" to do this is described
in the manual:
http://ant.apache.org/manual/using.html#buildfile
HTH,
Matt
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by Jeffrey E Care <ca...@us.ibm.com>.
You can conditionally run targets, so one way would be to use conditional
targets & antcall.
Another way would be to use ant-contrib: it has support for conditional
task execution.
JEC
--
Jeffrey E. Care (carej@us.ibm.com)
WebSphere Build SWAT Team Lead
WebSphere Build Tooling Lead (Project Mantis)
https://w3.opensource.ibm.com/projects/mantis
"Frank W. Zammetti" <fz...@omnytex.com> wrote on 02/28/2005 12:56:58 PM:
> This might be the last Ant question I ever have to ask (now, where is
the
> deed to that bridge in Brooklyn?!?)...
>
> Is it possible, and if so how, to do conditionals? I'd like to have a
way
> basically on each task to say "if property A=value1, then run this task,
> otherwise don't". I'm looking through the manual now but haven't come
> across what seems to fit the bill.
>
> Thank you once again!
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
Re: Conditionals
Posted by Matt Benson <gu...@yahoo.com>.
--- Ninju Bohra <ni...@yahoo.com> wrote:
> I tried to make a suggest the ANT developers group
> that they could accomplish that exact capablility
> with about 4 lines of code.
>
> See:
>
http://issues.apache.org/bugzilla/show_bug.cgi?id=33105
>
> They rejected it :-(
If it makes you feel any better, the Ant committer who
resolved your issue WONTFIX, Dominique Devienne, was
the chief proponent of adding if/unless to all tasks
as you requested. This would be a case of "don't
shoot the messenger."
-Matt
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Conditionals
Posted by Ninju Bohra <ni...@yahoo.com>.
I tried to make a suggest the ANT developers group that they could accomplish that exact capablility with about 4 lines of code.
See: http://issues.apache.org/bugzilla/show_bug.cgi?id=33105
They rejected it :-(
Just use (and overuse) the <if> task from the ant-contrib project
"Frank W. Zammetti" <fz...@omnytex.com> wrote:
This might be the last Ant question I ever have to ask (now, where is the
deed to that bridge in Brooklyn?!?)...
Is it possible, and if so how, to do conditionals? I'd like to have a way
basically on each task to say "if property A=value1, then run this task,
otherwise don't". I'm looking through the manual now but haven't come
across what seems to fit the bill.
Thank you once again!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
---------------------------------
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.