ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1090354 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/types/PropertySet.java
Date Fri, 08 Apr 2011 17:20:08 GMT
Author: mbenson
Date: Fri Apr  8 17:20:08 2011
New Revision: 1090354

URL: http://svn.apache.org/viewvc?rev=1090354&view=rev
Log:
Resource collection implementation of mapped PropertySet returned unusable resources.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/types/PropertySet.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1090354&r1=1090353&r2=1090354&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Apr  8 17:20:08 2011
@@ -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:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/PropertySet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/PropertySet.java?rev=1090354&r1=1090353&r2=1090354&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/PropertySet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/PropertySet.java Fri Apr  8 17:20:08
2011
@@ -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 DataTyp
             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 DataTyp
         } 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 DataTyp
             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();



Mime
View raw message