import-bot (20211) [Avatar] Offline
#1
[Originally posted by garagelogic]

Is there anyway short of using several messy targets to set a default value on
a property, and if an environment variable exists, overide the default. For
example, if project.home defaults to /Project/MyProject and env.PROJECT_HOME
is set to /Project/MyOtherProject, then project.home would point at
/Project/MyOtherProject. If the env value is not present, then it defaults to
/Project/MyProject.
import-bot (20211) [Avatar] Offline
#2
Re: Default Properties & Overriding
[Originally posted by ehatcher]

> Is there anyway short of using several messy targets to set a default value on
> a property, and if an environment variable exists, overide the default. For
> example, if project.home defaults to /Project/MyProject and env.PROJECT_HOME
> is set to /Project/MyOtherProject, then project.home would point at
> /Project/MyOtherProject. If the env value is not present, then it defaults to
> /Project/MyProject.

This question is best posed on the Ant user list (since its not specifically
related to our book), but since I'd probably answer on the user list too, I'll
do so here. smilie

Setting a default value of a property is simply this:

<property name="someProp" value="default value"/>

To "override" (or set first, actually, because properties are immutable) you
put the loading of property files prior to the setting of default values.

To override an environment variable, simply set the Ant property
"env.ENVIRONMENT_VAR_NAME" prior to loading environment variables using
<property environment="env"/> - same immutability mechanism applies.

Check out my JavaDevWithAnt project -
http://www.ehatchersolutions.com/JavaDevWithAnt - its chock full of examples
of using Ant properties, and with some experimentation you'll see how you can
override any of the properties at many levels.
import-bot (20211) [Avatar] Offline
#3
Re: Default Properties &amp; Overriding
[Originally posted by garagelogic]

> > Is there anyway short of using several messy targets to set a default
value on
> > a property, and if an environment variable exists, overide the default. For
> > example, if project.home defaults to /Project/MyProject and env.PROJECT_HOME
> > is set to /Project/MyOtherProject, then project.home would point at
> > /Project/MyOtherProject. If the env value is not present, then it
defaults to
> > /Project/MyProject.
>
> This question is best posed on the Ant user list (since its not specifically
> related to our book), but since I'd probably answer on the user list too, I'll
> do so here. smilie
>
> Setting a default value of a property is simply this:
>
> <property name="someProp" value="default value"/>
>
> To "override" (or set first, actually, because properties are immutable) you
> put the loading of property files prior to the setting of default values.
>
> To override an environment variable, simply set the Ant property
> "env.ENVIRONMENT_VAR_NAME" prior to loading environment variables using
> <property environment="env"/> - same immutability mechanism applies.
>
> Check out my JavaDevWithAnt project -
> http://www.ehatchersolutions.com/JavaDevWithAnt - its chock full of examples
> of using Ant properties, and with some experimentation you'll see how you can
> override any of the properties at many levels.

I guess my question was not clear. I want to overide a property based on the
existence of a environment variable. The goal is that *if* the environment
variable env.PROJECT_HOME exists, use this value for project.home. If it does
not exist, set it to a default value defined within the ANT script. I am
familiar with immutability, and use this to allow an optional property file to
set properties, but this scenario is not quite the same.
import-bot (20211) [Avatar] Offline
#4
Re: Default Properties &amp; Overriding
[Originally posted by steve_l]

the scenario is quite the same. Look at how we set the hostname on p448.