You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dale Anson <da...@germane-software.com> on 2003/03/06 23:01:27 UTC
"Call" task
Just sharing --
A common question on this list is how to get a property set in a target
after doing an <antcall>, the common answer is "you can't". I wrote a
very simple task, so simple in fact that I've included the complete code
below. Like AntCall, this task just calls a target in the current build
file. The difference is that all properties from the calling target are
available to the called target, and any properties set by the called
target are immediately available in the calling target. Makes me wonder
why AntCall wasn't written like this?
<shameless plug>
I posted a new version of Antelope today,
http://antelope.sourceforge.net. This task is included.
</shameless plug>
package ise.antelope.tasks;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
public class Call extends Task {
private String target = null;
public void setTarget(String target) {
this.target = target; }
public void execute() {
if (target == null)
throw new BuildException("target is required");
getProject().executeTarget(target);
}
}
Dale Anson
Re: "Call" task
Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Dale Anson" <da...@germane-software.com>
To: "Ant Users List" <us...@ant.apache.org>
Sent: Thursday, March 06, 2003 14:01
Subject: "Call" task
> Just sharing --
>
> A common question on this list is how to get a property set in a target
> after doing an <antcall>, the common answer is "you can't". I wrote a
> very simple task, so simple in fact that I've included the complete code
> below. Like AntCall, this task just calls a target in the current build
> file. The difference is that all properties from the calling target are
> available to the called target, and any properties set by the called
> target are immediately available in the calling target. Makes me wonder
> why AntCall wasn't written like this?
Because the authors didnt want it that way?
Right now <ant> and <antcall> effectively take a new environment down with
them. If you set all properties by the called target then you cannot <ant>
the same target twice and be sure it works, because in ant you cannot
overwrite properties.