Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / February 2006

Tip: Looking for answers? Try searching our database.

Ant - handling user input command-line flags

Thread view: 
dingbat@codesmiths.com - 16 Feb 2006 15:25 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.