From 741b777b460e22b0faa75afe9c2320025f90adc1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 14 May 2003 12:49:14 +0000 Subject: [PATCH] Add new builtin attribute to that selects certain predefined propertysets. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274576 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTypes/propertyset.html | 11 +++- .../apache/tools/ant/types/PropertySet.java | 50 +++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/docs/manual/CoreTypes/propertyset.html b/docs/manual/CoreTypes/propertyset.html index 2402d3652..8b642c6ec 100644 --- a/docs/manual/CoreTypes/propertyset.html +++ b/docs/manual/CoreTypes/propertyset.html @@ -42,7 +42,7 @@ set.

name Select the property with the given name. - Exactly one of these. + Exactly one of these. prefix @@ -56,6 +56,15 @@ set.

href="mapper.html#regexp-mapper">regexp type mappers, this equires a supported regular expression library. + + builtin + Selects a builtin set of properties. Valid + values for this attribute are all for all Ant + properties, system for the system properties and + commandline for all properties specified on the + command line when invoking Ant (plus a number of special + internal Ant properties). +

propertyset

diff --git a/src/main/org/apache/tools/ant/types/PropertySet.java b/src/main/org/apache/tools/ant/types/PropertySet.java index 410983248..f2059ba85 100644 --- a/src/main/org/apache/tools/ant/types/PropertySet.java +++ b/src/main/org/apache/tools/ant/types/PropertySet.java @@ -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