Return-Path: Mailing-List: contact user-help@ant.apache.org; run by ezmlm Delivered-To: mailing list user@ant.apache.org Received: (qmail 82319 invoked from network); 23 May 2003 17:08:05 -0000 Received: from k100-37.bas1.dbn.dublin.eircom.net (HELO corvil.com.) (159.134.100.37) by daedalus.apache.org with SMTP; 23 May 2003 17:08:05 -0000 Received: from preilly.local.corvil.com (preilly.local.corvil.com [172.18.1.173]) by corvil.com. (8.12.5/8.12.5) with ESMTP id h4NH87pg093106 for ; Fri, 23 May 2003 18:08:08 +0100 (IST) (envelope-from peter.reilly@corvil.com) Content-Type: text/plain; charset="iso-8859-1" From: peter reilly Organization: corvil To: Ant Users List Subject: Re: How can I determine which targets will be executed, using the Ant API? Date: Fri, 23 May 2003 18:13:04 +0100 User-Agent: KMail/1.4.3 References: <002801c32128$63d3f6f0$0a14a8c0@terre> <200305231733.36204.peter.reilly@corvil.com> <008301c3214b$49d8bab0$0a14a8c0@terre> In-Reply-To: <008301c3214b$49d8bab0$0a14a8c0@terre> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305231813.04229.peter.reilly@corvil.com> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Ah, I see. Peter On Friday 23 May 2003 17:49, Chris Brown wrote: > Hi Peter, > > I'm trying to access the list of targets to be executed, not the list o= f > 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 resolv= e > 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 variable= s > 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 c= an'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" > To: "Ant Users List" > 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 =3D target; > } > public void execute() { > if (target =3D=3D null) { > throw new BuildException( > "Need to specify target"); > } > Vector dependList =3D getProject().topoSort( > target, getProject().getTargets()); > log("Target [" + target + "] depends on"); > for (int i =3D 0; i < dependList.size(); ++i) { > Target t =3D (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 depen= ding > > 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.= =20 > > I'd like to put it in an "init" target, instead of copying to the sta= rt > > of > > lots > > > of other targets (to avoid cut-and-paste errors as the project evolve= s). > > > > 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 > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org > For additional commands, e-mail: user-help@ant.apache.org