ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Brown" <bro...@reflexe.fr>
Subject Re: How can I determine which targets will be executed, using the Ant API?
Date Fri, 23 May 2003 16:49:33 GMT

Hi Peter,

I'm trying to access the list of targets to be executed, not the list of ALL
targets in the build file.  I'd already looked at the javadocs and the
source code.... I tried using getTargets(), but that returns a list of all
targets in the project's build file.

Obviously, if I had the basic list, I could use topoSort(...) to resolve
dependencies, but I'm aware of that, and that's not the problem here.

The list of targets being executed seems to be stored as local variables
within method calls, and is not stored as an instance variable in
"Project.java".  In the source code for Ant 1.5.3, in line 609 of
org/apache/tools/ant/Main.java, a private instance variable (Vector targets)
is passed to the "executeTargets" method of Project, but these targets are
not exposed either in "Main.java" or "Project.java", so I can't tell if a
specific target is going to be called (unless of course a BuildException
occurs).  Furthermore, I don't think it's wise to access "Main.java", as
it's possible to execute targets in a project directly using the API without
using "main" (I think so anyway, I've never tried).

Thanks anyway,
Chris

----- Original Message ----- 
From: "peter reilly" <peter.reilly@corvil.com>
To: "Ant Users List" <user@ant.apache.org>
Sent: Friday, May 23, 2003 6:33 PM
Subject: Re: How can I determine which targets will be executed, using the
Ant API?


The target info is maintained per project in the Project
object's targets hashmap;
Project uses "topoSort()" to sort the targets.
These are publiclly visable.

The following task uses this information.
This does not deal with targets generated
using ant or antcall.

import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.BuildException;
import java.util.*;

public class TargetDepends extends Task {
    private String target;
    public void setTarget(String target) {
        this.target = target;
    }
    public void execute() {
        if (target == null) {
            throw new BuildException(
                "Need to specify target");
        }
        Vector dependList = getProject().topoSort(
            target, getProject().getTargets());
        log("Target [" + target + "] depends on");
        for (int i = 0; i < dependList.size(); ++i) {
            Target t = (Target) dependList.get(i);
            log(" - " + t.getName());

            if (t.getName().equals(target)) {
                break;
            }
        }
    }
}

Peter
On Friday 23 May 2003 13:39, Chris Brown wrote:
> Hello,
>
> How can I determine which targets will be executed, using the Ant API?
>
> I'm writing a very specific task that should behave differently depending
> upon what will be done later as the script continues executing.
>
> It's used in almost all build scenarios, and has a lot of parameters.  I'd
> like to put it in an "init" target, instead of copying to the start of
lots
> of other targets (to avoid cut-and-paste errors as the project evolves).
>
> How does Ant track this internally, and how can I access this information?
>
> Thanks,
> Chris
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


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





Mime
View raw message