| Method from org.apache.tools.ant.taskdefs.Ant Detail: |
public void addConfiguredTarget(Ant.TargetElement t) {
if (targetAttributeSet) {
throw new BuildException(
"nested target is incompatible with the target attribute");
}
String name = t.getName();
if (name.equals("")) {
throw new BuildException("target name must not be empty");
}
targets.add(name);
}
Add a target to this Ant invocation. |
public void addPropertyset(PropertySet ps) {
propertySets.addElement(ps);
}
Add a set of properties to pass to the new project. |
public void addReference(Ant.Reference ref) {
references.addElement(ref);
}
Add a Reference element identifying a data type to carry
over to the new project. |
public Property createProperty() {
Property p = new Property(true, getProject());
p.setProject(getNewProject());
p.setTaskName("property");
properties.addElement(p);
return p;
}
Property to pass to the new project.
The property is passed as a 'user property'. |
public void execute() throws BuildException {
File savedDir = dir;
String savedAntFile = antFile;
Vector locals = new Vector(targets);
try {
getNewProject();
if (dir == null && inheritAll) {
dir = getProject().getBaseDir();
}
initializeProject();
if (dir != null) {
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 = Main.DEFAULT_BUILD_FILENAME;
}
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);
} catch (BuildException ex) {
be = ProjectHelper
.addLocationToBuildException(ex, getLocation());
throw be;
} finally {
log("Exiting " + antFile + ".", Project.MSG_VERBOSE);
newProject.fireSubBuildFinished(be);
}
}
} finally {
// help the gc
newProject = null;
Enumeration e = properties.elements();
while (e.hasMoreElements()) {
Property p = (Property) e.nextElement();
p.setProject(null);
}
if (output != null && out != null) {
try {
out.close();
} catch (final Exception ex) {
//ignore
}
}
dir = savedDir;
antFile = savedAntFile;
}
}
|
protected Project getNewProject() {
if (newProject == null) {
reinit();
}
return newProject;
}
Get the (sub)-Project instance currently in use. |
public void handleErrorFlush(String errorOutputToFlush) {
if (newProject != null) {
newProject.demuxFlush(errorOutputToFlush, true);
} else {
super.handleErrorFlush(errorOutputToFlush);
}
}
Handle error output.
Send it the the new project if is present, otherwise
call the super class. |
public void handleErrorOutput(String errorOutputToHandle) {
if (newProject != null) {
newProject.demuxOutput(errorOutputToHandle, true);
} else {
super.handleErrorOutput(errorOutputToHandle);
}
}
Handle error output.
Send it the the new project if is present, otherwise
call the super class. |
public void handleFlush(String toFlush) {
if (newProject != null) {
newProject.demuxFlush(toFlush, false);
} else {
super.handleFlush(toFlush);
}
}
Handles output.
Send it the the new project if is present, otherwise
call the super class. |
public int handleInput(byte[] buffer,
int offset,
int length) throws IOException {
if (newProject != null) {
return newProject.demuxInput(buffer, offset, length);
}
return super.handleInput(buffer, offset, length);
}
Handles input.
Deleate to the created project, if present, otherwise
call the super class. |
public void handleOutput(String outputToHandle) {
if (newProject != null) {
newProject.demuxOutput(outputToHandle, false);
} else {
super.handleOutput(outputToHandle);
}
}
Handles output.
Send it the the new project if is present, otherwise
call the super class. |
public void init() {
newProject = getProject().createSubProject();
newProject.setJavaVersionProperty();
}
Creates a Project instance for the project to call. |
public void setAntfile(String antFile) {
// @note: it is a string and not a file to handle relative/absolute
// otherwise a relative file will be resolved based on the current
// basedir.
this.antFile = antFile;
}
The build file to use. Defaults to "build.xml". This file is expected
to be a filename relative to the dir attribute given. |
public void setDir(File dir) {
this.dir = dir;
}
The directory to use as a base directory for the new Ant project.
Defaults to the current project's basedir, unless inheritall
has been set to false, in which case it doesn't have a default
value. This will override the basedir setting of the called project. |
public void setInheritAll(boolean value) {
inheritAll = value;
}
If true, pass all properties to the new Ant project.
Defaults to true. |
public void setInheritRefs(boolean value) {
inheritRefs = value;
}
If true, pass all references to the new Ant project.
Defaults to false. |
public void setOutput(String outputFile) {
this.output = outputFile;
}
Set the filename to write the output to. This is relative to the value
of the dir attribute if it has been set or to the base directory of the
current project otherwise. |
public void setTarget(String targetToAdd) {
if (targetToAdd.equals("")) {
throw new BuildException("target attribute must not be empty");
}
targets.add(targetToAdd);
targetAttributeSet = true;
}
The target of the new Ant project to execute.
Defaults to the new project's default target. |