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

📄 componenthelper.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        }                        if (Task.class.isAssignableFrom(clazz)) {                            taskClassDefinitions.put(                                name, antTypeTable.getTypeClass(name));                        }                    }                    rebuildTaskClassDefinitions = false;                }            }        }        return taskClassDefinitions;    }    /**     * Returns the current type definition hashtable. The returned hashtable is     * "live" and so should not be modified.     *     * @return a map of from type name to implementing class     *         (String to Class).     */    public Hashtable getDataTypeDefinitions() {        synchronized (typeClassDefinitions) {            synchronized (antTypeTable) {                if (rebuildTypeClassDefinitions) {                    typeClassDefinitions.clear();                    for (Iterator i = antTypeTable.keySet().iterator();                         i.hasNext();) {                        String name = (String) i.next();                        Class clazz = antTypeTable.getExposedClass(name);                        if (clazz == null) {                            continue;                        }                        if (!(Task.class.isAssignableFrom(clazz))) {                            typeClassDefinitions.put(                                name, antTypeTable.getTypeClass(name));                        }                    }                    rebuildTypeClassDefinitions = false;                }            }        }        return typeClassDefinitions;    }    /**     * Adds a new datatype definition.     * Attempting to override an existing definition with an     * equivalent one (i.e. with the same classname) results in     * a verbose log message. Attempting to override an existing definition     * with a different one results in a warning log message, but the     * definition is changed.     *     * @param typeName The name of the datatype.     *                 Must not be <code>null</code>.     * @param typeClass The full name of the class implementing the datatype.     *                  Must not be <code>null</code>.     */    public void addDataTypeDefinition(String typeName, Class typeClass) {        AntTypeDefinition def = new AntTypeDefinition();        def.setName(typeName);        def.setClass(typeClass);        updateDataTypeDefinition(def);        project.log(" +User datatype: " + typeName + "     "                + typeClass.getName(), Project.MSG_DEBUG);    }    /**     * Describe <code>addDataTypeDefinition</code> method here.     *     * @param def an <code>AntTypeDefinition</code> value.     */    public void addDataTypeDefinition(AntTypeDefinition def) {        updateDataTypeDefinition(def);    }    /**     * Returns the current datatype definition hashtable. The returned     * hashtable is "live" and so should not be modified.     *     * @return a map of from datatype name to implementing class     *         (String to Class).     */    public Hashtable getAntTypeTable() {        return antTypeTable;    }    /**     * Creates a new instance of a task.     *     *  Called from Project.createTask(), which can be called by tasks.     *     * @param taskType The name of the task to create an instance of.     *                 Must not be <code>null</code>.     *     * @return an instance of the specified task, or <code>null</code> if     *         the task name is not recognised.     *     * @exception BuildException if the task name is recognised but task     *                           creation fails.     */    public Task createTask(String taskType) throws BuildException {        Task task = createNewTask(taskType);        if (task == null && taskType.equals(ANT_PROPERTY_TASK)) {            // quick fix for Ant.java use of property before            // initializing the project            addTaskDefinition(ANT_PROPERTY_TASK,                              org.apache.tools.ant.taskdefs.Property.class);            task = createNewTask(taskType);        }        return task;    }    /**     * Creates a new instance of a task.     * @since ant1.6     * @param taskType The name of the task to create an instance of.     *                 Must not be <code>null</code>.     *     * @return an instance of the specified task, or <code>null</code> if     *         the task name is not recognised.     *     * @exception BuildException if the task name is recognised but task     *                           creation fails.     */    private Task createNewTask(String taskType) throws BuildException {        Class c = getComponentClass(taskType);        if (c == null || !(Task.class.isAssignableFrom(c))) {            return null;        }        Object obj = createComponent(taskType);        if (obj == null) {            return null;        }        if (!(obj instanceof Task)) {            throw new BuildException(                "Expected a Task from '" + taskType                + "' but got an instance of " + obj.getClass().getName()                + " instead");        }        Task task = (Task) obj;        task.setTaskType(taskType);        // set default value, can be changed by the user        task.setTaskName(taskType);        project.log("   +Task: " + taskType, Project.MSG_DEBUG);        return task;    }    /**     * Creates a new instance of a data type.     *     * @param typeName The name of the data type to create an instance of.     *                 Must not be <code>null</code>.     *     * @return an instance of the specified data type, or <code>null</code> if     *         the data type name is not recognised.     *     * @exception BuildException if the data type name is recognised but     *                           instance creation fails.     */    public Object createDataType(String typeName) throws BuildException {        return createComponent(typeName);    }    /**     * Returns a description of the type of the given element.     * <p>     * This is useful for logging purposes.     *     * @param element The element to describe.     *                Must not be <code>null</code>.     *     * @return a description of the element type.     *     * @since Ant 1.6     */    public String getElementName(Object element) {        return getElementName(element, false);    }    /**     * Returns a description of the type of the given element.     * <p>     * This is useful for logging purposes.     *     * @param o     The element to describe.     *              Must not be <code>null</code>.     * @param brief whether to use a brief description.     * @return a description of the element type.     *     * @since Ant 1.7     */    public String getElementName(Object o, boolean brief) {        //  PR: I do not know what to do if the object class        //      has multiple defines        //      but this is for logging only...        Class elementClass = o.getClass();        String elementClassname = elementClass.getName();        for (Iterator i = antTypeTable.values().iterator(); i.hasNext();) {            AntTypeDefinition def = (AntTypeDefinition) i.next();            if (elementClassname.equals(def.getClassName())                    && (elementClass == def.getExposedClass(project))) {                String name = def.getName();                return brief ? name : "The <" + name + "> type";            }        }        return getUnmappedElementName(o.getClass(), brief);    }    /**     * Convenient way to get some element name even when you may not have a     * Project context.     * @param p       The optional Project instance.     * @param o       The element to describe.     *                Must not be <code>null</code>.     * @param brief   whether to use a brief description.     * @return a description of the element type.     * @since Ant 1.7     */    public static String getElementName(Project p, Object o, boolean brief) {        if (p == null) {            p = Project.getProject(o);        }        return p == null ? getUnmappedElementName(o.getClass(), brief)                : getComponentHelper(p).getElementName(o, brief);    }    private static String getUnmappedElementName(Class c, boolean brief) {        if (brief) {            String name = c.getName();            return name.substring(name.lastIndexOf('.') + 1);        }        return c.toString();    }    /**     * Check if definition is a valid definition--it may be a     * definition of an optional task that does not exist.     * @param def the definition to test.     * @return true if exposed type of definition is present.     */    private boolean validDefinition(AntTypeDefinition def) {        return !(def.getTypeClass(project) == null            || def.getExposedClass(project) == null);    }    /**     * Check if two definitions are the same.     * @param def  the new definition.     * @param old the old definition.     * @return true if the two definitions are the same.     */    private boolean sameDefinition(        AntTypeDefinition def, AntTypeDefinition old) {        boolean defValid = validDefinition(def);        boolean sameValidity = (defValid == validDefinition(old));        //must have same validity; then if they are valid they must also be the same:        return sameValidity && (!defValid || def.sameDefinition(old, project));    }    /**     * Update the component definition table with a new or     * modified definition.     * @param def the definition to update or insert.     */    private void updateDataTypeDefinition(AntTypeDefinition def) {        String name = def.getName();        synchronized (antTypeTable) {            rebuildTaskClassDefinitions = true;            rebuildTypeClassDefinitions = true;            AntTypeDefinition old = antTypeTable.getDefinition(name);            if (old != null) {                if (sameDefinition(def, old)) {                    return;                }                Class oldClass = antTypeTable.getExposedClass(name);                boolean isTask =                    (oldClass != null && Task.class.isAssignableFrom(oldClass));                project.log("Trying to override old definition of "                    + (isTask ? "task " : "datatype ") + name,                    (def.similarDefinition(old, project))                    ? Project.MSG_VERBOSE : Project.MSG_WARN);            }            project.log(" +Datatype " + name + " " + def.getClassName(),                        Project.MSG_DEBUG);            antTypeTable.put(name, def);        }    }    /**     * Called at the start of processing an antlib.     * @param uri the uri that is associated with this antlib.     */    public void enterAntLib(String uri) {        antLibCurrentUri = uri;        antLibStack.push(uri);    }    /**     * @return the current antlib uri.     */    public String getCurrentAntlibUri() {        return antLibCurrentUri;    }    /**     * Called at the end of processing an antlib.     */    public void exitAntLib() {        antLibStack.pop();        antLibCurrentUri = (antLibStack.size() == 0)            ? null : (String) antLibStack.peek();    }    /**     * Load ant's tasks.     */    private void initTasks() {        ClassLoader classLoader = getClassLoader(null);        Properties props = getDefaultDefinitions(false);        Enumeration e = props.propertyNames();        while (e.hasMoreElements()) {            String name = (String) e.nextElement();            String className = props.getProperty(name);            AntTypeDefinition def = new AntTypeDefinition();            def.setName(name);            def.setClassName(className);            def.setClassLoader(classLoader);            def.setAdaptToClass(Task.class);            def.setAdapterClass(TaskAdapter.class);            antTypeTable.put(name, def);        }    }    private ClassLoader getClassLoader(ClassLoader classLoader) {        String buildSysclasspath = project.getProperty(MagicNames.BUILD_SYSCLASSPATH);        if (project.getCoreLoader() != null            && !(BUILD_SYSCLASSPATH_ONLY.equals(buildSysclasspath))) {            classLoader = project.getCoreLoader();        }        return classLoader;    }    /**     * Load default task or type definitions - just the names,     *  no class loading.     * Caches results between calls to reduce overhead.     * @param type true for typedefs, false for taskdefs     * @return a mapping from definition names to class names     * @throws BuildException if there was some problem loading     *                        or parsing the definitions list     */    private static synchronized Properties getDefaultDefinitions(boolean type)        throws BuildException {        int idx = type ? 1 : 0;        if (defaultDefinitions[idx] == null) {            String resource = type

⌨️ 快捷键说明

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