Skip to content

Commit

Permalink
Further reduce usages of StringUtils (#9002)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Mar 2, 2024
1 parent dd8f903 commit b8e916a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jvnet.tiger_types.Types;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -425,7 +424,7 @@ public CheckMethod getCheckMethod(String fieldName) {
* sets that as the 'fillUrl' attribute.
*/
public void calcFillSettings(String field, Map<String, Object> attributes) {
String capitalizedFieldName = StringUtils.capitalize(field);
String capitalizedFieldName = field == null || field.isEmpty() ? field : Character.toTitleCase(field.charAt(0)) + field.substring(1);

Check warning on line 427 in core/src/main/java/hudson/model/Descriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 427 is only partially covered, 2 branches are missing
String methodName = "doFill" + capitalizedFieldName + "Items";
Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName);
if (method == null)
Expand Down Expand Up @@ -467,7 +466,7 @@ private List<String> buildFillDependencies(Method method, List<String> depends)
* Computes the auto-completion setting
*/
public void calcAutoCompleteSettings(String field, Map<String, Object> attributes) {
String capitalizedFieldName = StringUtils.capitalize(field);
String capitalizedFieldName = field == null || field.isEmpty() ? field : Character.toTitleCase(field.charAt(0)) + field.substring(1);

Check warning on line 469 in core/src/main/java/hudson/model/Descriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 469 is only partially covered, one branch is missing
String methodName = "doAutoComplete" + capitalizedFieldName;
Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName);
if (method == null)
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/util/FormValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
Expand Down Expand Up @@ -638,7 +637,7 @@ public static class CheckMethod {

public CheckMethod(Descriptor descriptor, String fieldName) {
this.descriptor = descriptor;
this.capitalizedFieldName = StringUtils.capitalize(fieldName);
this.capitalizedFieldName = fieldName == null || fieldName.isEmpty() ? fieldName : Character.toTitleCase(fieldName.charAt(0)) + fieldName.substring(1);

Check warning on line 640 in core/src/main/java/hudson/util/FormValidation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 640 is only partially covered, 2 branches are missing

method = ReflectionUtils.getPublicMethodNamed(descriptor.getClass(), "doCheck" + capitalizedFieldName);
if (method != null) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/hudson/PluginWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import jenkins.model.Jenkins;
import jenkins.util.URLClassLoader2;
import org.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -151,7 +151,7 @@ private final class PluginWrapperBuilder {
private ClassLoader cl = null;

private PluginWrapperBuilder(String name) {
this.name = name;
this.name = Objects.requireNonNull(name);
}

public PluginWrapperBuilder version(String version) {
Expand Down Expand Up @@ -192,7 +192,7 @@ private PluginWrapper build() {
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue("Short-Name", name);
attributes.putValue("Long-Name", StringUtils.capitalize(name));
attributes.putValue("Long-Name", Character.toTitleCase(name.charAt(0)) + name.substring(1));
attributes.putValue("Jenkins-Version", requiredCoreVersion);
attributes.putValue("Plugin-Version", version);
return new PluginWrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import hudson.PluginWrapper;
import java.io.IOException;
import java.util.function.BiPredicate;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import jenkins.security.SecurityListener;
import jenkins.security.apitoken.ApiTokenPropertyConfiguration;
import jenkins.security.seed.UserSeedProperty;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Matcher;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import hudson.model.User;
import java.io.IOException;
import jenkins.security.ApiTokenProperty;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Matchers;
import org.htmlunit.Page;
import org.htmlunit.html.DomNodeList;
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/org/kohsuke/stapler/BindTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import hudson.model.RootAction;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.htmlunit.Page;
import org.htmlunit.ScriptException;
import org.htmlunit.html.HtmlPage;
Expand Down

0 comments on commit b8e916a

Please sign in to comment.