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 / April 2004

Tip: Looking for answers? Try searching our database.

ANT Condition Conditional if statement

Thread view: 
GIMME - 23 Apr 2004 23:41 GMT
Your choice of :

1. Modify the project below so that if that when the property
doit is assigned then the message "doit" is printed. OR

2. Modify the project below so that if the property of doit is
true then the message "doit" is printed, and nothing happens
otherwise.

Thanks.

<project name="inf" default="all" basedir="." >

<property name="doit" value="true" />

<target name="go" if="${doit}">
<echo message="doit"/>
</target>

<target name="all">
<antcall target="go"/>
</target>

</project
nobody important - 24 Apr 2004 11:14 GMT
Do you have a question? Is it a quest or a competition? Do you think you are
able to demand solutions?

Or do you simply not understand the description in the manual
(http://ant.apache.org/manual/using.html#targets) ?

If the latter is the case RTFM! Understand that "if" and "unless" do not
check the value of the property only whether the property is set or not.

A hint for you - apart from reading documentation - is to use commandline
properties: "ant -Ddoit=doit"

/nobody important

> Your choice of :
>
[quoted text clipped - 20 lines]
>
> </project
GIMME - 26 Apr 2004 17:44 GMT
I read the manual, and as I understood it, ANT was not behaving
like like the manual said it should.

I did experiment with it, as the manual describes, checking whether or
not *ANT properties* are set. It didn't work. I didn't even occur
to me to use command line properties instead.

The propose of writing the question the way I did was to make it
easy for someone to provide a useful response.

Also, it makes it so that anyone else having the same question
who searches on Google can find a working example.

> Do you have a question? Is it a quest or a competition? Do you think you are
> able to demand solutions?
nobody important - 27 Apr 2004 18:45 GMT
Well, did you get it to work for you?

> I read the manual, and as I understood it, ANT was not behaving
> like like the manual said it should.

No, ANT is just implemented that way - IMHO: really annoying. And you
cannot - in strict ANT - reset a property. And yes, IMHO, the manual is not
the quality of a bestseller, but neither are "man"-pages.

Your problem with ANT properties, whether they are set or not would possibly
be solved by considering the ANT property-holder as a modified
java.util.Properties (in which you cannot put already existing properties) -
an Ant property is set if it exist within the Properties - that is,
Properties.getProperty("propertyName") does not return null. You could use
Properties.containsKey("propertyName") for better understanding.

That is: ANT's " if='doit' " equals "Does the project in this Ant-file
contain a property key called 'doit' ?"
It's not: "Does the project in this Ant-file contain a property key called
'doit' and is the text value of that property 'true' " as there's no reason
to assume need of parsing any property for arbitrary values in specific
types: int, boolean, double.

The great fun is when you set a property to "false" and later, someone else
is trying to understand what the script is doing, misses the point, that a
property set to "false" (notice the "set to" here) means the property is
actually set, and any " if = 'property' " will be executed.

> I did experiment with it, as the manual describes, checking whether or
> not *ANT properties* are set. It didn't work. I didn't even occur
[quoted text clipped - 8 lines]
> > Do you have a question? Is it a quest or a competition? Do you think you are
> > able to demand solutions?

/nobody important


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.