📄 propertyset.java
字号:
public Mapper getMapper() { return isReference() ? getRef().mapper : mapper; } /** * Convert the system properties to a hashtable. * Use propertynames to get the list of properties (including * default ones). */ private Hashtable getAllSystemProperties() { Hashtable ret = new Hashtable(); for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); ret.put(name, System.getProperties().getProperty(name)); } return ret; } /** * This is the operation to get the existing or recalculated properties. * @return the properties for this propertyset. */ public Properties getProperties() { if (isReference()) { return getRef().getProperties(); } Set names = null; Project prj = getProject(); Hashtable props = prj == null ? getAllSystemProperties() : prj.getProperties(); //quick & dirty, to make nested mapped p-sets work: for (Enumeration e = setRefs.elements(); e.hasMoreElements();) { PropertySet set = (PropertySet) e.nextElement(); props.putAll(set.getProperties()); } if (getDynamic() || cachedNames == null) { names = new HashSet(); addPropertyNames(names, props); // Add this PropertySet's nested PropertySets' property names. for (Enumeration e = setRefs.elements(); e.hasMoreElements();) { PropertySet set = (PropertySet) e.nextElement(); names.addAll(set.getProperties().keySet()); } if (negate) { //make a copy... HashSet complement = new HashSet(props.keySet()); complement.removeAll(names); names = complement; } if (!getDynamic()) { cachedNames = names; } } else { names = cachedNames; } FileNameMapper m = null; Mapper myMapper = getMapper(); if (myMapper != null) { m = myMapper.getImplementation(); } Properties properties = new Properties(); //iterate through the names, get the matching values for (Iterator iter = names.iterator(); iter.hasNext();) { String name = (String) iter.next(); String value = (String) props.get(name); if (value != null) { // may be null if a system property has been added // after the project instance has been initialized if (m != null) { //map the names String[] newname = m.mapFileName(name); if (newname != null) { name = newname[0]; } } properties.setProperty(name, value); } } return properties; } /** * @param names the output Set to fill with the property names * matching this PropertySet selection criteria. * @param properties the current Project properties, passed in to * avoid needless duplication of the Hashtable during recursion. */ private void addPropertyNames(Set names, Hashtable properties) { // Add this PropertySet's property names. for (Enumeration e = ptyRefs.elements(); e.hasMoreElements();) { PropertyRef r = (PropertyRef) e.nextElement(); if (r.name != null) { if (properties.get(r.name) != null) { names.add(r.name); } } else if (r.prefix != null) { for (Enumeration p = properties.keys(); p.hasMoreElements();) { String name = (String) p.nextElement(); if (name.startsWith(r.prefix)) { names.add(name); } } } else if (r.regex != null) { RegexpMatcherFactory matchMaker = new RegexpMatcherFactory(); RegexpMatcher matcher = matchMaker.newRegexpMatcher(); matcher.setPattern(r.regex); for (Enumeration p = properties.keys(); p.hasMoreElements();) { String name = (String) p.nextElement(); if (matcher.matches(name)) { names.add(name); } } } else if (r.builtin != null) { if (r.builtin.equals(BuiltinPropertySetName.ALL)) { names.addAll(properties.keySet()); } else if (r.builtin.equals(BuiltinPropertySetName.SYSTEM)) { names.addAll(System.getProperties().keySet()); } else if (r.builtin.equals(BuiltinPropertySetName .COMMANDLINE)) { names.addAll(getProject().getUserProperties().keySet()); } else { throw new BuildException("Impossible: Invalid builtin " + "attribute!"); } } else { throw new BuildException("Impossible: Invalid PropertyRef!"); } } } /** * Performs the check for circular references and returns the * referenced PropertySet. * @return the referenced PropertySet. */ protected PropertySet getRef() { return (PropertySet) getCheckedRef(PropertySet.class, "propertyset"); } /** * Sets the value of the refid attribute. * * @param r the reference this datatype should point to. * @throws BuildException if another attribute was set, since * refid and all other attributes are mutually exclusive. */ public final void setRefid(Reference r) { if (!noAttributeSet) { throw tooManyAttributes(); } super.setRefid(r); } /** * Ensures this data type is not a reference. * * <p>Calling this method as the first line of every bean method of * this data type (setXyz, addXyz, createXyz) ensure proper handling * of the refid attribute.</p> * * @throws BuildException if the refid attribute was already set, since * refid and all other attributes are mutually exclusive. */ protected final void assertNotReference() { if (isReference()) { throw tooManyAttributes(); } noAttributeSet = false; } /** * Flag which tracks whether any attribute has been set; used by * {@link #assertNotReference()} and {@link #setRefid(Reference)}. */ private boolean noAttributeSet = true; /** * Used for propertyref's builtin attribute. */ public static class BuiltinPropertySetName extends EnumeratedAttribute { static final String ALL = "all"; static final String SYSTEM = "system"; static final String COMMANDLINE = "commandline"; /** {@inheritDoc}. */ public String[] getValues() { return new String[] {ALL, SYSTEM, COMMANDLINE}; } } /** * A debug toString. * This gets a comma separated list of key=value pairs for * the properties in the set. * The output order is sorted according to the keys' <i>natural order</i>. * @return a string rep of this object. */ public String toString() { StringBuffer b = new StringBuffer(); TreeMap sorted = new TreeMap(getProperties()); for (Iterator i = sorted.entrySet().iterator(); i.hasNext();) { Map.Entry e = (Map.Entry) i.next(); if (b.length() != 0) { b.append(", "); } b.append(e.getKey().toString()); b.append("="); b.append(e.getValue().toString()); } return b.toString(); } /** * Fulfill the ResourceCollection interface. * @return an Iterator of Resources. * @since Ant 1.7 */ public Iterator iterator() { final Enumeration e = getProperties().propertyNames(); return new Iterator() { public boolean hasNext() { return e.hasMoreElements(); } public Object next() { return new PropertyResource(getProject(), (String) e.nextElement()); } public void remove() { throw new UnsupportedOperationException(); } }; } /** * Fulfill the ResourceCollection contract. * @return the size of this ResourceCollection. */ public int size() { return isReference() ? getRef().size() : getProperties().size(); } /** * Fulfill the ResourceCollection contract. * @return whether this is a filesystem-only resource collection. */ public boolean isFilesystemOnly() { return isReference() && getRef().isFilesystemOnly(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -