You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Brian Murray <br...@vanderbilt.edu> on 2002/04/02 17:53:58 UTC

Please clarify a point about properties

I'm trying to set up a precedence for setting properties as follows:
command-line-->environment-->file. 
In searching the archives for some information about setting properties
I saw the following statement which didn't seem accurate to me:

>> I would like to define default properties in a
>> property file and then "override" them from the
>> environment. I have found two mechanisms for
>> accomplishing this. The first is to use the
>> <condition> clause, the second is to use "if"
>> and "unless" attributes on targets that do <property>
>> tasks.
>>
> <property environment="env"/>
> <property name="my.desired.prop" value="${env.WHATEVER}"/>
> <property file="default.properties"/>
>
> then define my.desired.prop in default.properties.  It will be
"overridden"
> (which is a weird term, when its actually being set first instead of
being
> overwritten).


Now I'm fuzzy on the whole property thing, but it seems like
  <property name="my.desired.prop" value="${env.WHATEVER}"/>
Would set "my.desired.prop" to the STRING "${env.WHATEVER}" if WHATEVER
was not a defined environment variable.  Therefore, any attempt to set
"my.desired.prop" in the "default.properties" file would fail because
"my.desired.prop" would already be set.  

Am I off base?

Brian Murray
Vanderbilt University

Brian Murray
Vanderbilt University


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please clarify a point about properties

Posted by Diane Holt <ho...@yahoo.com>.
--- Erik Hatcher <ja...@ehatchersolutions.com> wrote:
> > Except you wouldn't actually need to override it that way, since it's
> > an environment variable, so you don't need to do it as a define --
> > just set it in your env. (To do it on the fly, just do
> > 'WHATEVER=my_value ant' [except under funky DOS, you have to do
> > 'set WHATEVER=my_value && ant'].)
> 
> Agreed - I was just showing how to override an environment setting,
> thats all.  Its very likely you may want it set in your environment,
> yet override it on a per-build basis for some reason.

That's what the above does -- just sets it for the invocation (except, as
usual, under funky DOS, since there's no distinction between a
set-in-the-shell var and an exported one, so you have to do:
C:\blah\blah> set WHATEVER=my_value && ant && set WHATEVER=

> > If you don't want to use the "env." property names throughout your
> > build file, just reassign it to another name once it has a value.
> 
> But the question is: how do I craft it such that I don't have
> env.WHATEVER in my properties file.  I'd rather have simply
> whatever.prop listed in my properties file, without the env prefix.
> Can you craft an example that shows that?

If you don't want to set them in a props file, then you're going to have
to set the default values for them in your build file. (Okay, not *have*
to, since you could conceivably have an rc file that sets up -D's for them
to pass on the Ant command-line, but that's just getting silly :)

And if you don't want to use the "env." names throughout the build, then
either convert their names in the build file as well, or have a props file
that does the name conversion. (The "or" being possible only if you don't
mean you don't want any reference to the "env." property anywhere in a
props file at all, even on the value side.)

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please clarify a point about properties

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
----- Original Message -----
From: "Diane Holt" <ho...@yahoo.com>
To: "Ant Users List" <an...@jakarta.apache.org>
Sent: Wednesday, April 03, 2002 11:46 AM
Subject: Re: Please clarify a point about properties


> --- Erik Hatcher <ja...@ehatchersolutions.com> wrote:
>
> > And use env.WHATEVER in your default.properties file as the property to
> > set there. And internally use that property name internally to your
> > build file where needed and override from the command-line
> > using -Denv.WHATEVER=<whatever>.
>
> Except you wouldn't actually need to override it that way, since it's an
> environment variable, so you don't need to do it as a define -- just set
> it in your env. (To do it on the fly, just do 'WHATEVER=my_value ant'
> [except under funky DOS, you have to do 'set WHATEVER=my_value && ant'].)

Agreed - I was just showing how to override an environment setting, thats
all.  Its very likely you may want it set in your environment, yet override
it on a per-build basis for some reason.

> > I prefer not to use "env." properties internally and reassign them to
> > non-enviromental looking names - if you wanted to do that in this case
> > you'd have to resort to a temporary property to act as an intermediate
> > placeholder, I think.
>
> If you don't want to use the "env." property names throughout your build
> file, just reassign it to another name once it has a value.

But the question is: how do I craft it such that I don't have env.WHATEVER
in my properties file.  I'd rather have simply whatever.prop listed in my
properties file, without the env prefix.  Can you craft an example that
shows that?

    Erik



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please clarify a point about properties

Posted by Diane Holt <ho...@yahoo.com>.
--- Erik Hatcher <ja...@ehatchersolutions.com> wrote:

> And use env.WHATEVER in your default.properties file as the property to
> set there. And internally use that property name internally to your
> build file where needed and override from the command-line
> using -Denv.WHATEVER=<whatever>.

Except you wouldn't actually need to override it that way, since it's an
environment variable, so you don't need to do it as a define -- just set
it in your env. (To do it on the fly, just do 'WHATEVER=my_value ant'
[except under funky DOS, you have to do 'set WHATEVER=my_value && ant'].)
 
> I prefer not to use "env." properties internally and reassign them to
> non-enviromental looking names - if you wanted to do that in this case
> you'd have to resort to a temporary property to act as an intermediate
> placeholder, I think.

If you don't want to use the "env." property names throughout your build
file, just reassign it to another name once it has a value.

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Please clarify a point about properties

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
----- Original Message -----
From: "Brian Murray" <br...@vanderbilt.edu>
To: <an...@jakarta.apache.org>
Sent: Tuesday, April 02, 2002 10:53 AM
Subject: Please clarify a point about properties


> I'm trying to set up a precedence for setting properties as follows:
> command-line-->environment-->file.
> In searching the archives for some information about setting properties
> I saw the following statement which didn't seem accurate to me:

Yes, there is definitely a flaw with that example, thanks for pointing that
out.

How about this?

<property environment="env"/>
<property file="default.properties"/>

And use env.WHATEVER in your default.properties file as the property to set
there.  And internally use that property name internally to your build file
where needed and override from the command-line
using -Denv.WHATEVER=<whatever>.

I'm sure there are other ways to do this with a cleaner property name.  I
prefer not to use "env." properties internally and reassign them to
non-enviromental looking names - if you wanted to do that in this case you'd
have to resort to a temporary property to act as an intermediate
placeholder, I think.

    Erik

>
> >> I would like to define default properties in a
> >> property file and then "override" them from the
> >> environment. I have found two mechanisms for
> >> accomplishing this. The first is to use the
> >> <condition> clause, the second is to use "if"
> >> and "unless" attributes on targets that do <property>
> >> tasks.
> >>
> > <property environment="env"/>
> > <property name="my.desired.prop" value="${env.WHATEVER}"/>
> > <property file="default.properties"/>
> >
> > then define my.desired.prop in default.properties.  It will be
> "overridden"
> > (which is a weird term, when its actually being set first instead of
> being
> > overwritten).
>
>
> Now I'm fuzzy on the whole property thing, but it seems like
>   <property name="my.desired.prop" value="${env.WHATEVER}"/>
> Would set "my.desired.prop" to the STRING "${env.WHATEVER}" if WHATEVER
> was not a defined environment variable.  Therefore, any attempt to set
> "my.desired.prop" in the "default.properties" file would fail because
> "my.desired.prop" would already be set.
>
> Am I off base?
>
> Brian Murray
> Vanderbilt University
>
> Brian Murray
> Vanderbilt University
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>