bodewig     2003/05/14 05:49:14

  Modified:    docs/manual/CoreTypes propertyset.html
               src/main/org/apache/tools/ant/types PropertySet.java
  Log:
  Add new builtin attribute to <propertyset> that selects certain
  predefined propertysets.
  
  Revision  Changes    Path
  1.2       +10 -1     ant/docs/manual/CoreTypes/propertyset.html
  
  Index: propertyset.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTypes/propertyset.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- propertyset.html  12 May 2003 15:19:18 -0000      1.1
  +++ propertyset.html  14 May 2003 12:49:14 -0000      1.2
  @@ -42,7 +42,7 @@
     <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>
  @@ -55,6 +55,15 @@
         regular expression.  Similar to <a
         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>
   
  
  
  
  1.4       +47 -3     ant/src/main/org/apache/tools/ant/types/PropertySet.java
  
  Index: PropertySet.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/PropertySet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PropertySet.java  12 May 2003 14:00:10 -0000      1.3
  +++ PropertySet.java  14 May 2003 12:49:14 -0000      1.4
  @@ -90,6 +90,7 @@
           private String name;
           private String regex;
           private String prefix;
  +        private String builtin;
   
           public void setName(String name) {
               assertValid("name", name);
  @@ -106,6 +107,12 @@
               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 String toString() {
  -            return "name=" + name + ", regex=" + regex + ", prefix=" + 
prefix;
  +            return "name=" + name + ", regex=" + regex + ", prefix=" + prefix
  +                + ", builtin=" + builtin;
           }
   
       }
  @@ -141,6 +149,12 @@
           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 @@
                           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 @@
           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
   
  
  
  

Reply via email to