ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Burton" <bi...@progress.com>
Subject Re: Access environment variables
Date Wed, 18 Oct 2000 22:50:45 GMT
Hello,

Nils Olav SelÄsdal wrote:
> 
> > -----Original Message-----
> > From: Stefan Bodewig [mailto:bodewig@bost.de]
> > Sent: 17. oktober 2000 15:57
> > To: ant-user@jakarta.apache.org
> > Subject: Re: Access environment variables
> >
> >
> > >>>>> "PB" == Peter Breitling
> > <breitlip@informatik.tu-muenchen.de> writes:
> >
> >  PB> Hum, i feared that. But then i need a wrapper script and this is
> >  PB> not elegant. Is there a reason for this design?
> >
> > It's not Ant's design, Java doesn't provide access to environment
> > variables.
> >
> > Stefan
> 
> Hmm .. linux have the 'env' command, suppose you could create a script that
> makes
> lots of -Dvarable=$variable parameters to ant here...

Maybe like this?

# get environment variables except for PATH, CLASSPATH and MANPATH,
# quoting the values and adding the prefix "-D" to each one
ENVDEFS=`env |egrep -v '^PATH|^CLASSPATH|^MANPATH' |
         sed -e 's/=\(.*\)$/="\1"/' -e 's/^/-D/'`
java $ENVDEFS ...

I'm new to Ant but here's my attempt at a cross-platform way of loading
environment variables for Ant 1.1:

       <target name="loadenv">
         <!-- Write out environment variables to a properties file -->
         <property name="env.file" value="environment.properties" />
         <exec command="env" os="UNIX" output="${env.file}" />
         <exec command="cmd /c set" os="Windows_NT" output="${env.file}"
/>
         <exec command="command /c set" os="Windows" output="${env.file}"
/>
         <!-- Now, load the environment variables as properties -->
         <property file="${env.file}" />
         <delete file="${env.file}" verbose="false" />
       </target>

       <target name="prepare" depends="loadenv">
         ...
       </target>

Note that the os attributes above are probably wrong.

I was trying to configure a target that would cause the build to fail if
the environment variables failed to load i.e. ${ANT_HOME} not available
but couldn't figure out how to do it.  Using a target like:
       <target name="prepare" depends="loadenv" if="${ANT_HOME}"
         ...
       </target>
would not execute but the compile target that depended on that target
still ran.  So how can I cause the build to stop on some condition?

Thanks,
-Bill
-- 
Bill Burton
billb@progress.com
Progress Software Corporation

Mime
View raw message