ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shackelford, John-Mason" <Sha...@ncs.com>
Subject RE: loadproperties gotcha
Date Tue, 15 Oct 2002 15:32:48 GMT
Stefan,

> Both tasks use Properties#load(InputStream)

Ah, then this explains the behavior. When Ant loads a property file it is
just pulling key-value pairs out of a HashTable. When a property is
previously defined normal  substitution occurs so that:

my.property.one = foo
my.property.two = ${my.property.one} bar

(my.property.two is now 'foo bar')

I use this all the time to good effect and assumed that since I am seeing
normal ant substation a property that has already been set would not be
overridden. But the behaviour of HashTable is exactly opposite that of Ant:
subsequent key-value pairs always replace the former ones where an existing
key already exists. My first thought was then to suggest, for the sake of
consistency--on this admittedly minor point--that we simply override the
put() in a Properties subclass to mimic the behavior we expect from Ant.

Then it occurs to me this morning: if we are adding properties only after
having loaded the HashTable we have no guarantee that the properties are
truly added in the order specified by the property file, which seems odd to
me since it means I've been incredibly lucky in nearly 10k + lines of
buildfiles and scores of properties files I've written in the past six
months. 

I knew I had adopted the practice of property composition within property
files after having read something suggesting it. I didn't see anything in
the current docs about thiit though and I took a quick look through _Java
Tools for Extreme Programming_ and _Ant: The Definitive Guide_ but didn't
see it there either.

Then I found this scrap from a tomcat buildfile:
(http://jakarta.apache.org/tomcat/tomcat-4.0-doc/appdev/build.xml.txt)

  You will note below that property values can be composed based on the
  contents of previously defined properties.  This is a powerful technique
  that helps you minimize the number of changes required when your
development
  environment is modified.  Note that property composition is allowed within
  "build.properties" files as well as in the "build.xml" script.

While one example hardly makes a case, it does seem to me that this is
something of an idiom, but unless I am being dense or have misunderstood you
it really isn't guaranteed to work the way we are accustomed to thinking
about it.

John-Mason Shackelford

Software Developer
NCS Pearson - Measurement Services
2510 North Dodge St.
Iowa City, IA 52245
319-354-9200x6214
shacjo@ncs.com



-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org] 
Sent: Monday, October 07, 2002 5:46 AM
To: ant-user@jakarta.apache.org
Subject: Re: loadproperties gotcha


On Fri, 4 Oct 2002, John-Mason Shackelford <ShacJo@ncs.com> wrote:

> I need to look at the source to confirm, but it looks to me like 
> <loadproperties> does not behave as <property> in that when two 
> identical properties occur in the same file the last rather than the 
> first value is set.

Having looked at the source: you may be right or wrong 8-).

Both tasks your Properties#load(InputStream) and I'm not sure which one is
going to be added to the resulting Properties object if your properties file
contains the same key multiple times.  I don't think this is defined at all.

Stefan

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>

**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message