* probably also if a BuildException is thrown by the new project.
*/
public void execute() throws BuildException {
File savedDir = dir;
String savedAntFile = antFile;
Vector locals = new VectorSet(targets);
try {
getNewProject();
if (dir == null && inheritAll) {
dir = getProject().getBaseDir();
}
initializeProject();
if (dir != null) {
if (!useNativeBasedir) {
newProject.setBaseDir(dir);
if (savedDir != null) {
// has been set explicitly
newProject.setInheritedProperty(MagicNames.PROJECT_BASEDIR,
dir.getAbsolutePath());
}
}
} else {
dir = getProject().getBaseDir();
}
overrideProperties();
if (antFile == null) {
antFile = getDefaultBuildFile();
}
File file = FILE_UTILS.resolveFile(dir, antFile);
antFile = file.getAbsolutePath();
log("calling target(s) "
+ ((locals.size() > 0) ? locals.toString() : "[default]")
+ " in build file " + antFile, Project.MSG_VERBOSE);
newProject.setUserProperty(MagicNames.ANT_FILE , antFile);
String thisAntFile = getProject().getProperty(MagicNames.ANT_FILE);
// Are we trying to call the target in which we are defined (or
// the build file if this is a top level task)?
if (thisAntFile != null
&& file.equals(getProject().resolveFile(thisAntFile))
&& getOwningTarget() != null) {
if (getOwningTarget().getName().equals("")) {
if (getTaskName().equals("antcall")) {
throw new BuildException("antcall must not be used at"
+ " the top level.");
}
throw new BuildException(getTaskName() + " task at the"
+ " top level must not invoke"
+ " its own build file.");
}
}
try {
ProjectHelper.configureProject(newProject, file);
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}
if (locals.size() == 0) {
String defaultTarget = newProject.getDefaultTarget();
if (defaultTarget != null) {
locals.add(defaultTarget);
}
}
if (newProject.getProperty(MagicNames.ANT_FILE)
.equals(getProject().getProperty(MagicNames.ANT_FILE))
&& getOwningTarget() != null) {
String owningTargetName = getOwningTarget().getName();
if (locals.contains(owningTargetName)) {
throw new BuildException(getTaskName() + " task calling "
+ "its own parent target.");
}
boolean circular = false;
for (Iterator it = locals.iterator();
!circular && it.hasNext();) {
Target other =
(Target) (getProject().getTargets().get(it.next()));
circular |= (other != null
&& other.dependsOn(owningTargetName));
}
if (circular) {
throw new BuildException(getTaskName()
+ " task calling a target"
+ " that depends on"
+ " its parent target \'"
+ owningTargetName
+ "\'.");
}
}
addReferences();
if (locals.size() > 0 && !(locals.size() == 1
&& "".equals(locals.get(0)))) {
BuildException be = null;
try {
log("Entering " + antFile + "...", Project.MSG_VERBOSE);
newProject.fireSubBuildStarted();
newProject.executeTargets(locals);