org.apache.tools.ant.taskdefs
public class: ImportTask [javadoc |
source]
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.ImportTask
All Implemented Interfaces:
Cloneable
Task to import another build file into the current project.
It must be 'top level'. On execution it will read another Ant file
into the same Project.
Important: we have not finalized how relative file references
will be resolved in deep/complex build hierarchies - such as what happens
when an imported file imports another file. Use absolute references for
enhanced build file stability, especially in the imported files.
Examples:
<import file="../common-targets.xml"/>
Import targets from a file in a parent directory.
<import file="${deploy-platform}.xml"/>
Import the project defined by the property deploy-platform.
- since:
Ant1.6 -
- ant.task:
category - ="control"
| Methods from org.apache.tools.ant.Task: |
|---|
|
bindToOwner, execute, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, markInvalid, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType |
| Method from org.apache.tools.ant.taskdefs.ImportTask Detail: |
public void execute() {
if (file == null) {
throw new BuildException("import requires file attribute");
}
if (getOwningTarget() == null
|| !"".equals(getOwningTarget().getName())) {
throw new BuildException("import only allowed as a top-level task");
}
ProjectHelper helper =
(ProjectHelper) getProject().
getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
if (helper == null) {
// this happens if the projecthelper was not registered with the project.
throw new BuildException("import requires support in ProjectHelper");
}
Vector importStack = helper.getImportStack();
if (importStack.size() == 0) {
// this happens if ant is used with a project
// helper that doesn't set the import.
throw new BuildException("import requires support in ProjectHelper");
}
if (getLocation() == null || getLocation().getFileName() == null) {
throw new BuildException("Unable to get location of import task");
}
File buildFile = new File(getLocation().getFileName()).getAbsoluteFile();
// Paths are relative to the build file they're imported from,
// *not* the current directory (same as entity includes).
File buildFileParent = new File(buildFile.getParent());
File importedFile = FILE_UTILS.resolveFile(buildFileParent, file);
getProject().log("Importing file " + importedFile + " from "
+ buildFile.getAbsolutePath(), Project.MSG_VERBOSE);
if (!importedFile.exists()) {
String message =
"Cannot find " + file + " imported from "
+ buildFile.getAbsolutePath();
if (optional) {
getProject().log(message, Project.MSG_VERBOSE);
return;
} else {
throw new BuildException(message);
}
}
if (importStack.contains(importedFile)) {
getProject().log(
"Skipped already imported file:\n "
+ importedFile + "\n", Project.MSG_VERBOSE);
return;
}
try {
helper.parse(getProject(), importedFile);
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}
}
This relies on the task order model. |
public void setFile(String file) {
// I don't think we can use File - different rules
// for relative paths.
this.file = file;
}
the name of the file to import. How relative paths are resolved is still
in flux: use absolute paths for safety. |
public void setOptional(boolean optional) {
this.optional = optional;
}
sets the optional attribute |