Methods Summary |
---|
protected static org.apache.tools.ant.helper.ProjectHelper2$AntHandler | getElementHandler()Returns element handler
return elementHandler;
|
protected static org.apache.tools.ant.helper.ProjectHelper2$AntHandler | getMainHandler()Returns main handler
return mainHandler;
|
protected static org.apache.tools.ant.helper.ProjectHelper2$AntHandler | getProjectHandler()Returns project handler
return projectHandler;
|
protected static org.apache.tools.ant.helper.ProjectHelper2$AntHandler | getTargetHandler()Returns target handler
return targetHandler;
|
public void | parse(org.apache.tools.ant.Project project, java.lang.Object source)Parse a source xml input.
getImportStack().addElement(source);
//System.out.println("Adding " + source);
AntXMLContext context = null;
context = (AntXMLContext) project.getReference("ant.parsing.context");
// System.out.println("Parsing " + getImportStack().size() + " " +
// context+ " " + getImportStack() );
if (context == null) {
context = new AntXMLContext(project);
project.addReference("ant.parsing.context", context);
project.addReference("ant.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();
}
|
public void | parse(org.apache.tools.ant.Project project, java.lang.Object source, org.apache.tools.ant.helper.ProjectHelper2$RootHandler handler)Parses the project file, configuring the project as it goes.
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;
} else if (t == null) {
t = exc;
}
throw new BuildException(exc.getMessage(), t, location);
} catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
} else if (t == null) {
t = exc;
}
throw new BuildException(exc.getMessage(), 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);
}
|
public org.apache.tools.ant.UnknownElement | parseUnknownElement(org.apache.tools.ant.Project project, java.net.URL source)Parse an unknown element from a url
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];
|
protected static void | setElementHandler(org.apache.tools.ant.helper.ProjectHelper2$AntHandler handler)Sets element handler
elementHandler = handler;
|
protected static void | setMainHandler(org.apache.tools.ant.helper.ProjectHelper2$AntHandler handler)Sets main handler
mainHandler = handler;
|
protected static void | setProjectHandler(org.apache.tools.ant.helper.ProjectHelper2$AntHandler handler)Sets project handler
projectHandler = handler;
|
protected static void | setTargetHandler(org.apache.tools.ant.helper.ProjectHelper2$AntHandler handler)Sets target handler
targetHandler = handler;
|