peterreilly    2005/01/18 01:41:20

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/types PropertySet.java
  Added:       src/etc/testcases/types propertyset.xml
               src/testcases/org/apache/tools/ant/types
                        PropertySetTest.java
  Log:
  propertyset references did not handle nested propertyset references
  Reported by: Matthew Nelson
  
  Revision  Changes    Path
  1.715     +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.714
  retrieving revision 1.715
  diff -u -r1.714 -r1.715
  --- WHATSNEW  14 Jan 2005 10:09:23 -0000      1.714
  +++ WHATSNEW  18 Jan 2005 09:41:20 -0000      1.715
  @@ -258,6 +258,8 @@
   * forked <javac> won't pass -source to a JDK 1.1 or 1.2 javac anymore.
     Bugzilla report 32948
   
  +* propertyset references did not handle nested propertyset references.
  +
   Changes from Ant 1.6.1 to Ant 1.6.2
   ===================================
   
  
  
  
  1.1                  ant/src/etc/testcases/types/propertyset.xml
  
  Index: propertyset.xml
  ===================================================================
  <!--
   * Copyright 2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
  -->
  
  <project>
    <property name="fooA" value="FooA"/>
    <property name="barB" value="BarB"/>
  
    <propertyset id="properties-starting-with-foo">
      <propertyref prefix="foo"/>
    </propertyset>
    <propertyset id="properties-starting-with-bar">
      <propertyref prefix="bar"/>
    </propertyset>
    <propertyset id="my-set">
      <propertyset refid="properties-starting-with-foo"/>
      <propertyset refid="properties-starting-with-bar"/>
    </propertyset>
    
    <macrodef name="expect.equals">
      <attribute name="test"/>
      <attribute name="exp"/>
      <attribute name="got"/>
      <sequential>
        <fail message=
            "@{test} failed: expected &quot;@{exp}&quot; got 
&quot;@{got}&quot;">
          <condition>
            <not>
              <equals arg1="@{exp}" arg2="@{got}"/>
            </not>
          </condition>
        </fail>
      </sequential>
    </macrodef>
  
    <target name="reference-to-two-references">
      <expect.equals
        test="reference to two references"
        exp="barB=BarB, fooA=FooA"
        got="${toString:my-set}"/>
    </target>
  </project>
  
  
  
  1.21      +28 -6     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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- PropertySet.java  10 Jan 2005 08:37:06 -0000      1.20
  +++ PropertySet.java  18 Jan 2005 09:41:20 -0000      1.21
  @@ -19,8 +19,10 @@
   
   import java.util.Enumeration;
   import java.util.Iterator;
  +import java.util.Map;
   import java.util.HashSet;
   import java.util.Set;
  +import java.util.TreeMap;
   import java.util.Hashtable;
   import java.util.Properties;
   import java.util.Stack;
  @@ -202,6 +204,9 @@
        * @return
        */
       public Properties getProperties() {
  +        if (isReference()) {
  +            return getRef().getProperties();
  +        }
           Set names = null;
           Project prj = getProject();
           Hashtable props =
  @@ -209,11 +214,7 @@
   
           if (getDynamic() || cachedNames == null) {
               names = new HashSet();
  -            if (isReference()) {
  -                getRef().addPropertyNames(names, props);
  -            } 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();
  @@ -375,5 +376,26 @@
               return new String[] {ALL, SYSTEM, COMMANDLINE};
           }
       }
  -} // END class PropertySet
   
  +    /**
  +     * A debug toString.
  +     * This gets a comma separated list of key=value pairs for
  +     * the properties in the set.
  +     * The output order is sorted according to the keys' <i>natural 
order</i>.
  +     * @return a string rep of this object
  +     */
  +    public String toString() {
  +        StringBuffer b = new StringBuffer();
  +        TreeMap sorted = new TreeMap(getProperties());
  +        for (Iterator i = sorted.entrySet().iterator(); i.hasNext();) {
  +            Map.Entry e = (Map.Entry) i.next();
  +            if (b.length() != 0) {
  +                b.append(", ");
  +            }
  +            b.append(e.getKey().toString());
  +            b.append("=");
  +            b.append(e.getValue().toString());
  +        }
  +        return b.toString();
  +    }
  +}
  
  
  
  1.1                  
ant/src/testcases/org/apache/tools/ant/types/PropertySetTest.java
  
  Index: PropertySetTest.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant.types;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.BuildFileTest;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.taskdefs.condition.Condition;
  
  public class PropertySetTest extends BuildFileTest {
  
      public PropertySetTest(String name) {
          super(name);
      }
  
      public void setUp() {
          configureProject("src/etc/testcases/types/propertyset.xml");
      }
  
      public void testReferenceToTwoReferences() {
          executeTarget("reference-to-two-references");
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to