ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Glick <>
Subject Project.executeTargets(String[]) is a poor API
Date Tue, 29 Aug 2000 17:04:36 GMT
When trying to write a task which involves running a number of targets
in the current project, where the list of targets to run is computed
dynamically, I found that there is not a clean way to do this (that I
could find) in the current Ant API.

I.e. I have a task property, let's say setSubTargets(String) where the
names of the subtargets are specified as a comma-separated list. I want
the task to first make sure all of these subtargets are run, with
whatever cross-dependencies as well as dependencies outside the group
that they may have; then do some other stuff.

I got this to work originally by overriding setOwningTarget(Target) to
first call super, and then add dependencies to the owning target for all
of the subtargets. This works, but is pretty ugly: a task should not
quietly change the dependencies of the target it is in, that is not too

So I tried to rewrite it, putting into the start of the execute() method
a call to Project.executeTargets(Vector<String>). But it turns out that
this is just the same as calling .executeTarget(String) on each target
individually; and if some of them have common dependencies, it will run
all the common dependencies several times, which is no good.

(Main.runBuild() uses this method, but here it is intended that the
targets be run sequentially, so that "ant clean all" works--or so I saw
on this list earlier. Personally I find this a little counterintuitive,
but OK.)

Since Project.topoSort and so on are private, the only way I could find
to run all the targets with their dependencies only counted once, was:
create a new Target(), give it some randomized unique name, give it
dependencies on all of the desired targets, add it to the project, and
execute it.

This does work but seems rather ugly. Perhaps Project.executeTargets()
should run all the targets "together" without duplicate dependencies
(and change Main.runBuild); or perhaps there should be a new Project
method to do this?


Jesse Glick   <>
NetBeans, Open APIs  <>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR

View raw message