Browse Source

Sort echoproperties output in text mode as well as XML.

PR: 18976


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277886 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
2f35469477
3 changed files with 49 additions and 9 deletions
  1. +1
    -1
      WHATSNEW
  2. +11
    -7
      src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java
  3. +37
    -1
      src/main/org/apache/tools/ant/util/CollectionUtils.java

+ 1
- 1
WHATSNEW View File

@@ -67,7 +67,7 @@ Other changes:
--------------

* <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.


+ 11
- 7
src/main/org/apache/tools/ant/taskdefs/optional/EchoProperties.java View File

@@ -325,15 +325,19 @@ public class EchoProperties extends Task {
*@exception 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)) {


+ 37
- 1
src/main/org/apache/tools/ant/util/CollectionUtils.java View File

@@ -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 @@ public class CollectionUtils {
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;


Loading…
Cancel
Save