@@ -18,6 +18,9 @@
package org.apache.tools.ant.types;
package org.apache.tools.ant.types;
import java.util.Enumeration;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.HashSet;
import java.util.Set;
import java.util.Hashtable;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Properties;
import java.util.Stack;
import java.util.Stack;
@@ -25,6 +28,7 @@ import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.PropertyHelper;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.regexp.RegexpMatcher;
import org.apache.tools.ant.util.regexp.RegexpMatcher;
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
@@ -37,7 +41,8 @@ import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
public class PropertySet extends DataType {
public class PropertySet extends DataType {
private boolean dynamic = true;
private boolean dynamic = true;
private Vector cachedNames;
private boolean negate = false;
private Set cachedNames;
private Vector ptyRefs = new Vector();
private Vector ptyRefs = new Vector();
private Vector setRefs = new Vector();
private Vector setRefs = new Vector();
private Mapper _mapper;
private Mapper _mapper;
@@ -145,6 +150,11 @@ public class PropertySet extends DataType {
this.dynamic = dynamic;
this.dynamic = dynamic;
}
}
public void setNegate(boolean negate) {
assertNotReference();
this.negate = negate;
}
public boolean getDynamic() {
public boolean getDynamic() {
return isReference() ? getRef().dynamic : dynamic;
return isReference() ? getRef().dynamic : dynamic;
}
}
@@ -154,19 +164,29 @@ public class PropertySet extends DataType {
}
}
public Properties getProperties() {
public Properties getProperties() {
Vector names = null;
Set names = null;
Project prj = getProject();
Project prj = getProject();
Hashtable props =
Hashtable props =
prj == null ? System.getProperties() : prj.getProperties();
prj == null ? System.getProperties() : prj.getProperties();
if (getDynamic() || cachedNames == null) {
if (getDynamic() || cachedNames == null) {
names = new Vector(); // :TODO: should be a Set!
names = new HashSet();
if (isReference()) {
if (isReference()) {
getRef().addPropertyNames(names, props);
getRef().addPropertyNames(names, props);
} else {
} else {
addPropertyNames(names, props);
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()) {
if (!getDynamic()) {
cachedNames = names;
cachedNames = names;
}
}
@@ -180,8 +200,8 @@ public class PropertySet extends DataType {
mapper = myMapper.getImplementation();
mapper = myMapper.getImplementation();
}
}
Properties properties = new Properties();
Properties properties = new Properties();
for (Enumeration e = names.elements(); e.hasMoreElements ();) {
String name = (String) e.nextElemen t();
for (Iterator iter = names.iterator(); iter.hasNext ();) {
String name = (String) it er .next();
String value = (String) props.get(name);
String value = (String) props.get(name);
if (mapper != null) {
if (mapper != null) {
String[] newname = mapper.mapFileName(name);
String[] newname = mapper.mapFileName(name);
@@ -195,12 +215,12 @@ public class PropertySet extends DataType {
}
}
/**
/**
* @param names the output vector to fill with the property names
* @param names the output Set to fill with the property names
* matching this PropertySet selection criteria.
* matching this PropertySet selection criteria.
* @param properties the current Project properties, passed in to
* @param properties the current Project properties, passed in to
* avoid needless duplication of the Hashtable during recursion.
* avoid needless duplication of the Hashtable during recursion.
*/
*/
private void addPropertyNames(Vector names, Hashtable properties) {
private void addPropertyNames(Set names, Hashtable properties) {
Project prj = getProject();
Project prj = getProject();
// Add this PropertySet's property names.
// Add this PropertySet's property names.
@@ -208,13 +228,13 @@ public class PropertySet extends DataType {
PropertyRef ref = (PropertyRef) e.nextElement();
PropertyRef ref = (PropertyRef) e.nextElement();
if (ref.name != null) {
if (ref.name != null) {
if (prj != null && prj.getProperty(ref.name) != null) {
if (prj != null && prj.getProperty(ref.name) != null) {
names.addElement (ref.name);
names.add(ref.name);
}
}
} else if (ref.prefix != null) {
} else if (ref.prefix != null) {
for (Enumeration p = properties.keys(); p.hasMoreElements();) {
for (Enumeration p = properties.keys(); p.hasMoreElements();) {
String name = (String) p.nextElement();
String name = (String) p.nextElement();
if (name.startsWith(ref.prefix)) {
if (name.startsWith(ref.prefix)) {
names.addElement (name);
names.add(name);
}
}
}
}
} else if (ref.regex != null) {
} else if (ref.regex != null) {
@@ -224,38 +244,26 @@ public class PropertySet extends DataType {
for (Enumeration p = properties.keys(); p.hasMoreElements();) {
for (Enumeration p = properties.keys(); p.hasMoreElements();) {
String name = (String) p.nextElement();
String name = (String) p.nextElement();
if (matcher.matches(name)) {
if (matcher.matches(name)) {
names.addElement (name);
names.add(name);
}
}
}
}
} else if (ref.builtin != null) {
} else if (ref.builtin != null) {
Enumeration e2 = null;
if (ref.builtin.equals(BuiltinPropertySetName.ALL)) {
if (ref.builtin.equals(BuiltinPropertySetName.ALL)) {
e2 = properties.keys( );
names.addAll(properties.keySet() );
} else if (ref.builtin.equals(BuiltinPropertySetName.SYSTEM)) {
} else if (ref.builtin.equals(BuiltinPropertySetName.SYSTEM)) {
e2 = System.getProperties().keys( );
names.addAll(System.getProperties().keySet() );
} else if (ref.builtin.equals(BuiltinPropertySetName
} else if (ref.builtin.equals(BuiltinPropertySetName
.COMMANDLINE)) {
.COMMANDLINE)) {
e2 = getProject().getUserProperties().keys( );
names.addAll(getProject().getUserProperties().keySet() );
} else {
} else {
throw new BuildException("Impossible: Invalid builtin "
throw new BuildException("Impossible: Invalid builtin "
+ "attribute!");
+ "attribute!");
}
}
while (e2.hasMoreElements()) {
names.addElement(e2.nextElement());
}
} else {
} else {
throw new BuildException("Impossible: Invalid PropertyRef!");
throw new BuildException("Impossible: Invalid PropertyRef!");
}
}
}
}
// Add this PropertySet's nested PropertySets' property names.
for (Enumeration e = setRefs.elements(); e.hasMoreElements();) {
PropertySet set = (PropertySet) e.nextElement();
set.addPropertyNames(names, properties);
}
}
}
/**
/**