Skip to content

Commit 25db00a

Browse files
committed
Remove unnecessary use of commons-lang
1 parent 88ac98a commit 25db00a

23 files changed

+56
-263
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ ext {
6363
dependencies {
6464
compileOnly project.deps.gocdPluginApi
6565
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
66-
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
6766
implementation group: 'io.fabric8', name: 'kubernetes-client', version: '5.12.4'
6867
implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.9.10'
6968
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.32'

src/main/java/cd/go/contrib/elasticagent/GoServerURLMetadata.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
package cd.go.contrib.elasticagent;
1818

1919
import cd.go.contrib.elasticagent.model.Metadata;
20-
import org.apache.commons.lang3.StringUtils;
2120

2221
import java.net.URI;
2322

23+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
24+
2425

2526
public class GoServerURLMetadata extends Metadata {
2627
public static String GO_SERVER_URL = "go_server_url";
@@ -31,7 +32,7 @@ public GoServerURLMetadata() {
3132

3233
@Override
3334
public String doValidate(String input) {
34-
if (StringUtils.isBlank(input)) {
35+
if (isBlank(input)) {
3536
return null;
3637
}
3738

@@ -40,7 +41,7 @@ public String doValidate(String input) {
4041
if (uri.getHost().equalsIgnoreCase("localhost") || uri.getHost().equalsIgnoreCase("127.0.0.1")) {
4142
return String.format("%s must not be localhost, since this gets resolved on the agents.", GO_SERVER_URL);
4243
}
43-
if (!StringUtils.endsWith(input, "/go")) {
44+
if (!input.endsWith("/go")) {
4445
return String.format("%s must be in format https://<GO_SERVER_URL>:<GO_SERVER_PORT>/go.", GO_SERVER_URL);
4546
}
4647
} catch (Exception e) {

src/main/java/cd/go/contrib/elasticagent/KubernetesAgentInstances.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.fabric8.kubernetes.api.model.Pod;
2222
import io.fabric8.kubernetes.api.model.PodList;
2323
import io.fabric8.kubernetes.client.KubernetesClient;
24-
import org.apache.commons.lang3.StringUtils;
2524

2625
import java.net.SocketTimeoutException;
2726
import java.time.Duration;
@@ -175,7 +174,7 @@ public void refreshAll(PluginSettings properties) {
175174
for (Pod pod : list.getItems()) {
176175
Map<String, String> podLabels = pod.getMetadata().getLabels();
177176
if (podLabels != null) {
178-
if (StringUtils.equals(Constants.KUBERNETES_POD_KIND_LABEL_VALUE, podLabels.get(Constants.KUBERNETES_POD_KIND_LABEL_KEY))) {
177+
if (Constants.KUBERNETES_POD_KIND_LABEL_VALUE.equals(podLabels.get(Constants.KUBERNETES_POD_KIND_LABEL_KEY))) {
179178
register(kubernetesInstanceFactory.fromKubernetesPod(pod));
180179
}
181180
}

src/main/java/cd/go/contrib/elasticagent/KubernetesClientFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import io.fabric8.kubernetes.client.ConfigBuilder;
2020
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
2121
import io.fabric8.kubernetes.client.KubernetesClient;
22-
import org.apache.commons.lang3.StringUtils;
2322

2423
import java.util.concurrent.TimeUnit;
2524

2625
import static cd.go.contrib.elasticagent.KubernetesPlugin.LOG;
26+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
2727
import static java.text.MessageFormat.format;
2828

2929
public class KubernetesClientFactory {
@@ -98,7 +98,7 @@ private long getKubernetesClientRecycleInterval() {
9898
}
9999

100100
String property = System.getProperty(CLIENT_RECYCLE_SYSTEM_PROPERTY_KEY);
101-
if (StringUtils.isBlank(property)) {
101+
if (isBlank(property)) {
102102
//set default to 10 minutes when system property is not specified
103103
this.kubernetesClientRecycleIntervalInMinutes = 10;
104104
return this.kubernetesClientRecycleIntervalInMinutes;

src/main/java/cd/go/contrib/elasticagent/KubernetesInstanceFactory.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.github.mustachejava.MustacheFactory;
2727
import io.fabric8.kubernetes.api.model.*;
2828
import io.fabric8.kubernetes.client.KubernetesClient;
29-
import org.apache.commons.lang3.StringUtils;
3029

3130
import java.io.IOException;
3231
import java.io.InputStream;
@@ -42,10 +41,10 @@
4241
import static cd.go.contrib.elasticagent.Constants.*;
4342
import static cd.go.contrib.elasticagent.KubernetesPlugin.LOG;
4443
import static cd.go.contrib.elasticagent.executors.GetProfileMetadataExecutor.*;
44+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
4545
import static java.lang.String.valueOf;
4646
import static java.nio.charset.StandardCharsets.UTF_8;
4747
import static java.text.MessageFormat.format;
48-
import static org.apache.commons.lang3.StringUtils.isBlank;
4948

5049
public class KubernetesInstanceFactory {
5150
public KubernetesInstance create(CreateAgentRequest request, PluginSettings settings, KubernetesClient client, PluginRequest pluginRequest) {
@@ -97,7 +96,7 @@ private KubernetesInstance createUsingProperties(CreateAgentRequest request, Plu
9796

9897
private Boolean privileged(CreateAgentRequest request) {
9998
final String privilegedMode = request.properties().get(PRIVILEGED.getKey());
100-
if (StringUtils.isBlank(privilegedMode)) {
99+
if (isBlank(privilegedMode)) {
101100
return false;
102101
}
103102
return Boolean.valueOf(privilegedMode);
@@ -116,15 +115,15 @@ private ResourceRequirements getPodResources(CreateAgentRequest request) {
116115
HashMap<String, Quantity> limits = new HashMap<>();
117116

118117
String maxMemory = request.properties().get("MaxMemory");
119-
if (StringUtils.isNotBlank(maxMemory)) {
118+
if (!isBlank(maxMemory)) {
120119
Size mem = Size.parse(maxMemory);
121120
LOG.debug(format("[Create Agent] Setting memory resource limit on k8s pod: {0}.", new Quantity(valueOf((long) mem.toMegabytes()), "M")));
122121
long memory = (long) mem.toBytes();
123122
limits.put("memory", new Quantity(valueOf(memory)));
124123
}
125124

126125
String maxCPU = request.properties().get("MaxCPU");
127-
if (StringUtils.isNotBlank(maxCPU)) {
126+
if (!isBlank(maxCPU)) {
128127
LOG.debug(format("[Create Agent] Setting cpu resource limit on k8s pod: {0}.", new Quantity(maxCPU)));
129128
limits.put("cpu", new Quantity(maxCPU));
130129
}
@@ -158,7 +157,7 @@ KubernetesInstance fromKubernetesPod(Pod elasticAgentPod) {
158157
try {
159158
ObjectMeta metadata = elasticAgentPod.getMetadata();
160159
Instant createdAt = Instant.now();
161-
if (StringUtils.isNotBlank(metadata.getCreationTimestamp())) {
160+
if (!isBlank(metadata.getCreationTimestamp())) {
162161
createdAt = Constants.KUBERNETES_POD_CREATION_TIME_FORMAT.parse(metadata.getCreationTimestamp(), Instant::from);
163162
}
164163
String environment = metadata.getLabels().get(ENVIRONMENT_LABEL_KEY);
@@ -172,10 +171,10 @@ KubernetesInstance fromKubernetesPod(Pod elasticAgentPod) {
172171

173172
private static List<EnvVar> environmentFrom(CreateAgentRequest request, PluginSettings settings, String podName, PluginRequest pluginRequest) {
174173
ArrayList<EnvVar> env = new ArrayList<>();
175-
String goServerUrl = StringUtils.isBlank(settings.getGoServerUrl()) ? pluginRequest.getSeverInfo().getSecureSiteUrl() : settings.getGoServerUrl();
174+
String goServerUrl = isBlank(settings.getGoServerUrl()) ? pluginRequest.getSeverInfo().getSecureSiteUrl() : settings.getGoServerUrl();
176175
env.add(new EnvVar("GO_EA_SERVER_URL", goServerUrl, null));
177176
String environment = request.properties().get("Environment");
178-
if (StringUtils.isNotBlank(environment)) {
177+
if (!isBlank(environment)) {
179178
env.addAll(parseEnvironments(environment));
180179
}
181180
env.addAll(request.autoregisterPropertiesAsEnvironmentVars(podName));
@@ -207,7 +206,7 @@ private static HashMap<String, String> labelsFrom(CreateAgentRequest request) {
207206
labels.put(CREATED_BY_LABEL_KEY, PLUGIN_ID);
208207
labels.put(JOB_ID_LABEL_KEY, valueOf(request.jobIdentifier().getJobId()));
209208

210-
if (StringUtils.isNotBlank(request.environment())) {
209+
if (!isBlank(request.environment())) {
211210
labels.put(ENVIRONMENT_LABEL_KEY, request.environment());
212211
}
213212

src/main/java/cd/go/contrib/elasticagent/PluginSettings.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import com.google.gson.GsonBuilder;
2121
import com.google.gson.annotations.Expose;
2222
import com.google.gson.annotations.SerializedName;
23-
import org.apache.commons.lang3.StringUtils;
23+
2424
import java.time.Duration;
2525
import java.time.temporal.ChronoUnit;
2626

2727
import static cd.go.contrib.elasticagent.utils.Util.IntTypeAdapter;
28+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
2829

2930
public class PluginSettings {
3031
@Expose
@@ -81,12 +82,12 @@ public Duration getAutoRegisterPeriod() {
8182
}
8283

8384
Integer getAutoRegisterTimeout() {
84-
Integer autoRegisterTimeoutInt = StringUtils.isNotBlank(autoRegisterTimeout) ? Integer.valueOf(autoRegisterTimeout) : null;
85+
Integer autoRegisterTimeoutInt = !isBlank(autoRegisterTimeout) ? Integer.valueOf(autoRegisterTimeout) : null;
8586
return getOrDefault(autoRegisterTimeoutInt, 10);
8687
}
8788

8889
public Integer getMaxPendingPods() {
89-
Integer maximumPendingPodsInt = StringUtils.isNotBlank(this.maxPendingPods) ? Integer.valueOf(this.maxPendingPods) : null;
90+
Integer maximumPendingPodsInt = !isBlank(this.maxPendingPods) ? Integer.valueOf(this.maxPendingPods) : null;
9091
return getOrDefault(maximumPendingPodsInt, 10);
9192
}
9293

@@ -111,7 +112,7 @@ public String getNamespace() {
111112
}
112113

113114
private <T> T getOrDefault(T t, T defaultValue) {
114-
if (t instanceof String && StringUtils.isBlank(String.valueOf(t))) {
115+
if (t instanceof String && isBlank(String.valueOf(t))) {
115116
return defaultValue;
116117
}
117118

src/main/java/cd/go/contrib/elasticagent/executors/AgentStatusReportExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
3030
import io.fabric8.kubernetes.api.model.Pod;
3131
import io.fabric8.kubernetes.client.KubernetesClient;
32-
import org.apache.commons.lang3.StringUtils;
3332

3433
import java.util.List;
3534

3635
import static cd.go.contrib.elasticagent.KubernetesPlugin.LOG;
36+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
3737
import static java.text.MessageFormat.format;
3838

3939
public class AgentStatusReportExecutor {
@@ -59,7 +59,7 @@ public GoPluginApiResponse execute() {
5959

6060
try {
6161
Pod pod;
62-
if (StringUtils.isNotBlank(elasticAgentId)) {
62+
if (!isBlank(elasticAgentId)) {
6363
pod = findPodUsingElasticAgentId(elasticAgentId, client);
6464
} else {
6565
pod = findPodUsingJobIdentifier(jobIdentifier, client);

src/main/java/cd/go/contrib/elasticagent/executors/ClusterProfileValidateRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import static cd.go.contrib.elasticagent.GoServerURLMetadata.GO_SERVER_URL;
3030
import static cd.go.contrib.elasticagent.executors.GetClusterProfileMetadataExecutor.FIELDS;
3131
import static cd.go.contrib.elasticagent.utils.Util.GSON;
32-
import static org.apache.commons.lang3.StringUtils.isBlank;
32+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
3333

3434
public class ClusterProfileValidateRequestExecutor implements RequestExecutor {
3535
private ClusterProfileValidateRequest request;

src/main/java/cd/go/contrib/elasticagent/executors/MigrateConfigurationRequestExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import cd.go.contrib.elasticagent.requests.MigrateConfigurationRequest;
2121
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse;
2222
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
23-
import org.apache.commons.lang3.StringUtils;
2423

2524
import java.util.Arrays;
2625
import java.util.List;
@@ -29,6 +28,7 @@
2928
import java.util.stream.Collectors;
3029

3130
import static cd.go.contrib.elasticagent.KubernetesPlugin.LOG;
31+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
3232

3333
public class MigrateConfigurationRequestExecutor implements RequestExecutor {
3434
private MigrateConfigurationRequest migrateConfigurationRequest;
@@ -110,6 +110,6 @@ private GoPluginApiResponse getGoPluginApiResponse(PluginSettings pluginSettings
110110
}
111111

112112
private boolean arePluginSettingsConfigured(PluginSettings pluginSettings) {
113-
return !StringUtils.isBlank(pluginSettings.getGoServerUrl());
113+
return !isBlank(pluginSettings.getGoServerUrl());
114114
}
115115
}

src/main/java/cd/go/contrib/elasticagent/executors/ProfileValidateRequestExecutor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse;
2626
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
2727
import io.fabric8.kubernetes.api.model.Pod;
28-
import org.apache.commons.lang3.StringUtils;
2928

3029
import java.io.IOException;
3130
import java.util.*;
3231

3332
import static cd.go.contrib.elasticagent.KubernetesPlugin.LOG;
3433
import static cd.go.contrib.elasticagent.executors.GetProfileMetadataExecutor.*;
3534
import static cd.go.contrib.elasticagent.utils.Util.GSON;
35+
import static cd.go.contrib.elasticagent.utils.Util.isBlank;
3636
import static java.text.MessageFormat.format;
3737

3838
public class ProfileValidateRequestExecutor implements RequestExecutor {
@@ -104,25 +104,25 @@ public GoPluginApiResponse execute() {
104104
}
105105

106106
private void validateRemoteFileSpec(HashMap<String, String> properties, ArrayList<Map<String, String>> result) {
107-
if (StringUtils.isBlank(properties.get(REMOTE_FILE.getKey()))) {
107+
if (isBlank(properties.get(REMOTE_FILE.getKey()))) {
108108
addNotBlankError(result, REMOTE_FILE.getKey(), "RemoteFile");
109109
}
110-
if (StringUtils.isBlank(properties.get(REMOTE_FILE_TYPE.getKey()))) {
110+
if (isBlank(properties.get(REMOTE_FILE_TYPE.getKey()))) {
111111
addNotBlankError(result, REMOTE_FILE_TYPE.getKey(), "RemoteFileType");
112112
}
113113
}
114114

115115
private void validateConfigPropertiesYaml(HashMap<String, String> properties, ArrayList<Map<String, String>> result) {
116116
String key = IMAGE.getKey();
117-
if (StringUtils.isBlank(properties.get(key))) {
117+
if (isBlank(properties.get(key))) {
118118
addNotBlankError(result, key, "Image");
119119
}
120120
}
121121

122122
private void validatePodYaml(HashMap<String, String> properties, ArrayList<Map<String, String>> result) {
123123
String key = POD_CONFIGURATION.getKey();
124124
String podYaml = properties.get(key);
125-
if (StringUtils.isBlank(podYaml)) {
125+
if (isBlank(podYaml)) {
126126
addNotBlankError(result, key, "Pod Configuration");
127127
return;
128128
}
@@ -135,7 +135,7 @@ private void validatePodYaml(HashMap<String, String> properties, ArrayList<Map<S
135135
return;
136136
}
137137

138-
if (StringUtils.isNotBlank(pod.getMetadata().getGenerateName())) {
138+
if (!isBlank(pod.getMetadata().getGenerateName())) {
139139
addError(result, key, "Invalid Pod Yaml. generateName field is not supported by GoCD. Please use {{ POD_POSTFIX }} instead.");
140140
}
141141
}

0 commit comments

Comments
 (0)