From 14ea08b49e98e020cde9265cc199b40a42990337 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 8 Apr 2011 17:20:08 +0000 Subject: [PATCH] Resource collection implementation of mapped PropertySet returned unusable resources. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1090354 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 + .../apache/tools/ant/types/PropertySet.java | 80 +++++++++++-------- 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 4adbd8f47..ada6b42af 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -34,6 +34,9 @@ Fixed bugs: * FileResource specified using basedir/name attributes was non-functional. + * Resource collection implementation of mapped PropertySet returned + unusable resources. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/types/PropertySet.java b/src/main/org/apache/tools/ant/types/PropertySet.java index 2ac084398..4a94084c8 100644 --- a/src/main/org/apache/tools/ant/types/PropertySet.java +++ b/src/main/org/apache/tools/ant/types/PropertySet.java @@ -31,6 +31,7 @@ import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.resources.MappedResource; import org.apache.tools.ant.types.resources.PropertyResource; import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.regexp.RegexpMatcher; @@ -292,17 +293,48 @@ public class PropertySet extends DataType implements ResourceCollection { return getRef().getProperties(); } dieOnCircularReference(); - Set names = null; - Project prj = getProject(); - Hashtable props = - prj == null ? getAllSystemProperties() : prj.getProperties(); + Hashtable props = getEffectiveProperties(); + Set names = getPropertyNames(props); + + 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; + } + private Hashtable getEffectiveProperties() { + Project prj = getProject(); + Hashtable result = 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()); + result.putAll(set.getProperties()); } + return result; + } + private Set getPropertyNames(Hashtable props) { + Set names; if (getDynamic() || cachedNames == null) { names = new HashSet(); addPropertyNames(names, props); @@ -323,30 +355,7 @@ public class PropertySet extends DataType implements ResourceCollection { } 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; + return names; } /** @@ -498,13 +507,20 @@ public class PropertySet extends DataType implements ResourceCollection { return getRef().iterator(); } dieOnCircularReference(); - final Enumeration e = getProperties().propertyNames(); + Hashtable props = getEffectiveProperties(); + Set names = getPropertyNames(props); + + Mapper myMapper = getMapper(); + final FileNameMapper m = myMapper == null ? null : myMapper.getImplementation(); + final Iterator iter = names.iterator(); + return new Iterator() { public boolean hasNext() { - return e.hasMoreElements(); + return iter.hasNext(); } public Object next() { - return new PropertyResource(getProject(), (String) e.nextElement()); + PropertyResource p = new PropertyResource(getProject(), (String) iter.next()); + return m == null ? (Resource) p : new MappedResource(p, m); } public void remove() { throw new UnsupportedOperationException();