Skip to content
Permalink
Browse files
some refactoring triggered by PR 50611
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/dotnet/trunk@1061884 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bodewig committed Jan 21, 2011
1 parent 4817ceb commit 15ac873fb177768257f146f14bdcce1084730c73
Showing 5 changed files with 78 additions and 48 deletions.
@@ -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>
@@ -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 void execute() {

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 static class NamedElement {
private String name;
public String getName() {return name;}
public void setName(String s) {name = s;}
public String toString() {return getName();}
}
}
@@ -126,6 +126,9 @@ public String getName() {
return name;
}

public String toString() {
return getName();
}
}

/**
@@ -159,6 +162,10 @@ public void setValue(String value) {
public String getValue() {
return value;
}

public String toString() {
return getName() + "=" + getValue();
}
}

/**
@@ -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 @@ protected String[] getBuildfileArguments(File buildFile) {
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 @@ protected String[] getTargetArguments(List targets) {
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];
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.ant.dotnet.util;

import java.util.Collection;
import java.util.Iterator;

/**
* 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 .NET Antlib 1.1
*/
public class CollectionUtils {

/**
* Creates a comma separated list of all values held in the given
* collection.
*
* @since .NET Antlib 1.1
*/
public static String flattenToString(Collection c) {
return flattenToString(c, ",");
}

/**
* Creates a list of all values held in the given collection
* separated by the given separator.
*
* @since .NET Antlib 1.1
*/
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(sep);
}
sb.append(String.valueOf(iter.next()));
first = false;
}
return sb.toString();
}
}

0 comments on commit 15ac873

Please sign in to comment.