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 17:22:14 GMT

I guess that means that there's no way to do this in Ant?  (would confirm my
suspicions).

Here's my use-case, for what it's worth.

I have a version of the <buildnumber> task (totally home-made, but with
similar aims).  I want to increment the build number if I'm going to attempt
to compile a new version of executable code, but don't want to increment it
if I'm only going to run a documentation-related task (for example).  The
documentation-related tasks include the build number in documentation files,
such as Javadocs.  Even if the compile fails, my home-brew <buildnumber>
replacement records this failure in a database.

In case anyone's wondering why I wrote my own version, it's because we work
in a team, compiling versions of the application on different branches of a
CVS repository, so build numbers do not simply increase in a linear way; we
use these serial numbers to track what build corresponds to which version,
and information about the environment in which the build was run.

Thanks again for your help Peter.

- Chris

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


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 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
>
>
>
>
>
> ---------------------------------------------------------------------
> 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