ProjectHelperImplpublic class ProjectHelperImpl extends org.apache.tools.ant.ProjectHelper
Fields Summary |
---|
private static final org.apache.tools.ant.util.FileUtils | FILE_UTILShelper for path -> URI and URI -> path conversions. | private Parser | parserSAX 1 style parser used to parse the given file. This may
in fact be a SAX 2 XMLReader wrapped in an XMLReaderAdapter. | private org.apache.tools.ant.Project | projectThe project to configure. | private File | buildFileThe configuration file to parse. | private File | buildFileParentParent directory of the build file. Used for resolving entities
and setting the project's base directory. | private Locator | locatorLocator for the configuration file parser.
Used for giving locations of errors etc. | private org.apache.tools.ant.Target | implicitTargetTarget that all other targets will depend upon implicitly.
This holds all tasks and data type definitions that have
been placed outside of targets. |
Constructors Summary |
---|
public ProjectHelperImpl()default constructor
implicitTarget.setName("");
|
Methods Summary |
---|
private void | configureId(java.lang.Object target, org.xml.sax.AttributeList attr)Scans an attribute list for the id attribute and
stores a reference to the target object in the project if an
id is found.
This method was moved out of the configure method to allow
it to be executed at parse time.
String id = attr.getValue("id");
if (id != null) {
project.addReference(id, target);
}
| private static void | handleElement(org.apache.tools.ant.helper.ProjectHelperImpl helperImpl, org.xml.sax.DocumentHandler parent, org.apache.tools.ant.Target target, java.lang.String elementName, org.xml.sax.AttributeList attrs)Start a new DataTypeHandler if element is known to be a
data-type and a TaskHandler otherwise.
Factored out of TargetHandler.
if (elementName.equals("description")) {
new DescriptionHandler(helperImpl, parent);
} else if (helperImpl.project.getDataTypeDefinitions()
.get(elementName) != null) {
new DataTypeHandler(helperImpl, parent, target)
.init(elementName, attrs);
} else {
new TaskHandler(helperImpl, parent, target, null, target)
.init(elementName, attrs);
}
| public void | parse(org.apache.tools.ant.Project project, java.lang.Object source)Parses the project file, configuring the project as it goes.
if (!(source instanceof File)) {
throw new BuildException("Only File source supported by "
+ "default plugin");
}
File bFile = (File) source;
FileInputStream inputStream = null;
InputSource inputSource = null;
this.project = project;
this.buildFile = new File(bFile.getAbsolutePath());
buildFileParent = new File(this.buildFile.getParent());
try {
try {
parser = JAXPUtils.getParser();
} catch (BuildException e) {
parser = new XMLReaderAdapter(JAXPUtils.getXMLReader());
}
String uri = FILE_UTILS.toURI(bFile.getAbsolutePath());
inputStream = new FileInputStream(bFile);
inputSource = new InputSource(inputStream);
inputSource.setSystemId(uri);
project.log("parsing buildfile " + bFile + " with URI = "
+ uri, Project.MSG_VERBOSE);
HandlerBase hb = new RootHandler(this);
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.setDTDHandler(hb);
parser.parse(inputSource);
} catch (SAXParseException exc) {
Location location =
new Location(exc.getSystemId(), exc.getLineNumber(),
exc.getColumnNumber());
Throwable t = exc.getException();
if (t instanceof BuildException) {
BuildException be = (BuildException) t;
if (be.getLocation() == Location.UNKNOWN_LOCATION) {
be.setLocation(location);
}
throw be;
}
throw new BuildException(exc.getMessage(), t, location);
} catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
}
throw new BuildException(exc.getMessage(), t);
} catch (FileNotFoundException exc) {
throw new BuildException(exc);
} catch (UnsupportedEncodingException exc) {
throw new BuildException("Encoding of project file is invalid.",
exc);
} catch (IOException exc) {
throw new BuildException("Error reading project file: "
+ exc.getMessage(), exc);
} finally {
FileUtils.close(inputStream);
}
|
|