You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2011/01/21 17:31:07 UTC
svn commit: r1061884 - in /ant/antlibs/dotnet/trunk: ./
src/main/org/apache/ant/dotnet/ src/main/org/apache/ant/dotnet/build/
src/main/org/apache/ant/dotnet/util/
Author: bodewig
Date: Fri Jan 21 16:31:05 2011
New Revision: 1061884
URL: http://svn.apache.org/viewvc?rev=1061884&view=rev
Log:
some refactoring triggered by PR 50611
Added:
ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/util/
ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/util/CollectionUtils.java
- copied, changed from r1061817, ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java
Modified:
ant/antlibs/dotnet/trunk/changes.xml
ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java
ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java
ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/MSBuildTask.java
Modified: ant/antlibs/dotnet/trunk/changes.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/changes.xml?rev=1061884&r1=1061883&r2=1061884&view=diff
==============================================================================
--- ant/antlibs/dotnet/trunk/changes.xml (original)
+++ ant/antlibs/dotnet/trunk/changes.xml Fri Jan 21 16:31:05 2011
@@ -52,7 +52,7 @@
The wix task has new nested elements that allow users to send
addtional command line arguments to candle and light.
</action>
- <action type="fix">
+ <action type="fix" issue="50611">
The include and exclude arguments to NUnit were broken (they
had a leading ",").
</action>
Modified: ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java?rev=1061884&r1=1061883&r2=1061884&view=diff
==============================================================================
--- ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java (original)
+++ ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/NUnitTask.java Fri Jan 21 16:31:05 2011
@@ -18,6 +18,7 @@
package org.apache.ant.dotnet;
+import org.apache.ant.dotnet.util.CollectionUtils;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Environment;
@@ -307,32 +308,12 @@ public class NUnitTask extends Task {
if (includes.size() > 0) {
StringBuffer sb = new StringBuffer("/include=");
- iter = includes.iterator();
- boolean first = true;
- while (iter.hasNext()) {
- if (first) {
- first = false;
- } else {
- sb.append(",");
- }
- NamedElement a = (NamedElement) iter.next();
- sb.append(a.getName());
- }
+ sb.append(CollectionUtils.flattenToString(includes));
exec.createArg().setValue(sb.toString());
}
if (excludes.size() > 0) {
StringBuffer sb = new StringBuffer("/exclude=");
- iter = excludes.iterator();
- boolean first = true;
- while (iter.hasNext()) {
- if (first) {
- first = false;
- } else {
- sb.append(",");
- }
- NamedElement a = (NamedElement) iter.next();
- sb.append(a.getName());
- }
+ sb.append(CollectionUtils.flattenToString(excludes));
exec.createArg().setValue(sb.toString());
}
@@ -349,5 +330,6 @@ public class NUnitTask extends Task {
private String name;
public String getName() {return name;}
public void setName(String s) {name = s;}
+ public String toString() {return getName();}
}
}
\ No newline at end of file
Modified: ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java?rev=1061884&r1=1061883&r2=1061884&view=diff
==============================================================================
--- ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java (original)
+++ ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java Fri Jan 21 16:31:05 2011
@@ -126,6 +126,9 @@ public abstract class AbstractBuildTask
return name;
}
+ public String toString() {
+ return getName();
+ }
}
/**
@@ -159,6 +162,10 @@ public abstract class AbstractBuildTask
public String getValue() {
return value;
}
+
+ public String toString() {
+ return getName() + "=" + getValue();
+ }
}
/**
Modified: ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/MSBuildTask.java
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/MSBuildTask.java?rev=1061884&r1=1061883&r2=1061884&view=diff
==============================================================================
--- ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/MSBuildTask.java (original)
+++ ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/build/MSBuildTask.java Fri Jan 21 16:31:05 2011
@@ -19,9 +19,10 @@
package org.apache.ant.dotnet.build;
import java.io.File;
-import java.util.Iterator;
import java.util.List;
+import org.apache.ant.dotnet.util.CollectionUtils;
+
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -58,18 +59,7 @@ public class MSBuildTask extends Abstrac
protected String[] getTargetArguments(List targets) {
if (targets.size() > 0) {
StringBuffer sb = new StringBuffer("/target:");
- Iterator iter = targets.iterator();
- boolean first = true;
- while (iter.hasNext()) {
- AbstractBuildTask.Target t =
- (AbstractBuildTask.Target) iter.next();
- if (!first) {
- sb.append(";");
- } else {
- first = false;
- }
- sb.append(t.getName());
- }
+ sb.append(CollectionUtils.flattenToString(targets, ";"));
return new String[]{sb.toString()};
} else {
return new String[0];
@@ -79,18 +69,7 @@ public class MSBuildTask extends Abstrac
protected String[] getPropertyArguments(List properties) {
if (properties.size() > 0) {
StringBuffer sb = new StringBuffer("/property:");
- Iterator iter = properties.iterator();
- boolean first = true;
- while (iter.hasNext()) {
- AbstractBuildTask.Property p =
- (AbstractBuildTask.Property) iter.next();
- if (!first) {
- sb.append(";");
- } else {
- first = false;
- }
- sb.append(p.getName()).append("=").append(p.getValue());
- }
+ sb.append(CollectionUtils.flattenToString(properties, ";"));
return new String[]{sb.toString()};
} else {
return new String[0];
Copied: ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/util/CollectionUtils.java (from r1061817, ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java)
URL: http://svn.apache.org/viewvc/ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/util/CollectionUtils.java?p2=ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/util/CollectionUtils.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java&r1=1061817&r2=1061884&rev=1061884&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java (original)
+++ ant/antlibs/dotnet/trunk/src/main/org/apache/ant/dotnet/util/CollectionUtils.java Fri Jan 21 16:31:05 2011
@@ -15,253 +15,48 @@
* limitations under the License.
*
*/
-package org.apache.tools.ant.util;
+package org.apache.ant.dotnet.util;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Vector;
-
-// CheckStyle:HideUtilityClassConstructorCheck OFF - bc
/**
- * A set of helper methods related to collection manipulation.
+ * Helper methods related to collection manipulation.
+ *
+ * <p>This is a stripped down copy of Ant 1.8.2's version so the .NET
+ * Antlib can still be used with Ant 1.7.0.</p>
*
- * @since Ant 1.5
+ * @since .NET Antlib 1.1
*/
public class CollectionUtils {
/**
- * Collections.emptyList() is Java5+.
- */
- public static final List EMPTY_LIST =
- Collections.unmodifiableList(new ArrayList(0));
-
- /**
- * Please use Vector.equals() or List.equals().
- * @param v1 the first vector.
- * @param v2 the second vector.
- * @return true if the vectors are equal.
- * @since Ant 1.5
- * @deprecated since 1.6.x.
- */
- public static boolean equals(Vector v1, Vector v2) {
- if (v1 == v2) {
- return true;
- }
-
- if (v1 == null || v2 == null) {
- return false;
- }
-
- return v1.equals(v2);
- }
-
- /**
- * Dictionary does not have an equals.
- * Please use Map.equals().
+ * Creates a comma separated list of all values held in the given
+ * collection.
*
- * <p>Follows the equals contract of Java 2's Map.</p>
- * @param d1 the first directory.
- * @param d2 the second directory.
- * @return true if the directories are equal.
- * @since Ant 1.5
- * @deprecated since 1.6.x.
+ * @since .NET Antlib 1.1
*/
- public static boolean equals(Dictionary d1, Dictionary d2) {
- if (d1 == d2) {
- return true;
- }
-
- if (d1 == null || d2 == null) {
- return false;
- }
-
- if (d1.size() != d2.size()) {
- return false;
- }
-
- Enumeration e1 = d1.keys();
- while (e1.hasMoreElements()) {
- Object key = e1.nextElement();
- Object value1 = d1.get(key);
- Object value2 = d2.get(key);
- if (value2 == null || !value1.equals(value2)) {
- return false;
- }
- }
-
- // don't need the opposite check as the Dictionaries have the
- // same size, so we've also covered all keys of d2 already.
-
- return true;
+ public static String flattenToString(Collection c) {
+ return flattenToString(c, ",");
}
/**
- * Creates a comma separated list of all values held in the given
- * collection.
+ * Creates a list of all values held in the given collection
+ * separated by the given separator.
*
- * @since Ant 1.8.0
+ * @since .NET Antlib 1.1
*/
- public static String flattenToString(Collection c) {
+ public static String flattenToString(Collection c, String sep) {
Iterator iter = c.iterator();
boolean first = true;
StringBuffer sb = new StringBuffer();
while (iter.hasNext()) {
if (!first) {
- sb.append(",");
+ sb.append(sep);
}
sb.append(String.valueOf(iter.next()));
first = false;
}
return sb.toString();
}
-
- /**
- * Dictionary does not know the putAll method. Please use Map.putAll().
- * @param m1 the to directory.
- * @param m2 the from directory.
- * @since Ant 1.6
- * @deprecated since 1.6.x.
- */
- public static void putAll(Dictionary m1, Dictionary m2) {
- for (Enumeration it = m2.keys(); it.hasMoreElements();) {
- Object key = it.nextElement();
- m1.put(key, m2.get(key));
- }
- }
-
- /**
- * An empty enumeration.
- * @since Ant 1.6
- */
- public static final class EmptyEnumeration implements Enumeration {
- /** Constructor for the EmptyEnumeration */
- public EmptyEnumeration() {
- }
-
- /**
- * @return false always.
- */
- public boolean hasMoreElements() {
- return false;
- }
-
- /**
- * @return nothing.
- * @throws NoSuchElementException always.
- */
- public Object nextElement() throws NoSuchElementException {
- throw new NoSuchElementException();
- }
- }
-
- /**
- * Append one enumeration to another.
- * Elements are evaluated lazily.
- * @param e1 the first enumeration.
- * @param e2 the subsequent enumeration.
- * @return an enumeration representing e1 followed by e2.
- * @since Ant 1.6.3
- */
- public static Enumeration append(Enumeration e1, Enumeration 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 e the Enumeration to adapt.
- * @return an Iterator.
- */
- public static Iterator asIterator(final Enumeration e) {
- return new Iterator() {
- public boolean hasNext() {
- return e.hasMoreElements();
- }
- public Object next() {
- return e.nextElement();
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
-
- /**
- * Returns a collection containing all elements of the iterator.
- *
- * @since Ant 1.8.0
- */
- public static Collection asCollection(final Iterator iter) {
- List l = new ArrayList();
- while (iter.hasNext()) {
- l.add(iter.next());
- }
- return l;
- }
-
- private static final class CompoundEnumeration implements Enumeration {
-
- private final Enumeration e1, e2;
-
- public CompoundEnumeration(Enumeration e1, Enumeration e2) {
- this.e1 = e1;
- this.e2 = e2;
- }
-
- public boolean hasMoreElements() {
- return e1.hasMoreElements() || e2.hasMoreElements();
- }
-
- public Object nextElement() throws NoSuchElementException {
- if (e1.hasMoreElements()) {
- return e1.nextElement();
- } else {
- return e2.nextElement();
- }
- }
-
- }
-
- /**
- * Counts how often the given Object occurs in the given
- * collection using equals() for comparison.
- *
- * @since Ant 1.8.0
- */
- public static int frequency(Collection c, Object o) {
- // same as Collections.frequency introduced with JDK 1.5
- int freq = 0;
- if (c != null) {
- for (Iterator i = c.iterator(); i.hasNext(); ) {
- Object test = i.next();
- if (o == null ? test == null : o.equals(test)) {
- freq++;
- }
- }
- }
- return freq;
- }
-
}