ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: property set in sub-task not defined
Date Mon, 17 Mar 2003 20:46:09 GMT
Using pure Ant:

<target name="init" depends="-lib.dir.exists?, -set.lib.classpath">
  <property name="lib.classpath" value="" />
  ...
</target>

<target name="-lib.dir.exists?">
   <available file="${lib.dir}" type="dir"
              property="lib.dir.exists" />
</target>

<target name="-set.lib.classpath" if="lib.dir.exists" >
  <path id="lib.classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar" />
  </path>
  <property name="lib.classpath" refid="lib.classpath" />
</target>

Using Ant-contrib would be nicer of course. Maybe one day it will make it to
Ant: some committer seem to prefer spaghetti Ant as above than an <if>, but
maybe just maybe the wind is turning from recent posts on ant-dev... --DD

-----Original Message-----
From: Pedro Salazar [mailto:pedro-b-salazar@ptinovacao.pt] 
Sent: Monday, March 17, 2003 2:33 PM
To: Ant Users List
Subject: RE: property set in sub-task not defined

Hi,

yes the "depends" should work, but it's not nice using the "depends" (I
think) because there are some variables that I don't have yet (lib.dir),
that are set in my main target.

My real case that I'm working is making a content classpath of the
directory $(lib.dir) if it exists, and put it "" (blank) if not to avoid
the string "${lib.classpath}. 

I cannot use the <fileset> directly only without verifying that the
directory exists, otherwise it throws an error. So, I'm trying to verify
it before:

<target name="init" />
 ...
 <available 
      file="${lib.dir}" type="dir" 
      property="lib_dir.exists"/>
    <antcall target="set_lib.classpath" />
    <antcall target="clear_lib.classpath" />
 ...
</target>

<target name="set_lib.classpath" if="lib_dir.exists" >
    <path id="lib.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    <property name="lib.classpath" refid="lib.classpath" />
</target>
<target name="clear_lib.classpath" unless="lib_dir.exists" >
    <property name="lib.classpath" value="" />
</target>

Do you have any approach instead using the depends (that would make very
noise)?

thanks,
Pedro Salazar.

On Mon, 2003-03-17 at 20:12, Dominique Devienne wrote:
> Use the depends attribute of target instead of antcall/ant. --DD
> 
> -----Original Message-----
> From: Pedro Salazar [mailto:pedro-b-salazar@ptinovacao.pt] 
> Sent: Monday, March 17, 2003 2:11 PM
> To: user@ant.apache.org
> Subject: property set in sub-task not defined
> 
> Greetings,
> 
> I'm trying to set a property in a sub-task, but it not working. I put
> here a sample test:
> 
> <target name="X">
>   <antcall target="Y" />
>    <echo message="Z is ${Z}" />
> </target>
> 
> <target name="Y">
>   <property name="Z" value="OK" />
> </target>
> 
> If I call the target X, I will get the output "Z is ${Z}" instead what I
> expect to happen, "Z is OK".
> 
> How can I set a property in a sub-task if we know that properties are
> immutable?
> 
> thanks,
> Pedro Salazar.
-- 
<id name="pedro salazar"> 
<email>pedro-b-salazar@ptinovacao.pt</email>
<pgp-key-id>0E129E31D803BC61</pgp-key-id>
</id>


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

Mime
View raw message