PR: 18976 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277886 13f79535-47bb-0310-9956-ffa450edef68master
@@ -67,7 +67,7 @@ Other changes: | |||||
-------------- | -------------- | ||||
* <echoproperties> now (alphanumerically) sorts the property list | * <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 | * A new base class DispatchTask has been added to facilitate elegant | ||||
creation of tasks with multiple actions. | creation of tasks with multiple actions. | ||||
@@ -325,15 +325,19 @@ public class EchoProperties extends Task { | |||||
*@exception IOException trouble | *@exception IOException trouble | ||||
*/ | */ | ||||
protected void saveProperties(Hashtable allProps, OutputStream os) | 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(); | String value = allProps.get(name).toString(); | ||||
props.put(name, value); | |||||
props.setProperty(name, value); | |||||
} | } | ||||
if ("text".equals(format)) { | if ("text".equals(format)) { | ||||
jdkSaveProperties(props, os, "Ant properties"); | jdkSaveProperties(props, os, "Ant properties"); | ||||
} else if ("xml".equals(format)) { | } else if ("xml".equals(format)) { | ||||
@@ -16,10 +16,11 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.util; | package org.apache.tools.ant.util; | ||||
import java.util.Vector; | |||||
import java.util.Iterator; | |||||
import java.util.Dictionary; | import java.util.Dictionary; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.NoSuchElementException; | import java.util.NoSuchElementException; | ||||
import java.util.Vector; | |||||
/** | /** | ||||
* A set of helper methods related to collection manipulation. | * A set of helper methods related to collection manipulation. | ||||
@@ -139,6 +140,41 @@ public class CollectionUtils { | |||||
return new CompoundEnumeration(e1, e2); | 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 static final class CompoundEnumeration implements Enumeration { | ||||
private final Enumeration e1, e2; | private final Enumeration e1, e2; | ||||