@@ -36,6 +36,12 @@ public class ResolvePropertyMap implements GetProperty {
private final GetProperty master;
private Map map;
private String prefix;
// whether properties of the value side of the map should be
// expanded
private boolean prefixValues = false;
// whether the current getProperty call is expanding the key side
// of the map
private boolean expandingLHS = true;
/**
* Constructor with a master getproperty and a collection of expanders.
@@ -59,19 +65,20 @@ public class ResolvePropertyMap implements GetProperty {
"Property " + name + " was circularly " + "defined.");
}
// if the property has already been set to the name it will
// have in the end, then return the existing value to ensure
// properties remain immutable
String masterPropertyName = name;
if (prefix != null) {
masterPropertyName = prefix + name;
}
Object masterProperty = master.getProperty(masterPropertyName);
if (masterProperty != null) {
return masterProperty;
}
try {
String fullKey = name;
if (prefix != null && prefixValues) {
fullKey = prefix + name;
}
Object masterValue = expandingLHS
? null : master.getProperty(fullKey);
// if the property is defined outside of this map don't
// consult the map at all.
if (masterValue != null) {
return masterValue;
}
expandingLHS = false;
seen.add(name);
return parseProperties.parseProperties((String) map.get(name));
} finally {
@@ -82,10 +89,10 @@ public class ResolvePropertyMap implements GetProperty {
/**
* The action method - resolves all the properties in a map.
* @param map the map to resolve properties in.
* @deprecated since Ant 1.8.1, use the two -arg method instead.
* @deprecated since Ant 1.8.2, use the three -arg method instead.
*/
public void resolveAllProperties(Map map) {
resolveAllProperties(map, null);
resolveAllProperties(map, null, false );
}
/**
@@ -93,13 +100,44 @@ public class ResolvePropertyMap implements GetProperty {
* @param map the map to resolve properties in.
* @param prefix the prefix the properties defined inside the map
* will finally receive - may be null.
* @deprecated since Ant 1.8.2, use the three-arg method instead.
*/
public void resolveAllProperties(Map map, String prefix) {
this.map = map; // The map gets used in the getProperty callback
resolveAllProperties(map, null, false);
}
/**
* The action method - resolves all the properties in a map.
* @param map the map to resolve properties in.
* @param prefix the prefix the properties defined inside the map
* will finally receive - may be null.
* @param prefixValues - whether the prefix will be applied
* to properties on the value side of the map as well.
*/
public void resolveAllProperties(Map map, String prefix,
boolean prefixValues) {
// The map, prefix and prefixValues flag get used in the
// getProperty callback
this.map = map;
this.prefix = prefix;
this.prefixValues = prefixValues;
for (Iterator i = map.keySet().iterator(); i.hasNext();) {
expandingLHS = true;
String key = (String) i.next();
Object result = getProperty(key);
// if the property has already been set to the name it
// will have in the end, then return the existing value to
// ensure properties remain immutable
String fullKey = key;
if (prefix != null) {
fullKey = prefix + key;
}
Object result = master.getProperty(fullKey);
if (result == null) {
result = getProperty(key);
}
String value = result == null ? "" : result.toString();
map.put(key, value);
}