On Jan 27, 2004, at 6:45 PM, Chad Woolley wrote:
I'm looking for a simple way to allow these differences to be
configurable, but still have defaults. Specifically, I'd like the
default to come from the Ant properties file, but be overridden by
environment variables, if they exist. This way, if people use the
default, they don't have to make any env vars, but if they insist on
being different, all they need to do is set the appropriate env var.
We store the properties file in CVS, so it gets overwritten with a
full checkout from CVS, so modifying the properties file isn't a good
option.
I currently do it by making a dependency target for each property,
like this:
!-- Get the wl.home property from either the environment or
properties file --
target name=get.wl.home
condition property=wl.home value=${env.WL_HOME}
isset property=env.WL_HOME /
/condition
condition property=wl.home value=${properties.wl.home}
isset property=properties.wl.home /
/condition
echo message=WL_HOME property = ${wl.home}/
/target
However, this is a pain because I have to make a custom target like
this for each different property.
Is there a more elegant way to approach this problem, preferably in a
way that doesn't require a custom task for each different property?
Yes, there is a more elegant way. Keep in mind that properties in Ant
are immutable. This really helps with this type of configuration, in
fact.
Have a look at how I structured the build file for JavaDevWithAnt:
http://www.ehatchersolutions.com/JavaDevWithAnt - there are several
properties files loaded and also environment variables. You never need
to use condition to do these kinds of tricks. I actually prefer to
put defaults directly into the build file and use properties files to
override them on a per-user/-environment basis. Like this:
Just use wl.home in your .properties files. And do this:
property file=${user.home}/.build.properties/
property name=wl.home location=some default value/
If you want to use environment variables for overrides, it can be a
little trickier. See the JavaDevWithAnt build file for lots to do with
Ant properties. Again, I rarely (almost never) use condition.
Erik
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]