ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs/optional EchoPropertiesTest.java
Date Fri, 23 Apr 2004 15:41:39 GMT
mbenson     2004/04/23 08:41:39

  Modified:    .        Tag: ANT_16_BRANCH WHATSNEW
               docs/manual/CoreTypes Tag: ANT_16_BRANCH propertyset.html
               src/etc/testcases/taskdefs/optional Tag: ANT_16_BRANCH
                        echoproperties.xml
               src/main/org/apache/tools/ant/types Tag: ANT_16_BRANCH
                        PropertySet.java
               src/testcases/org/apache/tools/ant/taskdefs/optional Tag:
                        ANT_16_BRANCH EchoPropertiesTest.java
  Log:
  merge <propertyset negate> to 1.6 branch.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.503.2.84 +2 -1      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.83
  retrieving revision 1.503.2.84
  diff -u -r1.503.2.83 -r1.503.2.84
  --- WHATSNEW	23 Apr 2004 15:32:13 -0000	1.503.2.83
  +++ WHATSNEW	23 Apr 2004 15:41:38 -0000	1.503.2.84
  @@ -4,7 +4,6 @@
   Changes that could break older environments:
   --------------------------------------------
   
  -
   Fixed bugs:
   -----------
   
  @@ -107,6 +106,8 @@
   
   * <nice> task lets you set the priority of the current thread; non-forking
     <java> code will inherit this priority in their main thread.
  +
  +* New attribute "negate" on <propertyset> to invert selection criteria.
   
   Changes from Ant 1.6.0 to Ant 1.6.1
   ===================================
  
  
  
  No                   revision
  No                   revision
  1.2.2.5   +11 -0     ant/docs/manual/CoreTypes/propertyset.html
  
  Index: propertyset.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTypes/propertyset.html,v
  retrieving revision 1.2.2.4
  retrieving revision 1.2.2.5
  diff -u -r1.2.2.4 -r1.2.2.5
  --- propertyset.html	9 Feb 2004 22:12:10 -0000	1.2.2.4
  +++ propertyset.html	23 Apr 2004 15:41:38 -0000	1.2.2.5
  @@ -26,6 +26,14 @@
         is used.  Default is &quot;<code>true</code>&quot;.</td>
       <td valign="top" align="center">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">negate</td>
  +    <td valign="top">Whether to negate results.  If
  +      &quot;<code>true</code>&quot;, all properties <i>not</i>
  +      selected by nested elements will be returned.
  +      Default is &quot;<code>false</code>&quot;.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   
  @@ -107,6 +115,9 @@
   
   <p>collects all properties whose name starts with &quot;foo&quot;, but
   changes the names to start with &quot;bar&quot; instead.</p>
  +
  +<p>If supplied, the nested mapper will be applied
  +subsequent to any negation of matched properties.</p>
   
   <hr>
   <p align="center">Copyright &copy; 2003-2004 The Apache Software Foundation.
