Quantcast

Reading environment variables in ant script directly

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Reading environment variables in ant script directly

Raja Nagendra Kumar
Hi,

Is it possible to read OS environment variables directly in ant script without the line

<property environment="evn"/>

As ant is java and by default all the ant variables would be passed to JRE on each java invocation, I am looking for a way to get the value of the property variables directly.

Why another line if I could avoid it. Also helps in managing few thing more smartly without this call each project.


Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Reading environment variables in ant script directly

Rez P

In short, no. You can test it for yourself by writing a simple ant script.  All system environment variables have to be preceded by "env.", otherwise, in the example below ${HOMEPATH} by itself is meaningless unless you have assigned a prior value to it. But the minute it's preceded by "env." it knows you're requesting something out of the system environment.  If you comment out, <property environment="env"/>, the script will work but ${env.HOMEPATH} will just echo as itself w/o a value.

 

<project name="test" basedir="." default="test-target">

  <target name="test-target">

 <property environment="env"/>
 <echo>User.Home=${env.HOMEPATH}</echo>

  </target>

</project>

 

 

 

> Date: Tue, 29 Dec 2009 22:56:32 -0800
> From: [hidden email]
> To: [hidden email]
> Subject: Reading environment variables in ant script directly
>
>
> Hi,
>
> Is it possible to read OS environment variables directly in ant script
> without the line
>
> <property environment="evn"/>
>
> As ant is java and by default all the ant variables would be passed to JRE
> on each java invocation, I am looking for a way to get the value of the
> property variables directly.
>
> Why another line if I could avoid it. Also helps in managing few thing more
> smartly without this call each project.
>
>
> Regards,
> Raja Nagendra Kumar,
> C.T.O
> www.tejasoft.com
> --
> View this message in context: http://old.nabble.com/Reading-environment-variables-in-ant-script-directly-tp26964622p26964622.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
     
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Reading environment variables in ant script directly

Raja Nagendra Kumar
Thank You Rez,

Are u aware of why such explicit  approach (of needing to use the task <property environment="env"/> ) was taken rather providing the environment properties directly.

It would be nice, if ant could consider to provide the environment variables implicitly including the conventions you mentioned on prefixing them with env.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reading environment variables in ant script directly

Joe Schmetzer
2009/12/30 Raja Nagendra Kumar <[hidden email]>:
> Are u aware of why such explicit  approach was taken rather providing the
> environment properties directly.
>
> It would be nice, if ant could consider to provide the environment variables
> implicitly including the conventions you mentioned on prefixing them with
> env.

Hi Raja,

That approach wouldn't work well with Ant's immutable properites. It
could lead to bugs that were hard to diagnose, and make build scripts
less portable.

For example, consider an ant script that used a property "libdir",
perhaps something like this:

    <property name="libdir" location="lib"/>

If Ant were to pick up environment variables directly, if this
particular property was defined in the external environment, then that
definition would take precedence, and the build would probably fail,
although the reason would not be immediatly obvious.

Regards,
Joe Schmetzer
Ant Script Library http://www.exubero.com/asl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Reading environment variables in ant script directly

Rez P
In reply to this post by Raja Nagendra Kumar

I'm not sure if there're any other reasons but to me it's very obvious so one can distinguish

${HOMEPATH} vs. ${env.HOMEPATH} as they're clearly 2 different animals, if you will.  How else Ant would know what you mean and how're you magically going to reference the system environment w/o "env."?

 

Even if there was a way to comment out <property environment="env"/>, it's no savings in memory or uncluttering your scripts!

 

Sorry, I really don't know if there's any other way to refer to system environment values, maybe someone else does?
 

> Date: Wed, 30 Dec 2009 10:14:14 -0800
> From: [hidden email]
> To: [hidden email]
> Subject: RE: Reading environment variables in ant script directly
>
>
> Thank You Rez,
>
> Are u aware of why such explicit approach was taken rather providing the
> environment properties directly.
>
> It would be nice, if ant could consider to provide the environment variables
> implicitly including the conventions you mentioned on prefixing them with
> env.
>
> Regards,
> Raja Nagendra Kumar,
> C.T.O
> www.tejasoft.com
> --
> View this message in context: http://old.nabble.com/Reading-environment-variables-in-ant-script-directly-tp26964622p26970528.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
     
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
http://clk.atdmt.com/GBL/go/171222985/direct/01/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reading environment variables in ant script directly

Raja Nagendra Kumar
In reply to this post by Joe Schmetzer
Sure joe, now I understand why we need to give a prefix. Joe, I was looking for why ant did not ant make all the environment variables available through some documented prefix notation rather by default rather than user adding this line in each build script.

<property environment="env"/>

Regards,
Nagendra
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reading environment variables in ant script directly

Antoine Levy Lambert
Hello Raja,

some ant scripts need access to environment variables but a lot of them
do not. So this leaves it to each build file developer to decide whether
he wants his ant property environment to include properties.

Now you can create easily a standard build file that you import
everywhere and containing the line <property environment="env"/>.

You may end up with other "boilerplate" declarations that you want in
all your build files.

Regards,

Antoine

Raja Nagendra Kumar wrote:

> Sure joe, now I understand why we need to give a prefix. Joe, I was looking
> for why ant did not ant make all the environment variables available through
> some documented prefix notation rather by default rather than user adding
> this line in each build script.
>
> <property environment="env"/>
>
> Regards,
> Nagendra
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Reading environment variables in ant script directly

Raja Nagendra Kumar
True Antonine.

I clearly understand that using of env is not to be encouraged and ant has a way to use them with care if one wants.

Infact, our internal Mobile Single Source Build Framework keeps this principle to keep our self more portable.

However, we still there is a need for access the common boiler plate ant script or ant properties which should exist on in system folders such ${user.home} or any of the currently exposed ant default properties. It is just one variable, we need to depend on. Only for such reason, we are doing a explicit evn property declaration and rest of them are pure ant.

Though it is one line (which is not too bad for us due to limited projects) for big enterprises with many projects, I was suggesting that why not ant  provide such custom properties though automatic support fetching the variables though some stand prefix such as evn.xxx etc.

Not sure, if we made our point clear to ant developers to see value of making by default environment variables available though a standard prefix, implicitly.

After all any framework should keep looking out for doing more with less of user code.. My suggestions come from this context.

Regards,
Nagendra
antoinell wrote
Hello Raja,

some ant scripts need access to environment variables but a lot of them
do not. So this leaves it to each build file developer to decide whether
he wants his ant property environment to include properties.

Now you can create easily a standard build file that you import
everywhere and containing the line <property environment="env"/>.

You may end up with other "boilerplate" declarations that you want in
all your build files.

Regards,

Antoine

Raja Nagendra Kumar wrote:
> Sure joe, now I understand why we need to give a prefix. Joe, I was looking
> for why ant did not ant make all the environment variables available through
> some documented prefix notation rather by default rather than user adding
> this line in each build script.
>
> <property environment="env"/>
>
> Regards,
> Nagendra
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Loading...