📄 projecthelperimpl.java
字号:
* @param locator The locator used by the parser. * Will not be <code>null</code>. */ public void setDocumentLocator(Locator locator) { helperImpl.locator = locator; } } /** * Handler for the top level "project" element. */ static class ProjectHandler extends AbstractHandler { /** * Constructor which just delegates to the superconstructor. * * @param parentHandler The handler which should be restored to the * parser at the end of the element. * Must not be <code>null</code>. */ public ProjectHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) { super(helperImpl, parentHandler); } /** * Initialisation routine called after handler creation * with the element name and attributes. The attributes which * this handler can deal with are: <code>"default"</code>, * <code>"name"</code>, <code>"id"</code> and <code>"basedir"</code>. * * @param tag Name of the element which caused this handler * to be created. Should not be <code>null</code>. * Ignored in this implementation. * @param attrs Attributes of the element which caused this * handler to be created. Must not be <code>null</code>. * * @exception SAXParseException if an unexpected attribute is * encountered or if the <code>"default"</code> attribute * is missing. */ public void init(String tag, AttributeList attrs) throws SAXParseException { String def = null; String name = null; String id = null; String baseDir = null; for (int i = 0; i < attrs.getLength(); i++) { String key = attrs.getName(i); String value = attrs.getValue(i); if (key.equals("default")) { def = value; } else if (key.equals("name")) { name = value; } else if (key.equals("id")) { id = value; } else if (key.equals("basedir")) { baseDir = value; } else { throw new SAXParseException("Unexpected attribute \"" + attrs.getName(i) + "\"", helperImpl.locator); } } if (def != null && !def.equals("")) { helperImpl.project.setDefaultTarget(def); } else { throw new BuildException("The default attribute is required"); } if (name != null) { helperImpl.project.setName(name); helperImpl.project.addReference(name, helperImpl.project); } if (id != null) { helperImpl.project.addReference(id, helperImpl.project); } if (helperImpl.project.getProperty("basedir") != null) { helperImpl.project.setBasedir(helperImpl.project.getProperty("basedir")); } else { if (baseDir == null) { helperImpl.project.setBasedir(helperImpl.buildFileParent.getAbsolutePath()); } else { // check whether the user has specified an absolute path if ((new File(baseDir)).isAbsolute()) { helperImpl.project.setBasedir(baseDir); } else { File resolvedBaseDir = FILE_UTILS.resolveFile( helperImpl.buildFileParent, baseDir); helperImpl.project.setBaseDir(resolvedBaseDir); } } } helperImpl.project.addTarget("", helperImpl.implicitTarget); } /** * Handles the start of a top-level element within the project. An * appropriate handler is created and initialised with the details * of the element. * * @param name The name of the element being started. * Will not be <code>null</code>. * @param attrs Attributes of the element being started. * Will not be <code>null</code>. * * @exception SAXParseException if the tag given is not * <code>"taskdef"</code>, <code>"typedef"</code>, * <code>"property"</code>, <code>"target"</code> * or a data type definition */ public void startElement(String name, AttributeList attrs) throws SAXParseException { if (name.equals("target")) { handleTarget(name, attrs); } else { handleElement(helperImpl, this, helperImpl.implicitTarget, name, attrs); } } /** * Handles a target definition element by creating a target handler * and initialising is with the details of the element. * * @param tag The name of the element to be handled. * Will not be <code>null</code>. * @param attrs Attributes of the element to be handled. * Will not be <code>null</code>. * * @exception SAXParseException if an error occurs initialising * the handler */ private void handleTarget(String tag, AttributeList attrs) throws SAXParseException { new TargetHandler(helperImpl, this).init(tag, attrs); } } /** * Handler for "target" elements. */ static class TargetHandler extends AbstractHandler { private Target target; /** * Constructor which just delegates to the superconstructor. * * @param parentHandler The handler which should be restored to the * parser at the end of the element. * Must not be <code>null</code>. */ public TargetHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) { super(helperImpl, parentHandler); } /** * Initialisation routine called after handler creation * with the element name and attributes. The attributes which * this handler can deal with are: <code>"name"</code>, * <code>"depends"</code>, <code>"if"</code>, * <code>"unless"</code>, <code>"id"</code> and * <code>"description"</code>. * * @param tag Name of the element which caused this handler * to be created. Should not be <code>null</code>. * Ignored in this implementation. * @param attrs Attributes of the element which caused this * handler to be created. Must not be <code>null</code>. * * @exception SAXParseException if an unexpected attribute is encountered * or if the <code>"name"</code> attribute is missing. */ public void init(String tag, AttributeList attrs) throws SAXParseException { String name = null; String depends = ""; String ifCond = null; String unlessCond = null; String id = null; String description = null; for (int i = 0; i < attrs.getLength(); i++) { String key = attrs.getName(i); String value = attrs.getValue(i); if (key.equals("name")) { name = value; if (name.equals("")) { throw new BuildException("name attribute must not" + " be empty", new Location(helperImpl.locator)); } } else if (key.equals("depends")) { depends = value; } else if (key.equals("if")) { ifCond = value; } else if (key.equals("unless")) { unlessCond = value; } else if (key.equals("id")) { id = value; } else if (key.equals("description")) { description = value; } else { throw new SAXParseException("Unexpected attribute \"" + key + "\"", helperImpl.locator); } } if (name == null) { throw new SAXParseException("target element appears without a name attribute", helperImpl.locator); } target = new Target(); // implicit target must be first on dependency list target.addDependency(""); target.setName(name); target.setIf(ifCond); target.setUnless(unlessCond); target.setDescription(description); helperImpl.project.addTarget(name, target); if (id != null && !id.equals("")) { helperImpl.project.addReference(id, target); } // take care of dependencies if (depends.length() > 0) { target.setDepends(depends); } } /** * Handles the start of an element within a target. * * @param name The name of the element being started. * Will not be <code>null</code>. * @param attrs Attributes of the element being started. * Will not be <code>null</code>. * * @exception SAXParseException if an error occurs when initialising * the appropriate child handler */ public void startElement(String name, AttributeList attrs) throws SAXParseException { handleElement(helperImpl, this, target, name, attrs); } } /** * Start a new DataTypeHandler if element is known to be a * data-type and a TaskHandler otherwise. * * <p>Factored out of TargetHandler.</p> * * @since Ant 1.6 */ private static void handleElement(ProjectHelperImpl helperImpl, DocumentHandler parent, Target target, String elementName, AttributeList attrs) throws SAXParseException { 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); } } /** * Handler for "description" elements. */ static class DescriptionHandler extends AbstractHandler { /** * Constructor which just delegates to the superconstructor. * * @param parentHandler The handler which should be restored to the * parser at the end of the element. * Must not be <code>null</code>. */ public DescriptionHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) { super(helperImpl, parentHandler); } /** * Adds the text as description to the project. * * @param buf A character array of the text within the element. * Will not be <code>null</code>. * @param start The start element in the array. * @param count The number of characters to read from the array. */ public void characters(char[] buf, int start, int count) { String text = new String(buf, start, count); String currentDescription = helperImpl.project.getDescription(); if (currentDescription == null) { helperImpl.project.setDescription(text); } else { helperImpl.project.setDescription(currentDescription + text); } } } /** * Handler for all task elements. */ static class TaskHandler extends AbstractHandler { /** Containing target, if any. */ private Target target; /** * Container for the task, if any. If target is * non-<code>null</code>, this must be too. */ private TaskContainer container; /** * Task created by this handler. */ private Task task; /** * Wrapper for the parent element, if any. The wrapper for this * element will be added to this wrapper as a child. */ private RuntimeConfigurable parentWrapper; /** * Wrapper for this element which takes care of actually configuring * the element, if this element is contained within a target. * Otherwise the configuration is performed with the configure method. * @see ProjectHelper#configure(Object,AttributeList,Project) */ private RuntimeConfigurable wrapper = null; /** * Constructor. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -