Browse Source

Add new builtin attribute to <propertyset> that selects certain

predefined propertysets.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274576 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
741b777b46
2 changed files with 57 additions and 4 deletions
  1. +10
    -1
      docs/manual/CoreTypes/propertyset.html
  2. +47
    -3
      src/main/org/apache/tools/ant/types/PropertySet.java

+ 10
- 1
docs/manual/CoreTypes/propertyset.html View File

@@ -42,7 +42,7 @@ set.</p>
<tr>
<td valign="top">name</td>
<td valign="top">Select the property with the given name.</td>
<td align="center" valign="top" rowspan="3">Exactly one of these.</td>
<td align="center" valign="top" rowspan="4">Exactly one of these.</td>
</tr>
<tr>
<td valign="top">prefix</td>
@@ -56,6 +56,15 @@ set.</p>
href="mapper.html#regexp-mapper">regexp type mappers</a>, this
equires a supported regular expression library.</td>
</tr>
<tr>
<td valign="top">builtin</td>
<td valign="top">Selects a builtin set of properties. Valid
values for this attribute are <code>all</code> for all Ant
properties, <code>system</code> for the system properties and
<code>commandline</code> for all properties specified on the
command line when invoking Ant (plus a number of special
internal Ant properties).</td>
</tr>
</table>

<h4>propertyset</h4>


+ 47
- 3
src/main/org/apache/tools/ant/types/PropertySet.java View File

@@ -90,6 +90,7 @@ public class PropertySet extends DataType {
private String name;
private String regex;
private String prefix;
private String builtin;

public void setName(String name) {
assertValid("name", name);
@@ -106,6 +107,12 @@ public class PropertySet extends DataType {
this.prefix = prefix;
}

public void setBuiltin(BuiltinPropertySetName b) {
String builtin = b.getValue();
assertValid("builtin", builtin);
this.builtin = builtin;
}

private void assertValid(String attr, String value) {
if (value == null || value.length() < 1) {
throw new BuildException("Invalid attribute: " + attr);
@@ -118,7 +125,8 @@ public class PropertySet extends DataType {
}

public String toString() {
return "name=" + name + ", regex=" + regex + ", prefix=" + prefix;
return "name=" + name + ", regex=" + regex + ", prefix=" + prefix
+ ", builtin=" + builtin;
}

}
@@ -141,6 +149,12 @@ public class PropertySet extends DataType {
addPropertyref(ref);
}

public void appendBuiltin(BuiltinPropertySetName b) {
PropertyRef ref = new PropertyRef();
ref.setBuiltin(b);
addPropertyref(ref);
}

public void setMapper(String type, String from, String to) {
Mapper mapper = createMapper();
Mapper.MapperType mapperType = new Mapper.MapperType();
@@ -256,8 +270,26 @@ public class PropertySet extends DataType {
names.addElement(name);
}
}
}
else {
} else if (ref.builtin != null) {

Enumeration enum = null;
if (ref.builtin.equals(BuiltinPropertySetName.ALL)) {
enum = properties.keys();
} else if (ref.builtin.equals(BuiltinPropertySetName.SYSTEM)) {
enum = System.getProperties().keys();
} else if (ref.builtin.equals(BuiltinPropertySetName
.COMMANDLINE)) {
enum = getProject().getUserProperties().keys();
} else {
throw new BuildException("Impossible: Invalid builtin "
+ "attribute!");
}

while (enum.hasMoreElements()) {
names.addElement(enum.nextElement());
}

} else {
throw new BuildException("Impossible: Invalid PropertyRef!");
}
}
@@ -321,5 +353,17 @@ public class PropertySet extends DataType {
noAttributeSet = false;
}
private boolean noAttributeSet = true;

/**
* Used for propertyref's builtin attribute.
*/
public static class BuiltinPropertySetName extends EnumeratedAttribute {
static final String ALL = "all";
static final String SYSTEM = "system";
static final String COMMANDLINE = "commandline";
public String[] getValues() {
return new String[] {ALL, SYSTEM, COMMANDLINE};
}
}
} // END class PropertySet


Loading…
Cancel
Save