mbenson 2005/03/10 13:16:08 Modified: . WHATSNEW src/main/org/apache/tools/ant/taskdefs/optional EchoProperties.java src/main/org/apache/tools/ant/util CollectionUtils.java Log: Sort echoproperties output in text mode as well as XML. PR: 18976 Revision Changes Path 1.770 +1 -1 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.769 retrieving revision 1.770 diff -u -r1.769 -r1.770 --- WHATSNEW 10 Mar 2005 16:13:54 -0000 1.769 +++ WHATSNEW 10 Mar 2005 21:16:07 -0000 1.770 @@ -67,7 +67,7 @@ -------------- * <echoproperties> now (alphanumerically) sorts the property list - before echoing, when you request XML output (format="xml"). + before echoing. Bugzilla report 18976. * A new base class DispatchTask has been added to facilitate elegant creation of tasks with multiple actions. 1.30 +11 -7 ant/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java Index: EchoProperties.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- EchoProperties.java 9 Mar 2005 23:38:22 -0000 1.29 +++ EchoProperties.java 10 Mar 2005 21:16:08 -0000 1.30 @@ -325,15 +325,19 @@ [EMAIL PROTECTED] IOException trouble */ protected void saveProperties(Hashtable allProps, OutputStream os) - throws IOException, BuildException { - Properties props = new Properties(); - Enumeration e = allProps.keys(); - while (e.hasMoreElements()) { - String name = e.nextElement().toString(); + throws IOException, BuildException { + final List keyList = new ArrayList(allProps.keySet()); + Collections.sort(keyList); + Properties props = new Properties() { + public Enumeration keys() { + return CollectionUtils.asEnumeration(keyList.iterator()); + } + }; + for (int i = 0; i < keyList.size(); i++) { + String name = keyList.get(i).toString(); String value = allProps.get(name).toString(); - props.put(name, value); + props.setProperty(name, value); } - if ("text".equals(format)) { jdkSaveProperties(props, os, "Ant properties"); } else if ("xml".equals(format)) { 1.17 +37 -1 ant/src/main/org/apache/tools/ant/util/CollectionUtils.java Index: CollectionUtils.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/CollectionUtils.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- CollectionUtils.java 24 Jan 2005 18:13:20 -0000 1.16 +++ CollectionUtils.java 10 Mar 2005 21:16:08 -0000 1.17 @@ -16,10 +16,11 @@ */ package org.apache.tools.ant.util; +import java.util.Vector; +import java.util.Iterator; import java.util.Dictionary; import java.util.Enumeration; import java.util.NoSuchElementException; -import java.util.Vector; /** * A set of helper methods related to collection manipulation. @@ -139,6 +140,41 @@ return new CompoundEnumeration(e1, e2); } + /** + * Adapt the specified Iterator to the Enumeration interface. + * @param iter the Iterator to adapt. + * @return an Enumeration. + */ + public static Enumeration asEnumeration(final Iterator iter) { + return new Enumeration() { + public boolean hasMoreElements() { + return iter.hasNext(); + } + public Object nextElement() { + return iter.next(); + } + }; + } + + /** + * Adapt the specified Enumeration to the Iterator interface. + * @param enum the Enumeration to adapt. + * @return an Iterator. + */ + public static Iterator asIterator(final Enumeration enum) { + return new Iterator() { + public boolean hasNext() { + return enum.hasMoreElements(); + } + public Object next() { + return enum.nextElement(); + } + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + private static final class CompoundEnumeration implements Enumeration { private final Enumeration e1, e2;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]