All rights
  
  
  
  No                   revision
  No                   revision
  1.3.2.1   +18 -0     ant/src/etc/testcases/taskdefs/optional/echoproperties.xml
  
  Index: echoproperties.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/echoproperties.xml,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- echoproperties.xml	14 May 2003 12:40:18 -0000	1.3
  +++ echoproperties.xml	23 Apr 2004 15:41:38 -0000	1.3.2.1
  @@ -72,6 +72,24 @@
       </echoproperties>
     </target>
   
  +  <target name="testEchoPrefixAsNegatedPropertyset" depends="setup">
  +    <echoproperties destfile="test-prefix.properties">
  +      <propertyset negate="true">
  +        <propertyref prefix="b."/>
  +      </propertyset>
  +    </echoproperties>
  +  </target>
  +
  +  <target name="testEchoPrefixAsDoublyNegatedPropertyset" depends="setup">
  +    <echoproperties destfile="test-prefix.properties">
  +      <propertyset negate="true">
  +        <propertyset negate="true">
  +          <propertyref prefix="a."/>
  +        </propertyset>
  +      </propertyset>
  +    </echoproperties>
  +  </target>
  +
     <target name="cleanup">
       <delete file="test.properties" failonerror="no" />
       <delete file="test-prefix.properties" failonerror="no" />
  
  
  
  No                   revision
  No                   revision
  1.8.2.5   +40 -30    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.8.2.4
  retrieving revision 1.8.2.5
  diff -u -r1.8.2.4 -r1.8.2.5
  --- PropertySet.java	9 Mar 2004 17:01:55 -0000	1.8.2.4
  +++ PropertySet.java	23 Apr 2004 15:41:38 -0000	1.8.2.5
  @@ -18,6 +18,9 @@
   package org.apache.tools.ant.types;
   
   import java.util.Enumeration;
  +import java.util.Iterator;
  +import java.util.HashSet;
  +import java.util.Set;
   import java.util.Hashtable;
   import java.util.Properties;
   import java.util.Stack;
  @@ -25,6 +28,7 @@
   
   import org.apache.tools.ant.BuildException;
   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.regexp.RegexpMatcher;
   import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
  @@ -37,7 +41,8 @@
   public class PropertySet extends DataType {
   
       private boolean dynamic = true;
  -    private Vector cachedNames;
  +    private boolean negate = false;
  +    private Set cachedNames;
       private Vector ptyRefs = new Vector();
       private Vector setRefs = new Vector();
       private Mapper _mapper;
  @@ -145,6 +150,11 @@
           this.dynamic = dynamic;
       }
   
  +    public void setNegate(boolean negate) {
  +        assertNotReference();
  +        this.negate = negate;
  +    }
  +
       public boolean getDynamic() {
           return isReference() ? getRef().dynamic : dynamic;
       }
  @@ -154,17 +164,29 @@
       }
   
       public Properties getProperties() {
  -        Vector names = null;
  +        Set names = null;
           Project prj = getProject();
  +        Hashtable props =
  +            prj == null ? System.getProperties() : prj.getProperties();
   
           if (getDynamic() || cachedNames == null) {
  -            names = new Vector(); // :TODO: should be a Set!
  +            names = new HashSet();
               if (isReference()) {
  -                getRef().addPropertyNames(names, prj.getProperties());
  +                getRef().addPropertyNames(names, props);
               } else {
  -                addPropertyNames(names, prj.getProperties());
  +                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()) {
                   cachedNames = names;
               }
  @@ -178,9 +200,9 @@
               mapper = myMapper.getImplementation();
           }
           Properties properties = new Properties();
  -        for (Enumeration e = names.elements(); e.hasMoreElements();) {
  -            String name = (String) e.nextElement();
  -            String value = prj.getProperty(name);
  +        for (Iterator iter = names.iterator(); iter.hasNext();) {
  +            String name = (String) iter.next();
  +            String value = (String) props.get(name);
               if (mapper != null) {
                   String[] newname = mapper.mapFileName(name);
                   if (newname != null) {
  @@ -193,26 +215,26 @@
       }
   
       /**
  -     * @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.
        * @param  properties the current Project properties, passed in to
        *         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();
   
           // Add this PropertySet's property names.
           for (Enumeration e = ptyRefs.elements(); e.hasMoreElements();) {
               PropertyRef ref = (PropertyRef) e.nextElement();
               if (ref.name != null) {
  -                if (prj.getProperty(ref.name) != null) {
  -                    names.addElement(ref.name);
  +                if (prj != null && prj.getProperty(ref.name) != null) {
  +                    names.add(ref.name);
                   }
               } else if (ref.prefix != null) {
                   for (Enumeration p = properties.keys(); p.hasMoreElements();) {
                       String name = (String) p.nextElement();
                       if (name.startsWith(ref.prefix)) {
  -                        names.addElement(name);
  +                        names.add(name);
                       }
                   }
               } else if (ref.regex != null) {
  @@ -222,37 +244,25 @@
                   for (Enumeration p = properties.keys(); p.hasMoreElements();) {
                       String name = (String) p.nextElement();
                       if (matcher.matches(name)) {
  -                        names.addElement(name);
  +                        names.add(name);
                       }
                   }
               } else if (ref.builtin != null) {
   
  -                Enumeration e2 = null;
                   if (ref.builtin.equals(BuiltinPropertySetName.ALL)) {
  -                    e2 = properties.keys();
  +                    names.addAll(properties.keySet());
                   } else if (ref.builtin.equals(BuiltinPropertySetName.SYSTEM)) {
  -                    e2 = System.getProperties().keys();
  +                    names.addAll(System.getProperties().keySet());
                   } else if (ref.builtin.equals(BuiltinPropertySetName
                                                 .COMMANDLINE)) {
  -                    e2 = getProject().getUserProperties().keys();
  +                    names.addAll(getProject().getUserProperties().keySet());
                   } else {
                       throw new BuildException("Impossible: Invalid builtin "
                                                + "attribute!");
                   }
  -
  -                while (e2.hasMoreElements()) {
  -                    names.addElement(e2.nextElement());
  -                }
  -
               } else {
                   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);
           }
       }
   
  
  
  
  No                   revision
  No                   revision
  1.6.2.5   +18 -10    ant/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
  
  Index: EchoPropertiesTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java,v
  retrieving revision 1.6.2.4
  retrieving revision 1.6.2.5
  diff -u -r1.6.2.4 -r1.6.2.5
  --- EchoPropertiesTest.java	9 Mar 2004 17:02:05 -0000	1.6.2.4
  +++ EchoPropertiesTest.java	23 Apr 2004 15:41:38 -0000	1.6.2.5
  @@ -141,20 +141,28 @@
   
   
       public void testEchoPrefix() throws Exception {
  -        executeTarget( "testEchoPrefix" );
  -        Properties props=loadPropFile(PREFIX_OUTFILE);
  -//        props.list(System.out);
  -        assertEquals("prefix didn't include 'a.set' property","true",props.getProperty("a.set"));
  -        assertNull("prefix failed to filter out property 'b.set'",
  -                   props.getProperty("b.set"));
  +        testEchoPrefixVarious("testEchoPrefix");
       }
   
       public void testEchoPrefixAsPropertyset() throws Exception {
  -        executeTarget( "testEchoPrefixAsPropertyset" );
  -        Properties props=loadPropFile(PREFIX_OUTFILE);
  -        assertEquals("prefix didn't include 'a.set' property","true",props.getProperty("a.set"));
  +        testEchoPrefixVarious("testEchoPrefixAsPropertyset");
  +    }
  +
  +    public void testEchoPrefixAsNegatedPropertyset() throws Exception {
  +        testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset");
  +    }
  +
  +    public void testEchoPrefixAsDoublyNegatedPropertyset() throws Exception {
  +        testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset");
  +    }
  +
  +    private void testEchoPrefixVarious(String target) throws Exception {
  +        executeTarget(target);
  +        Properties props = loadPropFile(PREFIX_OUTFILE);
  +        assertEquals("prefix didn't include 'a.set' property",
  +            "true", props.getProperty("a.set"));
           assertNull("prefix failed to filter out property 'b.set'",
  -                   props.getProperty("b.set"));
  +            props.getProperty("b.set"));
       }
   
       protected Properties loadPropFile(String relativeFilename)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message