I'm using Ant instead of shell scripts. So I _know_ this is going to be
hard work, but in the big picture it's useful to me (I have an Ant
task that's usable from either the command line or callable from the
main Ant build).
What I need is to set a property to either a literal string or an empty
string, depending on the presence of a command line flag (either
setting or not setting a property, with the -D option). Then I can use
my property "thing.suffix" like this:
<property name="thingname" value="${thing.root}${thing.suffix}" />
Obviously in Ant then _not_ setting the property is a totally different
situation to setting it to an empty string. I don't ever want a
thingname of "foobar${thing.suffix}"
I have this working, but the downside is that it needs two extra
targets for every property!
<target name="sp-thing-t" if="thingflag" >
<property name="thing.suffix" value="-thingified" />
</target>
<target name="sp-thing-f" unless="thingflag" >
<property name="thing.suffix" value="" />
</target>
<target name="build" depends="sp-thing-t, sp-thing-f"
I have so much "thing-1 and thing-2" around that my source is starting
to look like Dr Seuss.
Is there a cleaner way of doing this? I looked at using <condition>
but that only seems to let me set a property to a boolean, not a
literal string. I can use it to make complex choices, but I still need
my pair of complementary filtered targets to map this onto the strings.
Thanks for any advice
Roedy Green - 17 Feb 2006 03:29 GMT
>I have this working, but the downside is that it needs two extra
>targets for every property!
I felt like Yosemite Sam trying to get ANT to simply do conditional
copies without multiple steps and phony targets.
The goofy thing is ANT does not even have an XML grammar or verifier..
It is not true XML. We have all the pain and not much of the gain.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.