diff --git a/pom.xml b/pom.xml
index 65ea4a078..f3f267900 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,7 @@ THE SOFTWARE.
1885
false
false
+ false
diff --git a/src/main/java/hudson/plugins/ec2/CloudHelper.java b/src/main/java/hudson/plugins/ec2/CloudHelper.java
index 335ce37b5..fc532de87 100644
--- a/src/main/java/hudson/plugins/ec2/CloudHelper.java
+++ b/src/main/java/hudson/plugins/ec2/CloudHelper.java
@@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
-import org.apache.commons.lang.StringUtils;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.ec2.Ec2Client;
@@ -46,7 +45,7 @@ static Instance getInstanceWithRetry(String instanceId, EC2Cloud cloud) throws S
@CheckForNull
static Instance getInstance(String instanceId, EC2Cloud cloud) throws SdkException {
- if (StringUtils.isEmpty(instanceId) || cloud == null) {
+ if (instanceId == null || instanceId.isEmpty() || cloud == null) {
return null;
}
diff --git a/src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java b/src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
index 8c1dd850f..bc9ec1b6e 100644
--- a/src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
+++ b/src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
@@ -50,7 +50,6 @@
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
-import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.verb.POST;
@@ -1124,7 +1123,7 @@ public boolean isAllowSelfSignedCertificate() {
public static ListBoxModel fillZoneItems(AwsCredentialsProvider credentialsProvider, String region) {
ListBoxModel model = new ListBoxModel();
- if (!StringUtils.isEmpty(region)) {
+ if (region != null && !region.isEmpty()) {
Ec2Client client =
AmazonEC2Factory.getInstance().connect(credentialsProvider, EC2Cloud.parseRegion(region), null);
DescribeAvailabilityZonesResponse zones = client.describeAvailabilityZones();
diff --git a/src/main/java/hudson/plugins/ec2/EC2Cloud.java b/src/main/java/hudson/plugins/ec2/EC2Cloud.java
index f5018d477..fe395dbd6 100644
--- a/src/main/java/hudson/plugins/ec2/EC2Cloud.java
+++ b/src/main/java/hudson/plugins/ec2/EC2Cloud.java
@@ -94,7 +94,6 @@
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.util.Timer;
-import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -924,8 +923,8 @@ private int countJenkinsNodeSpotInstancesWithoutRequests(
if (template != null) {
List instanceTags = sir.tags();
for (Tag tag : instanceTags) {
- if (StringUtils.equals(tag.key(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)
- && StringUtils.equals(
+ if (Objects.equals(tag.key(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)
+ && Objects.equals(
tag.value(), getSlaveTypeTagValue(EC2_SLAVE_TYPE_SPOT, template.description))
&& sir.launchSpecification().imageId().equals(template.getAmi())) {
@@ -988,16 +987,16 @@ private List getGenericFilters(String jenkinsServerUrl, SlaveTemplate te
private boolean isEc2ProvisionedAmiSlave(List tags, String description) {
for (Tag tag : tags) {
- if (StringUtils.equals(tag.key(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)) {
+ if (Objects.equals(tag.key(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)) {
if (description == null) {
return true;
- } else if (StringUtils.equals(tag.value(), EC2Cloud.EC2_SLAVE_TYPE_DEMAND)
- || StringUtils.equals(tag.value(), EC2Cloud.EC2_SLAVE_TYPE_SPOT)) {
+ } else if (Objects.equals(tag.value(), EC2Cloud.EC2_SLAVE_TYPE_DEMAND)
+ || Objects.equals(tag.value(), EC2Cloud.EC2_SLAVE_TYPE_SPOT)) {
// To handle cases where description is null and also upgrade cases for existing agent nodes.
return true;
- } else if (StringUtils.equals(
+ } else if (Objects.equals(
tag.value(), getSlaveTypeTagValue(EC2Cloud.EC2_SLAVE_TYPE_DEMAND, description))
- || StringUtils.equals(
+ || Objects.equals(
tag.value(), getSlaveTypeTagValue(EC2Cloud.EC2_SLAVE_TYPE_SPOT, description))) {
return true;
} else {
@@ -1229,7 +1228,7 @@ private CompletableFuture waitForRunningAndConnectAsync(final SlaveTemplat
t);
return null;
}
- if (StringUtils.isEmpty(instanceId)) {
+ if (instanceId == null || instanceId.isEmpty()) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
@@ -1394,7 +1393,7 @@ public static AwsCredentialsProvider createCredentialsProvider(
final boolean useInstanceProfileForCredentials, final String credentialsId) {
if (useInstanceProfileForCredentials) {
return InstanceProfileCredentialsProvider.create();
- } else if (StringUtils.isBlank(credentialsId)) {
+ } else if (credentialsId == null || credentialsId.isBlank()) {
return DefaultCredentialsProvider.builder().build();
} else {
AmazonWebServicesCredentials credentials = getCredentials(credentialsId);
@@ -1414,10 +1413,11 @@ public static AwsCredentialsProvider createCredentialsProvider(
AwsCredentialsProvider provider = createCredentialsProvider(useInstanceProfileForCredentials, credentialsId);
- if (StringUtils.isNotEmpty(roleArn)) {
+ if (roleArn != null && !roleArn.isEmpty()) {
AssumeRoleRequest assumeRoleRequest = AssumeRoleRequest.builder()
.roleArn(roleArn)
- .roleSessionName(StringUtils.defaultIfBlank(roleSessionName, "Jenkins"))
+ .roleSessionName(
+ roleSessionName != null && !roleSessionName.isBlank() ? roleSessionName : "Jenkins")
.build();
StsClientBuilder stsClientBuilder = StsClient.builder()
@@ -1441,7 +1441,7 @@ public static AwsCredentialsProvider createCredentialsProvider(
@CheckForNull
private static AmazonWebServicesCredentials getCredentials(@CheckForNull String credentialsId) {
- if (StringUtils.isBlank(credentialsId)) {
+ if (credentialsId == null || credentialsId.isBlank()) {
return null;
}
return CredentialsMatchers.firstOrNull(
@@ -1592,7 +1592,7 @@ public FormValidation doCheckRoleSessionName(
@QueryParameter String roleArn, @QueryParameter String roleSessionName) {
// Don't do anything if the user is only reading the configuration
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
- if (StringUtils.isNotEmpty(roleArn) && StringUtils.isBlank(roleSessionName)) {
+ if (roleArn != null && !roleArn.isEmpty() && (roleSessionName == null || roleSessionName.isBlank())) {
return FormValidation.warning(
"Session Name is recommended when specifying an Arn Role. If empty, 'Jenkins' will be used.");
}
@@ -1628,7 +1628,7 @@ public FormValidation doCheckSshKeysCredentialsId(
if (k == null) {
validations.add(FormValidation.error(
"Failed to find private key file " + System.getProperty(SSH_PRIVATE_KEY_FILEPATH)));
- if (!StringUtils.isEmpty(value)) {
+ if (value != null && !value.isEmpty()) {
validations.add(FormValidation.warning(
"Private key file path defined, selected credential will be ignored"));
}
@@ -1658,7 +1658,7 @@ public FormValidation doCheckSshKeysCredentialsId(
}
if (!System.getProperty(SSH_PRIVATE_KEY_FILEPATH, "").isEmpty()) {
- if (!StringUtils.isEmpty(value)) {
+ if (value != null && !value.isEmpty()) {
validations.add(FormValidation.warning("Using private key file instead of selected credential"));
} else {
validations.add(FormValidation.ok("Using private key file"));
@@ -1722,7 +1722,7 @@ public FormValidation doTestConnection(
if (k == null) {
validations.add(FormValidation.error(
"Failed to find private key file " + System.getProperty(SSH_PRIVATE_KEY_FILEPATH)));
- if (!StringUtils.isEmpty(sshKeysCredentialsId)) {
+ if (sshKeysCredentialsId != null && !sshKeysCredentialsId.isEmpty()) {
validations.add(FormValidation.warning(
"Private key file path defined, selected credential will be ignored"));
}
@@ -1753,7 +1753,7 @@ public FormValidation doTestConnection(
}
if (!System.getProperty(SSH_PRIVATE_KEY_FILEPATH, "").isEmpty()) {
- if (!StringUtils.isEmpty(sshKeysCredentialsId)) {
+ if (sshKeysCredentialsId != null && !sshKeysCredentialsId.isEmpty()) {
validations.add(
FormValidation.warning("Using private key file instead of selected credential"));
} else {
diff --git a/src/main/java/hudson/plugins/ec2/EC2HostAddressProvider.java b/src/main/java/hudson/plugins/ec2/EC2HostAddressProvider.java
index 7c0c4786d..dc06e10eb 100644
--- a/src/main/java/hudson/plugins/ec2/EC2HostAddressProvider.java
+++ b/src/main/java/hudson/plugins/ec2/EC2HostAddressProvider.java
@@ -1,7 +1,6 @@
package hudson.plugins.ec2;
import java.util.Optional;
-import org.apache.commons.lang.StringUtils;
import software.amazon.awssdk.services.ec2.model.Instance;
public class EC2HostAddressProvider {
@@ -62,6 +61,6 @@ private static String getPrivateIpAddress(Instance instance) {
}
private static Optional filterNonEmpty(String value) {
- return Optional.ofNullable(value).filter(StringUtils::isNotEmpty);
+ return Optional.ofNullable(value).filter(s -> !s.isEmpty());
}
}
diff --git a/src/main/java/hudson/plugins/ec2/EC2PrivateKey.java b/src/main/java/hudson/plugins/ec2/EC2PrivateKey.java
index 5d52b7ee4..bb38f1909 100644
--- a/src/main/java/hudson/plugins/ec2/EC2PrivateKey.java
+++ b/src/main/java/hudson/plugins/ec2/EC2PrivateKey.java
@@ -38,7 +38,6 @@
import java.util.logging.Logger;
import javax.crypto.Cipher;
import jenkins.bouncycastle.api.PEMEncodable;
-import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import software.amazon.awssdk.core.exception.SdkException;
@@ -145,7 +144,7 @@ public String decryptWindowsPassword(String encodedPassword) throws SdkException
cipher.init(
Cipher.DECRYPT_MODE,
PEMEncodable.decode(privateKey.getPlainText()).toPrivateKey());
- byte[] cipherText = Base64.getDecoder().decode(StringUtils.deleteWhitespace(encodedPassword));
+ byte[] cipherText = Base64.getDecoder().decode(encodedPassword.replaceAll("\\s+", ""));
byte[] plainText = cipher.doFinal(cipherText);
return new String(plainText, StandardCharsets.US_ASCII);
} catch (Exception e) {
@@ -161,7 +160,7 @@ public static EC2PrivateKey fetchFromDisk() {
@CheckForNull
public static EC2PrivateKey fetchFromDisk(String filepath) {
- if (StringUtils.isNotEmpty(filepath)) {
+ if (filepath != null && !filepath.isEmpty()) {
try {
return new EC2PrivateKey(Files.readString(Paths.get(filepath), StandardCharsets.UTF_8));
} catch (IOException e) {
diff --git a/src/main/java/hudson/plugins/ec2/EC2SlaveMonitor.java b/src/main/java/hudson/plugins/ec2/EC2SlaveMonitor.java
index 3c8ba83a3..933193beb 100644
--- a/src/main/java/hudson/plugins/ec2/EC2SlaveMonitor.java
+++ b/src/main/java/hudson/plugins/ec2/EC2SlaveMonitor.java
@@ -14,7 +14,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.ec2.model.Ec2Exception;
import software.amazon.awssdk.services.ec2.model.Instance;
@@ -51,7 +50,7 @@ private void removeDeadNodes() {
for (Node node : Jenkins.get().getNodes()) {
if (node instanceof EC2AbstractSlave ec2Slave) {
String instanceId = ec2Slave.getInstanceId();
- if (StringUtils.isEmpty(instanceId)) {
+ if (instanceId == null || instanceId.isEmpty()) {
continue;
}
EC2Cloud cloud = ec2Slave.getCloud();
diff --git a/src/main/java/hudson/plugins/ec2/EC2SpotSlave.java b/src/main/java/hudson/plugins/ec2/EC2SpotSlave.java
index 7256dfe57..a979d347d 100644
--- a/src/main/java/hudson/plugins/ec2/EC2SpotSlave.java
+++ b/src/main/java/hudson/plugins/ec2/EC2SpotSlave.java
@@ -16,7 +16,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.ec2.Ec2Client;
@@ -308,7 +307,7 @@ public String getSpotInstanceRequestId() {
@Override
public String getInstanceId() {
- if (StringUtils.isEmpty(instanceId)) {
+ if (instanceId == null || instanceId.isEmpty()) {
SpotInstanceRequest sr = getSpotRequest();
if (sr != null) {
instanceId = sr.instanceId();
diff --git a/src/main/java/hudson/plugins/ec2/MacData.java b/src/main/java/hudson/plugins/ec2/MacData.java
index 155895457..e657e38f3 100644
--- a/src/main/java/hudson/plugins/ec2/MacData.java
+++ b/src/main/java/hudson/plugins/ec2/MacData.java
@@ -3,7 +3,6 @@
import hudson.Extension;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
public class MacData extends SSHData {
@@ -59,29 +58,29 @@ public boolean equals(Object obj) {
return false;
}
final MacData other = (MacData) obj;
- if (StringUtils.isEmpty(rootCommandPrefix)) {
- if (!StringUtils.isEmpty(other.rootCommandPrefix)) {
+ if (rootCommandPrefix == null || rootCommandPrefix.isEmpty()) {
+ if (other.rootCommandPrefix != null && !other.rootCommandPrefix.isEmpty()) {
return false;
}
} else if (!rootCommandPrefix.equals(other.rootCommandPrefix)) {
return false;
}
- if (StringUtils.isEmpty(slaveCommandPrefix)) {
- if (!StringUtils.isEmpty(other.slaveCommandPrefix)) {
+ if (slaveCommandPrefix == null || slaveCommandPrefix.isEmpty()) {
+ if (other.slaveCommandPrefix != null && !other.slaveCommandPrefix.isEmpty()) {
return false;
}
} else if (!slaveCommandPrefix.equals(other.slaveCommandPrefix)) {
return false;
}
- if (StringUtils.isEmpty(slaveCommandSuffix)) {
- if (!StringUtils.isEmpty(other.slaveCommandSuffix)) {
+ if (slaveCommandSuffix == null || slaveCommandSuffix.isEmpty()) {
+ if (other.slaveCommandSuffix != null && !other.slaveCommandSuffix.isEmpty()) {
return false;
}
} else if (!slaveCommandSuffix.equals(other.slaveCommandSuffix)) {
return false;
}
- if (StringUtils.isEmpty(sshPort)) {
- if (!StringUtils.isEmpty(other.sshPort)) {
+ if (sshPort == null || sshPort.isEmpty()) {
+ if (other.sshPort != null && !other.sshPort.isEmpty()) {
return false;
}
} else if (!sshPort.equals(other.sshPort)) {
diff --git a/src/main/java/hudson/plugins/ec2/SSHData.java b/src/main/java/hudson/plugins/ec2/SSHData.java
index 5d7c5a00a..f43440026 100644
--- a/src/main/java/hudson/plugins/ec2/SSHData.java
+++ b/src/main/java/hudson/plugins/ec2/SSHData.java
@@ -1,7 +1,6 @@
package hudson.plugins.ec2;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
public abstract class SSHData extends AMITypeData {
protected final String rootCommandPrefix;
@@ -103,29 +102,29 @@ public boolean equals(Object obj) {
return false;
}
final SSHData other = (SSHData) obj;
- if (StringUtils.isEmpty(rootCommandPrefix)) {
- if (!StringUtils.isEmpty(other.rootCommandPrefix)) {
+ if (rootCommandPrefix == null || rootCommandPrefix.isEmpty()) {
+ if (other.rootCommandPrefix != null && !other.rootCommandPrefix.isEmpty()) {
return false;
}
} else if (!rootCommandPrefix.equals(other.rootCommandPrefix)) {
return false;
}
- if (StringUtils.isEmpty(slaveCommandPrefix)) {
- if (!StringUtils.isEmpty(other.slaveCommandPrefix)) {
+ if (slaveCommandPrefix == null || slaveCommandPrefix.isEmpty()) {
+ if (other.slaveCommandPrefix != null && !other.slaveCommandPrefix.isEmpty()) {
return false;
}
} else if (!slaveCommandPrefix.equals(other.slaveCommandPrefix)) {
return false;
}
- if (StringUtils.isEmpty(slaveCommandSuffix)) {
- if (!StringUtils.isEmpty(other.slaveCommandSuffix)) {
+ if (slaveCommandSuffix == null || slaveCommandSuffix.isEmpty()) {
+ if (other.slaveCommandSuffix != null && !other.slaveCommandSuffix.isEmpty()) {
return false;
}
} else if (!slaveCommandSuffix.equals(other.slaveCommandSuffix)) {
return false;
}
- if (StringUtils.isEmpty(sshPort)) {
- if (!StringUtils.isEmpty(other.sshPort)) {
+ if (sshPort == null || sshPort.isEmpty()) {
+ if (other.sshPort != null && !other.sshPort.isEmpty()) {
return false;
}
} else if (!sshPort.equals(other.sshPort)) {
diff --git a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java
index 8c0c12bde..dd221b821 100644
--- a/src/main/java/hudson/plugins/ec2/SlaveTemplate.java
+++ b/src/main/java/hudson/plugins/ec2/SlaveTemplate.java
@@ -74,7 +74,6 @@
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.slaves.iterators.api.NodeIterator;
-import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -349,7 +348,9 @@ public SlaveTemplate(
Boolean metadataSupported,
Boolean enclaveEnabled) {
- if (StringUtils.isNotBlank(remoteAdmin) || StringUtils.isNotBlank(jvmopts) || StringUtils.isNotBlank(tmpDir)) {
+ if ((remoteAdmin != null && !remoteAdmin.isBlank())
+ || (jvmopts != null && !jvmopts.isBlank())
+ || (tmpDir != null && !tmpDir.isBlank())) {
LOGGER.log(
Level.FINE,
"As remoteAdmin, jvmopts or tmpDir is not blank, we must ensure the user has ADMINISTER rights.");
@@ -374,11 +375,11 @@ public SlaveTemplate(
this.description = description;
this.initScript = initScript;
this.tmpDir = tmpDir;
- this.userData = StringUtils.trimToEmpty(userData);
+ this.userData = userData == null ? "" : userData.trim();
this.numExecutors = Util.fixNull(numExecutors).trim();
this.remoteAdmin = remoteAdmin;
- if (StringUtils.isNotBlank(javaPath)) {
+ if (javaPath != null && !javaPath.isBlank()) {
this.javaPath = javaPath;
} else {
this.javaPath = EC2AbstractSlave.DEFAULT_JAVA_PATH;
@@ -1714,7 +1715,7 @@ public String getSlaveCommandSuffix() {
}
public String chooseSubnetId() {
- if (StringUtils.isBlank(subnetId)) {
+ if (subnetId == null || subnetId.isBlank()) {
return null;
} else {
String[] subnetIdList = getSubnetId().split(EC2_RESOURCE_ID_DELIMETERS);
@@ -2136,9 +2137,10 @@ private void logInstanceCheck(Instance instance, String message) {
}
private boolean isSameIamInstanceProfile(Instance instance) {
- return StringUtils.isBlank(getIamInstanceProfile())
+ String iamProfile = getIamInstanceProfile();
+ return (iamProfile == null || iamProfile.isBlank())
|| (instance.iamInstanceProfile() != null
- && instance.iamInstanceProfile().arn().equals(getIamInstanceProfile()));
+ && instance.iamInstanceProfile().arn().equals(iamProfile));
}
private boolean isTerminatingOrShuttindDown(InstanceStateName instanceStateName) {
@@ -2207,13 +2209,14 @@ HashMap> makeRunInstancesRequestAndFilters(
.build());
Placement.Builder placementBuilder = Placement.builder();
- if (StringUtils.isNotBlank(getZone())) {
+ String zone = getZone();
+ if (zone != null && !zone.isBlank()) {
if (getTenancyAttribute().equals(Tenancy.Dedicated)) {
placementBuilder.tenancy("dedicated");
}
riRequestBuilder.placement(placementBuilder.build());
diFilters.add(
- Filter.builder().name("availability-zone").values(getZone()).build());
+ Filter.builder().name("availability-zone").values(zone).build());
}
if (getTenancyAttribute().equals(Tenancy.Host)) {
@@ -2238,7 +2241,7 @@ HashMap> makeRunInstancesRequestAndFilters(
LOGGER.log(Level.FINE, () -> String.format("Chose subnetId %s", subnetId));
InstanceNetworkInterfaceSpecification.Builder netBuilder = InstanceNetworkInterfaceSpecification.builder();
- if (StringUtils.isNotBlank(subnetId)) {
+ if (subnetId != null && !subnetId.isBlank()) {
netBuilder.subnetId(subnetId);
diFilters.add(Filter.builder().name("subnet-id").values(subnetId).build());
@@ -2295,10 +2298,10 @@ HashMap> makeRunInstancesRequestAndFilters(
.build());
}
- if (StringUtils.isNotBlank(getIamInstanceProfile())) {
- riRequestBuilder.iamInstanceProfile(IamInstanceProfileSpecification.builder()
- .arn(getIamInstanceProfile())
- .build());
+ String iamProfile = getIamInstanceProfile();
+ if (iamProfile != null && !iamProfile.isBlank()) {
+ riRequestBuilder.iamInstanceProfile(
+ IamInstanceProfileSpecification.builder().arn(iamProfile).build());
}
List tagList = new ArrayList<>();
@@ -2657,7 +2660,7 @@ private Image getImage() throws SdkException {
}
private void setupCustomDeviceMapping(List deviceMappings) {
- if (StringUtils.isNotBlank(customDeviceMapping)) {
+ if (customDeviceMapping != null && !customDeviceMapping.isBlank()) {
deviceMappings.addAll(DeviceMappingParser.parse(customDeviceMapping));
}
}
@@ -2700,16 +2703,17 @@ private List provisionSpot(Image image, int number, EnumSet String.format("Chose subnetId %s", subnetId));
- if (StringUtils.isNotBlank(subnetId)) {
+ if (subnetId != null && !subnetId.isBlank()) {
netBuilder.subnetId(subnetId);
/*
@@ -2754,9 +2758,10 @@ private List provisionSpot(Image image, int number, EnumSet instTags = buildTags(EC2Cloud.EC2_SLAVE_TYPE_SPOT);
- if (StringUtils.isNotBlank(getIamInstanceProfile())) {
+ String iamProfile = getIamInstanceProfile();
+ if (iamProfile != null && !iamProfile.isBlank()) {
launchSpecificationBuilder.iamInstanceProfile(IamInstanceProfileSpecification.builder()
- .arn(getIamInstanceProfile())
+ .arn(iamProfile)
.build());
}
@@ -2860,7 +2865,7 @@ private List getBlockDeviceMappings(Image image) {
if (useEphemeralDevices) {
newMappings.addAll(getNewEphemeralDeviceMapping(image));
} else {
- if (StringUtils.isNotBlank(customDeviceMapping)) {
+ if (customDeviceMapping != null && !customDeviceMapping.isBlank()) {
newMappings.addAll(DeviceMappingParser.parse(customDeviceMapping));
}
}
@@ -2874,10 +2879,10 @@ private HashSet buildTags(String slaveType) {
if (tags != null && !tags.isEmpty()) {
for (EC2Tag t : tags) {
instTags.add(Tag.builder().key(t.getName()).value(t.getValue()).build());
- if (StringUtils.equals(t.getName(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)) {
+ if (Objects.equals(t.getName(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)) {
hasCustomTypeTag = true;
}
- if (StringUtils.equals(t.getName(), EC2Tag.TAG_NAME_JENKINS_SERVER_URL)) {
+ if (Objects.equals(t.getName(), EC2Tag.TAG_NAME_JENKINS_SERVER_URL)) {
hasJenkinsServerUrlTag = true;
}
}
@@ -2896,7 +2901,7 @@ private HashSet buildTags(String slaveType) {
.build());
}
- if (parent != null && StringUtils.isNotBlank(parent.name)) {
+ if (parent != null && parent.name != null && !parent.name.isBlank()) {
instTags.add(Tag.builder()
.key(EC2Tag.TAG_NAME_JENKINS_CLOUD_NAME)
.value(parent.name)
@@ -3175,7 +3180,7 @@ protected Object readResolve() {
if (metadataHopsLimit == null) {
metadataHopsLimit = EC2AbstractSlave.DEFAULT_METADATA_HOPS_LIMIT;
}
- if (StringUtils.isBlank(javaPath)) {
+ if (javaPath == null || javaPath.isBlank()) {
javaPath = EC2AbstractSlave.DEFAULT_JAVA_PATH;
}
if (enclaveEnabled == null) {
diff --git a/src/main/java/hudson/plugins/ec2/ssh/EC2MacLauncher.java b/src/main/java/hudson/plugins/ec2/ssh/EC2MacLauncher.java
index 00c315a1a..027983419 100644
--- a/src/main/java/hudson/plugins/ec2/ssh/EC2MacLauncher.java
+++ b/src/main/java/hudson/plugins/ec2/ssh/EC2MacLauncher.java
@@ -43,7 +43,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.scp.client.CloseableScpClient;
import org.apache.sshd.scp.common.helpers.ScpTimestampCommandDetails;
@@ -163,7 +162,8 @@ protected void launchScript(EC2Computer computer, TaskListener listener)
logInfo(computer, listener, "Creating tmp directory (" + tmpDir + ") if it does not exist");
executeRemote(clientSession, "mkdir -p " + tmpDir, logger);
- if (StringUtils.isNotBlank(initScript)
+ if (initScript != null
+ && !initScript.isBlank()
&& !executeRemote(clientSession, "test -e ~/.hudson-run-init", logger)) {
logInfo(computer, listener, "Upload init script");
scp.upload(
diff --git a/src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java b/src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java
index 191b35bab..ffc7ea7e7 100644
--- a/src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java
+++ b/src/main/java/hudson/plugins/ec2/ssh/EC2SSHLauncher.java
@@ -41,12 +41,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.future.ConnectFuture;
@@ -353,7 +353,7 @@ public Collection> attributeKeys() {
throw new IOException("goto sleep");
}
- if (StringUtils.isBlank(host)) {
+ if (host == null || host.isBlank()) {
logWarning(computer, listener, "Empty host, your host is most likely waiting for an ip address.");
throw new IOException("goto sleep");
}
@@ -404,8 +404,8 @@ public Collection> attributeKeys() {
logInfo(computer, listener, "Failed to connect via ssh: " + e.getMessage());
if (computer.isOffline()
- && StringUtils.isNotBlank(computer.getOfflineCauseReason())
- && computer.getOfflineCauseReason().equals(Messages.OfflineCause_SSHKeyCheckFailed())) {
+ && Objects.equals(
+ computer.getOfflineCauseReason(), Messages.OfflineCause_SSHKeyCheckFailed())) {
throw SdkException.create(
"The connection couldn't be established and the computer is now offline", e);
} else {
diff --git a/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java b/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
index 61cd8e201..b3c8d4373 100644
--- a/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
+++ b/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
@@ -43,7 +43,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.scp.client.CloseableScpClient;
import org.apache.sshd.scp.common.helpers.ScpTimestampCommandDetails;
@@ -160,7 +159,8 @@ protected void launchScript(EC2Computer computer, TaskListener listener)
logInfo(computer, listener, "Creating tmp directory (" + tmpDir + ") if it does not exist");
executeRemote(clientSession, "mkdir -p " + tmpDir, logger);
- if (StringUtils.isNotBlank(initScript)
+ if (initScript != null
+ && !initScript.isBlank()
&& !executeRemote(clientSession, "test -e ~/.hudson-run-init", logger)) {
logInfo(computer, listener, "Upload init script");
scp.upload(
diff --git a/src/main/java/hudson/plugins/ec2/ssh/EC2WindowsSSHLauncher.java b/src/main/java/hudson/plugins/ec2/ssh/EC2WindowsSSHLauncher.java
index bc4ba7240..a4bd3b848 100644
--- a/src/main/java/hudson/plugins/ec2/ssh/EC2WindowsSSHLauncher.java
+++ b/src/main/java/hudson/plugins/ec2/ssh/EC2WindowsSSHLauncher.java
@@ -20,7 +20,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
-import org.apache.commons.lang.StringUtils;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.scp.client.CloseableScpClient;
import org.apache.sshd.scp.common.helpers.ScpTimestampCommandDetails;
@@ -134,7 +133,8 @@ protected void launchScript(EC2Computer computer, TaskListener listener)
logInfo(computer, listener, "Creating tmp directory (" + tmpDir + ") if it does not exist");
executeRemote(clientSession, "IF NOT EXIST " + tmpDir + " MKDIR " + tmpDir, logger);
- if (StringUtils.isNotBlank(initScript)
+ if (initScript != null
+ && !initScript.isBlank()
&& !executeRemote(
clientSession, "IF NOT EXIST %USERPROFILE%\\.hudson-run-init EXIT /B 999", logger)) {
logInfo(computer, listener, "Upload init script");
diff --git a/src/main/java/hudson/plugins/ec2/util/DeviceMappingParser.java b/src/main/java/hudson/plugins/ec2/util/DeviceMappingParser.java
index d6a0816ba..176f16150 100644
--- a/src/main/java/hudson/plugins/ec2/util/DeviceMappingParser.java
+++ b/src/main/java/hudson/plugins/ec2/util/DeviceMappingParser.java
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.lang.StringUtils;
import software.amazon.awssdk.services.ec2.model.BlockDeviceMapping;
import software.amazon.awssdk.services.ec2.model.EbsBlockDevice;
@@ -65,25 +64,25 @@ private static EbsBlockDevice parseEbs(String blockDevice) {
String[] parts = blockDevice.split(":");
EbsBlockDevice.Builder ebsBuilder = EbsBlockDevice.builder();
- if (StringUtils.isNotBlank(getOrEmpty(parts, 0))) {
+ if (!getOrEmpty(parts, 0).isBlank()) {
ebsBuilder.snapshotId(parts[0]);
}
- if (StringUtils.isNotBlank(getOrEmpty(parts, 1))) {
+ if (!getOrEmpty(parts, 1).isBlank()) {
ebsBuilder.volumeSize(Integer.valueOf(parts[1]));
}
- if (StringUtils.isNotBlank(getOrEmpty(parts, 2))) {
+ if (!getOrEmpty(parts, 2).isBlank()) {
ebsBuilder.deleteOnTermination(Boolean.valueOf(parts[2]));
}
- if (StringUtils.isNotBlank(getOrEmpty(parts, 3))) {
+ if (!getOrEmpty(parts, 3).isBlank()) {
ebsBuilder.volumeType(parts[3]);
}
- if (StringUtils.isNotBlank(getOrEmpty(parts, 4))) {
+ if (!getOrEmpty(parts, 4).isBlank()) {
ebsBuilder.iops(Integer.valueOf(parts[4]));
}
- if (StringUtils.isNotBlank(getOrEmpty(parts, 5))) {
+ if (!getOrEmpty(parts, 5).isBlank()) {
ebsBuilder.encrypted(parts[5].equals("encrypted"));
}
- if (StringUtils.isNotBlank(getOrEmpty(parts, 6))) {
+ if (!getOrEmpty(parts, 6).isBlank()) {
ebsBuilder.throughput(Integer.valueOf(parts[6]));
}
diff --git a/src/main/java/hudson/plugins/ec2/util/FIPS140Utils.java b/src/main/java/hudson/plugins/ec2/util/FIPS140Utils.java
index 11aa27d5b..51a8153e7 100644
--- a/src/main/java/hudson/plugins/ec2/util/FIPS140Utils.java
+++ b/src/main/java/hudson/plugins/ec2/util/FIPS140Utils.java
@@ -11,7 +11,6 @@
import java.security.interfaces.RSAKey;
import jenkins.bouncycastle.api.PEMEncodable;
import jenkins.security.FIPS140;
-import org.apache.commons.lang.StringUtils;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.DSAPublicKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
@@ -75,7 +74,7 @@ public static void ensureNoPasswordLeak(URL url, String password) {
* @throws IllegalArgumentException if there is a risk that the password will leak
*/
public static void ensureNoPasswordLeak(boolean useHTTPS, String password) {
- ensureNoPasswordLeak(useHTTPS, !StringUtils.isEmpty(password));
+ ensureNoPasswordLeak(useHTTPS, password != null && !password.isEmpty());
}
/**
@@ -101,7 +100,7 @@ public static void ensureNoPasswordLeak(boolean useHTTPS, boolean usePassword) {
*/
public static void ensurePasswordLength(String password) {
if (FIPS140.useCompliantAlgorithms()) {
- if (StringUtils.isBlank(password) || password.length() < 14) {
+ if (password == null || password.isBlank() || password.length() < 14) {
throw new IllegalArgumentException(Messages.EC2Cloud_passwordLengthInFIPSMode());
}
}
@@ -137,7 +136,7 @@ public static void ensurePrivateKeyInFipsMode(String privateKeyString) {
if (!FIPS140.useCompliantAlgorithms()) {
return;
}
- if (StringUtils.isBlank(privateKeyString)) {
+ if (privateKeyString == null || privateKeyString.isBlank()) {
throw new IllegalArgumentException(Messages.EC2Cloud_keyIsMandatoryInFIPSMode());
}
try {