ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: TaskContainer and setProperty
Date Thu, 05 Sep 2002 16:29:38 GMT
If you look at the code of <echo>, you'll see that setMessage(String msg)
never calls getProject().replaceProperties(msg);, and it's not done
elsewhere in the code either. This implies it's done by the framework
*before* calling that attribute setter method, and most likely done *before*
you ever get the chance to set the property...

I don't know how you could delay this stuff to happen, short of relying on
dynamic configurator, which would leave you with the painful task of doing
of the work the framework is already doing (creating the sub-element, and
initializing their attributes).

And also, property immutability is likely to bite you, since Ant doesn't
support the notion of a variable you can change for each invocatin. The
Ant-contrib task gets away from that by using <antcall> internally, but then
the resource hog (dixit Stefan today) issue bites you, and of course
property changes are not propagated.

Can you explain what you're doing that would require this modified
<foreach>? --DD

-----Original Message-----
From: Brian Pontarelli [mailto:brian@pontarelli.com] 
Sent: Thursday, September 05, 2002 11:04 AM
To: Ant Users List
Subject: TaskContainer and setProperty


I'm sure that this stuff has been covered multiple times before, but I'm
having trouble locating stuff in the archives as well as location in the
code.

Here's my dilemna:
I have a foreach tag (groan right?) that does multiple things. It calls to
targets and executes embedded tasks. The call to targets works fine with the
whole delegation to the "antcall" task (which is annoying, but works). The
embedded tasks, doesn't work at all.

Here's what my build file looks like

<foreach list="foo,bar" property="current">
  <echo message="Current is ${current}"/>
</foreach>

My code is roughly this:

// If there are embedded tasks, set the local property and then
// execute those. The 'tasks' variable is a List that is populated
// via the addTask(Task) method
if (!tasks.isEmpty()) {
    project.setProperty(property, token);

    Iterator iter = tasks.iterator();
    Task curTask;
    while (iter.hasNext()) {
        // curTask.setProject(project); tried this to no avail
        curTask = (Task) iter.next();
        curTask.perform();
    }
}

This does not work because the embedded tasks do not see the property at
all. They don't even see the first value or anything. Here's my output:

[foreach] Current is ${current}
[foreach] Current is ${current}

First off, can someone point me the the code in the ant framework that makes
properties immutable so that you must use the "antcall" hack to call other
targets correctly? Also, could someone please explain to me what ant is
doing when it constructs the embedded tasks that prevent them from seeing
properties? Last, does anyone have any work-arounds for this problem?

Thanks
Brian Pontarelli


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

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


Mime
View raw message