Skip to content

Commit

Permalink
Revert "Use org.apache.commons.lang.StringUtils.join() instead of han…
Browse files Browse the repository at this point in the history
…d-crafted solution. The package is already use elsewhere."

Back to hand-crafted solution since org.apache.commons.lang.StringUtils package is used only reporting module, but not in the
main CC sources. And I don't want to add a package just due to the single method (and in Java8, there is String.join() method
anyway).

This reverts commit 2add214.
  • Loading branch information
t-dan committed Oct 22, 2018
1 parent c948b5e commit 978b5af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main/checkstyleSuppressions.xml
Expand Up @@ -13,7 +13,7 @@

<!-- main/src/net/sourceforge/cruisecontrol/builders/PipedScript.java:10:8: Unused import - net.sourceforge.cruisecontrol.Builder
But the import is required by javadoc ... -->
<suppress checks="Unused" files="PipedScript.java" lines="11"/>
<suppress checks="Unused" files="PipedScript.java" lines="10"/>

<suppress checks="PackageDeclaration" files="CruiseControl.java"/>
<suppress checks="PackageDeclaration" files="CruiseControlWithJetty.java"/>
Expand Down
17 changes: 14 additions & 3 deletions main/src/net/sourceforge/cruisecontrol/builders/PipedScript.java
Expand Up @@ -5,7 +5,6 @@
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.jdom2.Element;

import net.sourceforge.cruisecontrol.Builder;
Expand Down Expand Up @@ -237,10 +236,22 @@ public static final class Helpers {
* @return the comma-separated items from the input collection
*/
public static String join(final Collection<String> s) {
return s != null ? StringUtils.join(s.iterator(), ",") : "";
return join(s != null ? s.toArray(new String[s.size()]) : null);
}
public static String join(final String[] s) {
return s != null ? StringUtils.join(s, ",") : "";
if (s == null) {
return "";
}

final StringBuffer b = new StringBuffer(s.length * 8);
for (String str : s) {
b.append(str);
b.append(',');
}
if (b.length() > 1) {
b.setLength(b.length() - 1); // Removes the last ','
}
return b.toString();
}
/** Splits the string to the array according to the ',' separator. It is, in particular, helpful
* for {@link PipedScript#setPipeFrom(String)} to {@link PipedScript#getPipeFrom()} and/or
Expand Down

0 comments on commit 978b5af

Please sign in to comment.