| Method from org.apache.tools.ant.helper.ProjectHelper2 Detail: |
protected static ProjectHelper2.AntHandler getElementHandler() {
return elementHandler;
}
|
protected static ProjectHelper2.AntHandler getMainHandler() {
return mainHandler;
}
|
protected static ProjectHelper2.AntHandler getProjectHandler() {
return projectHandler;
}
|
protected static ProjectHelper2.AntHandler getTargetHandler() {
return targetHandler;
}
|
public void parse(Project project,
Object source) throws BuildException {
getImportStack().addElement(source);
AntXMLContext context = null;
context = (AntXMLContext) project.getReference(REFID_CONTEXT);
if (context == null) {
context = new AntXMLContext(project);
project.addReference(REFID_CONTEXT, context);
project.addReference(REFID_TARGETS, context.getTargets());
}
if (getImportStack().size() > 1) {
// we are in an imported file.
context.setIgnoreProjectTag(true);
Target currentTarget = context.getCurrentTarget();
Target currentImplicit = context.getImplicitTarget();
Map currentTargets = context.getCurrentTargets();
try {
Target newCurrent = new Target();
newCurrent.setProject(project);
newCurrent.setName("");
context.setCurrentTarget(newCurrent);
context.setCurrentTargets(new HashMap());
context.setImplicitTarget(newCurrent);
parse(project, source, new RootHandler(context, mainHandler));
newCurrent.execute();
} finally {
context.setCurrentTarget(currentTarget);
context.setImplicitTarget(currentImplicit);
context.setCurrentTargets(currentTargets);
}
} else {
// top level file
context.setCurrentTargets(new HashMap());
parse(project, source, new RootHandler(context, mainHandler));
// Execute the top-level target
context.getImplicitTarget().execute();
}
}
Parse a source xml input. |
public void parse(Project project,
Object source,
ProjectHelper2.RootHandler handler) throws BuildException {
AntXMLContext context = handler.context;
File buildFile = null;
URL url = null;
String buildFileName = null;
if (source instanceof File) {
buildFile = (File) source;
buildFile = FILE_UTILS.normalize(buildFile.getAbsolutePath());
context.setBuildFile(buildFile);
buildFileName = buildFile.toString();
// } else if (source instanceof InputStream ) {
} else if (source instanceof URL) {
url = (URL) source;
buildFileName = url.toString();
// } else if (source instanceof InputSource ) {
} else {
throw new BuildException("Source " + source.getClass().getName()
+ " not supported by this plugin");
}
InputStream inputStream = null;
InputSource inputSource = null;
try {
/**
* SAX 2 style parser used to parse the given file.
*/
XMLReader parser = JAXPUtils.getNamespaceXMLReader();
String uri = null;
if (buildFile != null) {
uri = FILE_UTILS.toURI(buildFile.getAbsolutePath());
inputStream = new FileInputStream(buildFile);
} else {
inputStream = url.openStream();
uri = url.toString(); // ?? OK ??
}
inputSource = new InputSource(inputStream);
if (uri != null) {
inputSource.setSystemId(uri);
}
project.log("parsing buildfile " + buildFileName
+ " with URI = " + uri, Project.MSG_VERBOSE);
DefaultHandler hb = handler;
parser.setContentHandler(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 == null ? exc : t, location);
} catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
}
throw new BuildException(exc.getMessage(), t == null ? exc : t);
} catch (FileNotFoundException exc) {
throw new BuildException(exc);
} catch (UnsupportedEncodingException exc) {
throw new BuildException("Encoding of project file "
+ buildFileName + " is invalid.", exc);
} catch (IOException exc) {
throw new BuildException("Error reading project file "
+ buildFileName + ": " + exc.getMessage(), exc);
} finally {
FileUtils.close(inputStream);
}
}
Parses the project file, configuring the project as it goes. |
public UnknownElement parseUnknownElement(Project project,
URL source) throws BuildException {
Target dummyTarget = new Target();
dummyTarget.setProject(project);
AntXMLContext context = new AntXMLContext(project);
context.addTarget(dummyTarget);
context.setImplicitTarget(dummyTarget);
parse(context.getProject(), source, new RootHandler(context, elementHandler));
Task[] tasks = dummyTarget.getTasks();
if (tasks.length != 1) {
throw new BuildException("No tasks defined");
}
return (UnknownElement) tasks[0];
}
Parse an unknown element from a url |
protected static void setElementHandler(ProjectHelper2.AntHandler handler) {
elementHandler = handler;
}
|
protected static void setMainHandler(ProjectHelper2.AntHandler handler) {
mainHandler = handler;
}
|
protected static void setProjectHandler(ProjectHelper2.AntHandler handler) {
projectHandler = handler;
}
|
protected static void setTargetHandler(ProjectHelper2.AntHandler handler) {
targetHandler = handler;
}
|