⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 projecthelper2.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                // no further processing                return;            }            // set explicitly before starting ?            if (project.getProperty("basedir") != null) {                project.setBasedir(project.getProperty("basedir"));            } else {                // Default for baseDir is the location of the build file.                if (baseDir == null) {                    project.setBasedir(context.getBuildFileParent().getAbsolutePath());                } else {                    // check whether the user has specified an absolute path                    if ((new File(baseDir)).isAbsolute()) {                        project.setBasedir(baseDir);                    } else {                        project.setBaseDir(FILE_UTILS.resolveFile(                                               context.getBuildFileParent(), baseDir));                    }                }            }            project.addTarget("", context.getImplicitTarget());            context.setCurrentTarget(context.getImplicitTarget());        }        /**         * 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 uri The namespace URI for this element.         * @param name The name of the element being started.         *            Will not be <code>null</code>.         * @param qname The qualified name for this element.         * @param attrs Attributes of the element being started.         *              Will not be <code>null</code>.         * @param context The context for this element.         * @return a target or an element handler.         *         * @exception org.xml.sax.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 AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,                                       AntXMLContext context) throws SAXParseException {            return name.equals("target") && (uri.equals("") || uri.equals(ANT_CORE_URI))                    ? ProjectHelper2.targetHandler : ProjectHelper2.elementHandler;        }    }    /**     * Handler for "target" elements.     */    public static class TargetHandler extends AntHandler {        /**         * 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 uri The namespace URI for this element.         * @param tag Name of the element which caused this handler         *            to be created. Should not be <code>null</code>.         *            Ignored in this implementation.         * @param qname The qualified name for this element.         * @param attrs Attributes of the element which caused this         *              handler to be created. Must not be <code>null</code>.         * @param context The current context.         *         * @exception SAXParseException if an unexpected attribute is encountered         *            or if the <code>"name"</code> attribute is missing.         */        public void onStartElement(String uri, String tag, String qname, Attributes attrs,                                   AntXMLContext context) throws SAXParseException {            String name = null;            String depends = "";            Project project = context.getProject();            Target target = new Target();            target.setProject(project);            target.setLocation(new Location(context.getLocator()));            context.addTarget(target);            for (int i = 0; i < attrs.getLength(); i++) {                String attrUri = attrs.getURI(i);                if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {                    continue; // Ignore attributes from unknown uris                }                String key = attrs.getLocalName(i);                String value = attrs.getValue(i);                if (key.equals("name")) {                    name = value;                    if ("".equals(name)) {                        throw new BuildException("name attribute must " + "not be empty");                    }                } else if (key.equals("depends")) {                    depends = value;                } else if (key.equals("if")) {                    target.setIf(value);                } else if (key.equals("unless")) {                    target.setUnless(value);                } else if (key.equals("id")) {                    if (value != null && !value.equals("")) {                        context.getProject().addReference(value, target);                    }                } else if (key.equals("description")) {                    target.setDescription(value);                } else {                    throw new SAXParseException("Unexpected attribute \""                            + key + "\"", context.getLocator());                }            }            if (name == null) {                throw new SAXParseException("target element appears without a name attribute",                        context.getLocator());            }            // Check if this target is in the current build file            if (context.getCurrentTargets().get(name) != null) {                throw new BuildException("Duplicate target '" + name + "'", target.getLocation());            }            Hashtable projectTargets = project.getTargets();            boolean   usedTarget = false;            // If the name has not already been defined define it            if (projectTargets.containsKey(name)) {                project.log("Already defined in main or a previous import, ignore "                        + name, Project.MSG_VERBOSE);            } else {                target.setName(name);                context.getCurrentTargets().put(name, target);                project.addOrReplaceTarget(name, target);                usedTarget = true;            }            if (depends.length() > 0) {                target.setDepends(depends);            }            if (context.isIgnoringProjectTag() && context.getCurrentProjectName() != null                && context.getCurrentProjectName().length() != 0) {                // In an impored file (and not completely                // ignoring the project tag)                String newName = context.getCurrentProjectName() + "." + name;                Target newTarget = usedTarget ? new Target(target) : target;                newTarget.setName(newName);                context.getCurrentTargets().put(newName, newTarget);                project.addOrReplaceTarget(newName, newTarget);            }        }        /**         * Handles the start of an element within a target.         *         * @param uri The namespace URI for this element.         * @param name The name of the element being started.         *            Will not be <code>null</code>.         * @param qname The qualified name for this element.         * @param attrs Attributes of the element being started.         *              Will not be <code>null</code>.         * @param context The current context.         * @return an element handler.         *         * @exception SAXParseException if an error occurs when initialising         *                              the appropriate child handler         */        public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,                                       AntXMLContext context) throws SAXParseException {            return ProjectHelper2.elementHandler;        }        /**         * Handle the end of the project, sets the current target of the         * context to be the implicit target.         *         * @param uri The namespace URI of the element.         * @param tag The name of the element.         * @param context The current context.         */        public void onEndElement(String uri, String tag, AntXMLContext context) {            context.setCurrentTarget(context.getImplicitTarget());        }    }    /**     * Handler for all project elements ( tasks, data types )     */    public static class ElementHandler extends AntHandler {        /**         * Constructor.         */        public ElementHandler() {        }        /**         * Initialisation routine called after handler creation         * with the element name and attributes. This configures         * the element with its attributes and sets it up with         * its parent container (if any). Nested elements are then         * added later as the parser encounters them.         *         * @param uri The namespace URI for this element.         * @param tag Name of the element which caused this handler         *            to be created. Must not be <code>null</code>.         * @param qname The qualified name for this element.         * @param attrs Attributes of the element which caused this         *              handler to be created. Must not be <code>null</code>.         * @param context The current context.         *         * @exception SAXParseException in case of error (not thrown in         *                              this implementation)         */        public void onStartElement(String uri, String tag, String qname, Attributes attrs,                                   AntXMLContext context) throws SAXParseException {            RuntimeConfigurable parentWrapper = context.currentWrapper();            Object parent = null;            if (parentWrapper != null) {                parent = parentWrapper.getProxy();            }            /* UnknownElement is used for tasks and data types - with               delayed eval */            UnknownElement task = new UnknownElement(tag);            task.setProject(context.getProject());            task.setNamespace(uri);            task.setQName(qname);            task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag));            task.setTaskName(qname);            Location location = new Location(context.getLocator().getSystemId(),                    context.getLocator().getLineNumber(), context.getLocator().getColumnNumber());            task.setLocation(location);            task.setOwningTarget(context.getCurrentTarget());            if (parent != null) {                // Nested element                ((UnknownElement) parent).addChild(task);            }  else {                // Task included in a target ( including the default one ).                context.getCurrentTarget().addTask(task);            }            context.configureId(task, attrs);            // container.addTask(task);            // This is a nop in UE: task.init();            RuntimeConfigurable wrapper = new RuntimeConfigurable(task, task.getTaskName());            for (int i = 0; i < attrs.getLength(); i++) {                String name = attrs.getLocalName(i);                String attrUri = attrs.getURI(i);                if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {                    name = attrUri + ":" + attrs.getQName(i);                }                String value = attrs.getValue(i);                // PR: Hack for ant-type value                //  an ant-type is a component name which can                // be namespaced, need to extract the name                // and convert from qualified name to uri/name                if (ANT_TYPE.equals(name) || (ANT_CORE_URI.equals(attrUri)                        && ANT_TYPE.equals(attrs.getLocalName(i)))) {                    context.getProject().log(                        "WARNING: "                        + "the ant-type mechanism has been deprecated"                        + StringUtils.LINE_SEP                        + "         and"                        + " will not be available in Ant 1.8.0 or higher",                        Project.MSG_WARN);                    name = ANT_TYPE;                    int index = value.indexOf(":");                    if (index >= 0) {                        String prefix = value.substring(0, index);                        String mappedUri = context.getPrefixMapping(prefix);                        if (mappedUri == null) {                            throw new BuildException(                                    "Unable to find XML NS prefix \"" + prefix + "\"");                        }                        value = ProjectHelper.genComponentName(                                mappedUri, value.substring(index + 1));                    }                }                wrapper.setAttribute(name, value);            }            if (parentWrapper != null) {                parentWrapper.addChild(wrapper);            }            context.pushWrapper(wrapper);        }        /**         * Adds text to the task, using the wrapper         *         * @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.         * @param context The current context.         *         * @exception SAXParseException if the element doesn't support text         *         * @see ProjectHelper#addText(Project,java.lang.Object,char[],int,int)         */        public void characters(char[] buf, int start, int count,                               AntXMLContext context) throws SAXParseException {            RuntimeConfigurable wrapper = context.currentWrapper();            wrapper.addText(buf, start, count);        }        /**         * Handles the start of an element within a target. Task containers         * will always use another task handler, and all other tasks         * will always use a nested element handler.         *         * @param uri The namespace URI for this element.         * @param tag The name of the element being started.         *            Will not be <code>null</code>.         * @param qname The qualified name for this element.         * @param attrs Attributes of the element being started.         *              Will not be <code>null</code>.         * @param context The current context.         * @return The handler for elements.         *         * @exception SAXParseException if an error occurs when initialising         *                              the appropriate child handler         */        public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs,                                       AntXMLContext context) throws SAXParseException {            return ProjectHelper2.elementHandler;        }        /**         * Handles the end of the element. This pops the wrapper from         * the context.         *         * @param uri The namespace URI for the element.         * @param tag The name of the element.         * @param context The current context.         */        public void onEndElement(String uri, String tag, AntXMLContext context) {            context.popWrapper();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -