ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duane Morin" <duane.mo...@db.com>
Subject Setting <path id=...> after invoking a target
Date Thu, 26 Sep 2002 18:45:04 GMT
Hello everyone,

Currently I have a project that has a build.properties file that looks 
like this:

libdir=${env.CHECKOUTAREA}/lib
builddir=${env.CHECKOUTAREA}/build
...

and so on.  User is expected to specify CHECKOUTAREA before running Ant. 
My build.xml then looks like this:

<property file="build.properties"/>

<path id="compile.classpath">
 <fileset dir="${libdir}">
   <include name="**/*.jar"/>
 </fileset>
</path>

(Actually the compile.classpath includes a bunch more stuff but I'm 
shortening.)

This works well for us.  Anybody that needs to create a new target that 
involves java compilation can then just invoke compile.classpath.


Ok, enough setup, here's my question.  If CHECKOUTAREA is not set, 
build.properties will blindly set the properties incorrectly.  I would 
like to write a target that fails if the environment variable is not set, 
and only if it does not fail, then go ahead and load the properties.  So I 
have this:

<target name="setProperties">
 <fail message="Please set CHECKOUTAREA" unless="env.CHECKOUTAREA"/>
 <property file="build.properties"/>
</target>

(I removed the earlier call to <property file>)

This works.  The problem is that the <path id=compile.classpath> block has 
already been executed at this point, with bad information because it runs 
at a time when <property file="build.properties"> has not yet run.  But if 
I put the <path> identifier inside the setProperties target, then no one 
else can use it.

In this particular example I've just realized that I can fix it -- I can 
load up the build.properties file first and then check to see whether the 
env variables were set, because if they're not, I'm failing anyway.  But I 
would like to ultimately replace that "just fail if they're not set" with 
"if they're not set, query the user for them interactively" and I think 
the problem would be the same -- waiting on <path id> until Ant has all 
the necessary information.

Anybody have any thoughts for me?

Thanks very much!

Duane

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message