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

📄 propertyhelper.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (done) {            return true;        }        if (null != properties.get(name) && verbose) {            project.log("Overriding previous definition of property \"" + name                    + "\"", Project.MSG_VERBOSE);        }        if (verbose) {            project.log("Setting project property: " + name + " -> "                    + value, Project.MSG_DEBUG);        }        if (name != null && value != null) {            properties.put(name, value);        }        return true;    }    /**     * Sets a property if no value currently exists. If the property     * exists already, a message is logged and the method returns with     * no other effect.     *     * @param ns   The namespace for the property (currently not used).     * @param name The name of property to set.     *             Must not be <code>null</code>.     * @param value The new value of the property.     *              Must not be <code>null</code>.     * @since Ant 1.6     */    public synchronized void setNewProperty(String ns, String name,                                            Object value) {        if (null != properties.get(name)) {            project.log("Override ignored for property \"" + name                    + "\"", Project.MSG_VERBOSE);            return;        }        boolean done = setPropertyHook(ns, name, value, false, false, true);        if (done) {            return;        }        project.log("Setting project property: " + name + " -> "                + value, Project.MSG_DEBUG);        if (name != null && value != null) {            properties.put(name, value);        }    }    /**     * Sets a user property, which cannot be overwritten by     * set/unset property calls. Any previous value is overwritten.     * @param ns   The namespace for the property (currently not used).     * @param name The name of property to set.     *             Must not be <code>null</code>.     * @param value The new value of the property.     *              Must not be <code>null</code>.     */    public synchronized void setUserProperty(String ns, String name,                                             Object value) {        project.log("Setting ro project property: " + name + " -> "                + value, Project.MSG_DEBUG);        userProperties.put(name, value);        boolean done = setPropertyHook(ns, name, value, false, true, false);        if (done) {            return;        }        properties.put(name, value);    }    /**     * Sets an inherited user property, which cannot be overwritten by set/unset     * property calls. Any previous value is overwritten. Also marks     * these properties as properties that have not come from the     * command line.     *     * @param ns   The namespace for the property (currently not used).     * @param name The name of property to set.     *             Must not be <code>null</code>.     * @param value The new value of the property.     *              Must not be <code>null</code>.     */    public synchronized void setInheritedProperty(String ns, String name,                                                  Object value) {        inheritedProperties.put(name, value);        project.log("Setting ro project property: " + name + " -> "                + value, Project.MSG_DEBUG);        userProperties.put(name, value);        boolean done = setPropertyHook(ns, name, value, true, false, false);        if (done) {            return;        }        properties.put(name, value);    }    // -------------------- Getting properties  --------------------    /**     * Returns the value of a property, if it is set.  You can override     * this method in order to plug your own storage.     *     * @param ns   The namespace for the property (currently not used).     * @param name The name of the property.     *             May be <code>null</code>, in which case     *             the return value is also <code>null</code>.     * @return the property value, or <code>null</code> for no match     *         or if a <code>null</code> name is provided.     */    public synchronized Object getProperty(String ns, String name) {        if (name == null) {            return null;        }        Object o = getPropertyHook(ns, name, false);        if (o != null) {            return o;        }        return properties.get(name);    }    /**     * Returns the value of a user property, if it is set.     *     * @param ns   The namespace for the property (currently not used).     * @param name The name of the property.     *             May be <code>null</code>, in which case     *             the return value is also <code>null</code>.     * @return the property value, or <code>null</code> for no match     *         or if a <code>null</code> name is provided.     */    public synchronized Object getUserProperty(String ns, String name) {        if (name == null) {            return null;        }        Object o = getPropertyHook(ns, name, true);        if (o != null) {            return o;        }        return userProperties.get(name);    }    // -------------------- Access to property tables  --------------------    // This is used to support ant call and similar tasks. It should be    // deprecated, it is possible to use a better (more efficient)    // mechanism to preserve the context.    /**     * Returns a copy of the properties table.     * @return a hashtable containing all properties (including user properties).     */    public Hashtable getProperties() {        //avoid concurrent modification:        synchronized (properties) {            return new Hashtable(properties);        }        // There is a better way to save the context. This shouldn't        // delegate to next, it's for backward compatibility only.    }    /**     * Returns a copy of the user property hashtable     * @return a hashtable containing just the user properties     */    public Hashtable getUserProperties() {        //avoid concurrent modification:        synchronized (userProperties) {            return new Hashtable(userProperties);        }    }    /**     * special back door for subclasses, internal access to the hashtables     * @return the live hashtable of all properties     */    protected Hashtable getInternalProperties() {        return properties;    }    /**     * special back door for subclasses, internal access to the hashtables     *     * @return the live hashtable of user properties     */    protected Hashtable getInternalUserProperties() {        return userProperties;    }    /**     * special back door for subclasses, internal access to the hashtables     *     * @return the live hashtable inherited properties     */    protected Hashtable getInternalInheritedProperties() {        return inheritedProperties;    }    /**     * Copies all user properties that have not been set on the     * command line or a GUI tool from this instance to the Project     * instance given as the argument.     *     * <p>To copy all "user" properties, you will also have to call     * {@link #copyUserProperties copyUserProperties}.</p>     *     * @param other the project to copy the properties to.  Must not be null.     *     * @since Ant 1.6     */    public void copyInheritedProperties(Project other) {        //avoid concurrent modification:        synchronized (inheritedProperties) {            Enumeration e = inheritedProperties.keys();            while (e.hasMoreElements()) {                String arg = e.nextElement().toString();                if (other.getUserProperty(arg) != null) {                    continue;                }                Object value = inheritedProperties.get(arg);                other.setInheritedProperty(arg, value.toString());            }        }    }    /**     * Copies all user properties that have been set on the command     * line or a GUI tool from this instance to the Project instance     * given as the argument.     *     * <p>To copy all "user" properties, you will also have to call     * {@link #copyInheritedProperties copyInheritedProperties}.</p>     *     * @param other the project to copy the properties to.  Must not be null.     *     * @since Ant 1.6     */    public void copyUserProperties(Project other) {        //avoid concurrent modification:        synchronized (userProperties) {            Enumeration e = userProperties.keys();            while (e.hasMoreElements()) {                Object arg = e.nextElement();                if (inheritedProperties.containsKey(arg)) {                    continue;                }                Object value = userProperties.get(arg);                other.setUserProperty(arg.toString(), value.toString());            }        }    }    // -------------------- Property parsing  --------------------    // Moved from ProjectHelper. You can override the static method -    // this is used for backward compatibility (for code that calls    // the parse method in ProjectHelper).    /** Default parsing method. It is here only to support backward compatibility     * for the static ProjectHelper.parsePropertyString().     */    static void parsePropertyStringDefault(String value, Vector fragments, Vector propertyRefs)            throws BuildException {        int prev = 0;        int pos;        //search for the next instance of $ from the 'prev' position        while ((pos = value.indexOf("$", prev)) >= 0) {            //if there was any text before this, add it as a fragment            //TODO, this check could be modified to go if pos>prev;            //seems like this current version could stick empty strings            //into the list            if (pos > 0) {                fragments.addElement(value.substring(prev, pos));            }            //if we are at the end of the string, we tack on a $            //then move past it            if (pos == (value.length() - 1)) {                fragments.addElement("$");                prev = pos + 1;            } else if (value.charAt(pos + 1) != '{') {                //peek ahead to see if the next char is a property or not                //not a property: insert the char as a literal                /*                fragments.addElement(value.substring(pos + 1, pos + 2));                prev = pos + 2;                */                if (value.charAt(pos + 1) == '$') {                    //backwards compatibility two $ map to one mode                    fragments.addElement("$");                    prev = pos + 2;                } else {                    //new behaviour: $X maps to $X for all values of X!='$'                    fragments.addElement(value.substring(pos, pos + 2));                    prev = pos + 2;                }            } else {                //property found, extract its name or bail on a typo                int endName = value.indexOf('}', pos);                if (endName < 0) {                    throw new BuildException("Syntax error in property: " + value);                }                String propertyName = value.substring(pos + 2, endName);                fragments.addElement(null);                propertyRefs.addElement(propertyName);                prev = endName + 1;            }        }        //no more $ signs found        //if there is any tail to the file, append it        if (prev < value.length()) {            fragments.addElement(value.substring(prev));        }    }}

⌨️ 快捷键说明

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