Skip to content

Commit

Permalink
Migrate from Apache Commons StringUtils#join to Java Platform `Stri…
Browse files Browse the repository at this point in the history
…ng#join` (jenkinsci#5992)
  • Loading branch information
basil authored Dec 1, 2021
1 parent 9fd69f7 commit 8ee11e2
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ public FilePath createTempDir(final String prefix, final String suffix) throws I
} else {
s = new String[]{prefix, suffix};
}
String name = StringUtils.join(s, ".");
String name = String.join(".", s);
return new FilePath(this, act(new CreateTempDir(name)));
} catch (IOException e) {
throw new IOException("Failed to create a temp directory on "+remote,e);
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import jenkins.util.SystemProperties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -159,7 +158,7 @@ public String getIdentityPublicKey() {
* @since 2.16
*/
public String getAgentProtocolNames() {
return StringUtils.join(Jenkins.get().getAgentProtocols(), ", ");
return String.join(", ", Jenkins.get().getAgentProtocols());
}

/**
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/logging/LogRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import javax.servlet.ServletException;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -169,7 +168,7 @@ public static Set<String> getAutoCompletionCandidates(List<String> loggerNamesLi

String longerPrefix = null;
for (int i = loggerNameParts.length; i > 0; i--) {
String loggerNamePrefix = StringUtils.join(Arrays.copyOf(loggerNameParts, i), ".");
String loggerNamePrefix = String.join(".", Arrays.copyOf(loggerNameParts, i));
seenPrefixes.put(loggerNamePrefix, seenPrefixes.getOrDefault(loggerNamePrefix, 0) + 1);
if (longerPrefix == null) {
relevantPrefixes.add(loggerNamePrefix); // actual logger name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public List<String> getChoices() {
}

public String getChoicesText() {
return StringUtils.join(choices, "\n");
return String.join("\n", choices);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/model/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static String getCanonicalName(ItemGroup context, String path) {
}
name.push(p[i]);
}
return StringUtils.join(name, '/');
return String.join("/", name);
}

/**
Expand Down Expand Up @@ -312,7 +312,7 @@ public static String computeRelativeNamesAfterRenaming(String oldFullName, Strin
newValue.add(relativeName);
}
}
return StringUtils.join(newValue, ",");
return String.join(",", newValue);
}

// Had difficulty adapting the version in Functions to use no live items, so rewrote it:
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ public Categories doItemCategories(StaplerRequest req, StaplerResponse rsp, @Que
metadata.put("iconClassName", iconClassName);
if (ctx != null) {
Icon icon = IconSet.icons
.getIconByClassSpec(StringUtils.join(new String[]{iconClassName, iconStyle}, " "));
.getIconByClassSpec(String.join(" ", iconClassName, iconStyle));
if (icon != null) {
metadata.put("iconQualifiedUrl", icon.getQualifiedUrl(ctx));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand All @@ -50,7 +49,7 @@ public CompositeCauseOfBlockage(List<CauseOfBlockage> delegates) {

@Override
public String getShortDescription() {
return StringUtils.join(uniqueReasons.keySet(), "; ");
return String.join("; ", uniqueReasons.keySet());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ public void filter(@NonNull EnvVars envVars, @NonNull EnvVarsFilterRuleContext c
}

if (!variablesRemoved.isEmpty()) {
context.getTaskListener().getLogger().println(Messages.RetainVariablesLocalRule_RemovalMessage(getDescriptor().getDisplayName(), StringUtils.join(variablesRemoved.toArray(), ", ")));
context.getTaskListener().getLogger().println(Messages.RetainVariablesLocalRule_RemovalMessage(getDescriptor().getDisplayName(), String.join(", ", variablesRemoved)));
}
if (!variablesReset.isEmpty()) {
// reset the variables using the initial value from System
variablesReset.forEach(variableName -> envVars.put(variableName, systemEnvVars.get(variableName)));
context.getTaskListener().getLogger().println(Messages.RetainVariablesLocalRule_ResetMessage(getDescriptor().getDisplayName(), StringUtils.join(variablesReset.toArray(), ", ")));
context.getTaskListener().getLogger().println(Messages.RetainVariablesLocalRule_ResetMessage(getDescriptor().getDisplayName(), String.join(", ", variablesReset)));
}
}

Expand Down
5 changes: 2 additions & 3 deletions test/src/test/java/jenkins/AgentProtocolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.List;
import java.util.Set;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -84,9 +83,9 @@ public static void assertProtocols(Jenkins jenkins, boolean shouldBeEnabled, @Ch
if (!failedChecks.isEmpty()) {
String message = String.format("Protocol(s) are not %s: %s. %sEnabled protocols: %s",
shouldBeEnabled ? "enabled" : "disabled",
StringUtils.join(failedChecks, ','),
String.join(",", failedChecks),
why != null ? "Reason: " + why + ". " : "",
StringUtils.join(agentProtocols, ','));
String.join(",", agentProtocols));
fail(message);
}
}
Expand Down

0 comments on commit 8ee11e2

Please sign in to comment.