From ff0cfb8ee70fa755f75e98b29eee392f3a45957f Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Tue, 18 Jan 2005 09:41:20 +0000 Subject: [PATCH] propertyset references did not handle nested propertyset references Reported by: Matthew Nelson git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277378 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 + src/etc/testcases/types/propertyset.xml | 55 +++++++++++++++++++ .../apache/tools/ant/types/PropertySet.java | 34 ++++++++++-- .../tools/ant/types/PropertySetTest.java | 39 +++++++++++++ 4 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 src/etc/testcases/types/propertyset.xml create mode 100644 src/testcases/org/apache/tools/ant/types/PropertySetTest.java diff --git a/WHATSNEW b/WHATSNEW index f875507ae..43a4e766a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -258,6 +258,8 @@ Fixed bugs: * forked 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 =================================== diff --git a/src/etc/testcases/types/propertyset.xml b/src/etc/testcases/types/propertyset.xml new file mode 100644 index 000000000..68ce6c23a --- /dev/null +++ b/src/etc/testcases/types/propertyset.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/types/PropertySet.java b/src/main/org/apache/tools/ant/types/PropertySet.java index 3cec27514..3199343b6 100644 --- a/src/main/org/apache/tools/ant/types/PropertySet.java +++ b/src/main/org/apache/tools/ant/types/PropertySet.java @@ -19,8 +19,10 @@ package org.apache.tools.ant.types; 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 @@ public class PropertySet extends DataType { * @return */ public Properties getProperties() { + if (isReference()) { + return getRef().getProperties(); + } Set names = null; Project prj = getProject(); Hashtable props = @@ -209,11 +214,7 @@ public class PropertySet extends DataType { 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 @@ public class PropertySet extends DataType { 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' natural order. + * @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(); + } +} diff --git a/src/testcases/org/apache/tools/ant/types/PropertySetTest.java b/src/testcases/org/apache/tools/ant/types/PropertySetTest.java new file mode 100644 index 000000000..b30dd3ca0 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/types/PropertySetTest.java @@ -0,0 +1,39 @@ +/* + * 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"); + } +}