Browse Source

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
master
Matthew Jason Benson 14 years ago
parent
commit
14ea08b49e
2 changed files with 51 additions and 32 deletions
  1. +3
    -0
      WHATSNEW
  2. +48
    -32
      src/main/org/apache/tools/ant/types/PropertySet.java

+ 3
- 0
WHATSNEW View File

@@ -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:
--------------



+ 48
- 32
src/main/org/apache/tools/ant/types/PropertySet.java View File

@@ -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();


Loading…
Cancel
Save