polish: Use ObjectUtils#isEmpty(Object).
Co-authored-by: Moderne <team@moderne.io>
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.config.environment.EnvironmentMediaType;
|
||||
import org.springframework.cloud.configuration.TlsProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@@ -326,7 +327,7 @@ public class ConfigClientProperties {
|
||||
URL url = new URL(uri);
|
||||
String userInfo = url.getUserInfo();
|
||||
// no credentials in url, return explicit credentials
|
||||
if (StringUtils.isEmpty(userInfo) || ":".equals(userInfo)) {
|
||||
if (ObjectUtils.isEmpty(userInfo) || ":".equals(userInfo)) {
|
||||
return result;
|
||||
}
|
||||
String bare = UriComponentsBuilder.fromHttpUrl(uri).userInfo(null).build().toUriString();
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.cloud.config.environment.PropertySource;
|
||||
import org.springframework.cloud.config.server.encryption.CipherEnvironmentEncryptor;
|
||||
import org.springframework.cloud.config.server.encryption.EnvironmentEncryptor;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.vault.core.VaultKeyValueOperations;
|
||||
import org.springframework.vault.support.VaultResponse;
|
||||
|
||||
@@ -80,7 +80,7 @@ public class VaultEnvironmentEncryptor implements EnvironmentEncryptor {
|
||||
throw new RuntimeException("Wrong format");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(parts[0]) || StringUtils.isEmpty(parts[1])) {
|
||||
if (ObjectUtils.isEmpty(parts[0]) || ObjectUtils.isEmpty(parts[1])) {
|
||||
throw new RuntimeException("Wrong format");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.cloud.config.environment.PropertySource;
|
||||
import org.springframework.cloud.config.server.config.ConfigServerProperties;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -68,11 +69,11 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
|
||||
|
||||
@Override
|
||||
public Environment findOne(String specifiedApplication, String specifiedProfiles, String specifiedLabel) {
|
||||
final String application = StringUtils.isEmpty(specifiedApplication)
|
||||
final String application = ObjectUtils.isEmpty(specifiedApplication)
|
||||
? serverProperties.getDefaultApplicationName() : specifiedApplication;
|
||||
final String profiles = StringUtils.isEmpty(specifiedProfiles) ? serverProperties.getDefaultProfile()
|
||||
final String profiles = ObjectUtils.isEmpty(specifiedProfiles) ? serverProperties.getDefaultProfile()
|
||||
: specifiedProfiles;
|
||||
final String label = StringUtils.isEmpty(specifiedLabel) ? serverProperties.getDefaultLabel() : specifiedLabel;
|
||||
final String label = ObjectUtils.isEmpty(specifiedLabel) ? serverProperties.getDefaultLabel() : specifiedLabel;
|
||||
|
||||
String[] profileArray = parseProfiles(profiles);
|
||||
String[] apps = new String[] { application };
|
||||
@@ -120,11 +121,11 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
|
||||
|
||||
private String buildObjectKeyPrefix(String application, String profile, String label) {
|
||||
StringBuilder objectKeyPrefix = new StringBuilder();
|
||||
if (!StringUtils.isEmpty(label)) {
|
||||
if (!ObjectUtils.isEmpty(label)) {
|
||||
objectKeyPrefix.append(label).append(PATH_SEPARATOR);
|
||||
}
|
||||
objectKeyPrefix.append(application);
|
||||
if (!StringUtils.isEmpty(profile)) {
|
||||
if (!ObjectUtils.isEmpty(profile)) {
|
||||
objectKeyPrefix.append("-").append(profile);
|
||||
}
|
||||
return objectKeyPrefix.toString();
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
import org.springframework.cloud.config.environment.PropertySource;
|
||||
import org.springframework.cloud.config.server.config.ConfigServerProperties;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.cloud.config.server.environment.AwsSecretsManagerEnvironmentProperties.DEFAULT_PATH_SEPARATOR;
|
||||
@@ -66,11 +67,11 @@ public class AwsSecretsManagerEnvironmentRepository implements EnvironmentReposi
|
||||
final String defaultApplication = configServerProperties.getDefaultApplicationName();
|
||||
final String defaultProfile = configServerProperties.getDefaultProfile();
|
||||
|
||||
if (StringUtils.isEmpty(application)) {
|
||||
if (ObjectUtils.isEmpty(application)) {
|
||||
application = defaultApplication;
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(profileList)) {
|
||||
if (ObjectUtils.isEmpty(profileList)) {
|
||||
profileList = defaultProfile;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.amazonaws.services.secretsmanager.AWSSecretsManager;
|
||||
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
|
||||
|
||||
import org.springframework.cloud.config.server.config.ConfigServerProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Tejas Pandilwar
|
||||
@@ -41,12 +41,12 @@ public class AwsSecretsManagerEnvironmentRepositoryFactory implements
|
||||
AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard();
|
||||
String region = environmentProperties.getRegion();
|
||||
|
||||
if (!StringUtils.isEmpty(region)) {
|
||||
if (!ObjectUtils.isEmpty(region)) {
|
||||
Regions awsRegion = Regions.fromName(region);
|
||||
clientBuilder.withRegion(awsRegion);
|
||||
|
||||
String endpoint = environmentProperties.getEndpoint();
|
||||
if (!StringUtils.isEmpty(endpoint)) {
|
||||
if (!ObjectUtils.isEmpty(endpoint)) {
|
||||
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
|
||||
endpoint, awsRegion.getName());
|
||||
clientBuilder.withEndpointConfiguration(endpointConfiguration);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.support.CredentialDetails;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.json.JsonCredential;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
@@ -48,10 +49,10 @@ public class CredhubEnvironmentRepository implements EnvironmentRepository {
|
||||
|
||||
@Override
|
||||
public Environment findOne(String application, String profilesList, String label) {
|
||||
if (StringUtils.isEmpty(profilesList)) {
|
||||
if (ObjectUtils.isEmpty(profilesList)) {
|
||||
profilesList = DEFAULT_PROFILE;
|
||||
}
|
||||
if (StringUtils.isEmpty(label)) {
|
||||
if (ObjectUtils.isEmpty(label)) {
|
||||
label = DEFAULT_LABEL;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.eclipse.jgit.transport.http.HttpConnection;
|
||||
import org.eclipse.jgit.transport.http.apache.HttpClientConnection;
|
||||
|
||||
import org.springframework.cloud.config.server.support.HttpClientSupport;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
@@ -144,14 +144,14 @@ public class HttpClientConfigurableHttpConnectionFactory implements Configurable
|
||||
List<String> values = new LinkedList<>();
|
||||
for (String token : tokens) {
|
||||
String[] valueTokens = spec.split(token);
|
||||
if (!StringUtils.isEmpty(valueTokens[0])) {
|
||||
if (!ObjectUtils.isEmpty(valueTokens[0])) {
|
||||
values.add(valueTokens[0]);
|
||||
}
|
||||
if (valueTokens.length > 1) {
|
||||
spec = valueTokens[1];
|
||||
}
|
||||
}
|
||||
if (tokens.length == 1 && !StringUtils.isEmpty(spec)) {
|
||||
if (tokens.length == 1 && !ObjectUtils.isEmpty(spec)) {
|
||||
values.add(spec);
|
||||
}
|
||||
return values;
|
||||
|
||||
@@ -64,6 +64,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.lang.String.format;
|
||||
@@ -343,14 +344,14 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
|
||||
// Check if git points to valid repository and default label is not empty or
|
||||
// null.
|
||||
if (null != git && git.getRepository() != null && !StringUtils.isEmpty(getDefaultLabel())) {
|
||||
if (null != git && git.getRepository() != null && !ObjectUtils.isEmpty(getDefaultLabel())) {
|
||||
// Checkout the default branch set for repo in git. This may not always be
|
||||
// master. It depends on the
|
||||
// admin and organization settings.
|
||||
String defaultBranchInGit = git.getRepository().getBranch();
|
||||
// If default branch is not empty and NOT equal to defaultLabel, then
|
||||
// checkout the branch/tag/commit-id.
|
||||
if (!StringUtils.isEmpty(defaultBranchInGit)
|
||||
if (!ObjectUtils.isEmpty(defaultBranchInGit)
|
||||
&& !getDefaultLabel().equalsIgnoreCase(defaultBranchInGit)) {
|
||||
checkout(git, getDefaultLabel());
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.core.Ordered;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -83,10 +84,10 @@ public class JdbcEnvironmentRepository implements EnvironmentRepository, Ordered
|
||||
@Override
|
||||
public Environment findOne(String application, String profile, String label) {
|
||||
String config = application;
|
||||
if (StringUtils.isEmpty(label)) {
|
||||
if (ObjectUtils.isEmpty(label)) {
|
||||
label = "master";
|
||||
}
|
||||
if (StringUtils.isEmpty(profile)) {
|
||||
if (ObjectUtils.isEmpty(profile)) {
|
||||
profile = "default";
|
||||
}
|
||||
if (!profile.startsWith("default")) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.cloud.config.server.environment.VaultEnvironmentPrope
|
||||
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties.AuthenticationMethod;
|
||||
import org.springframework.cloud.config.server.environment.vault.SpringVaultClientAuthenticationProvider;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.vault.authentication.ClientAuthentication;
|
||||
import org.springframework.vault.authentication.PcfAuthentication;
|
||||
import org.springframework.vault.authentication.PcfAuthenticationOptions;
|
||||
@@ -67,7 +67,7 @@ public class PcfClientAuthenticationProvider extends SpringVaultClientAuthentica
|
||||
|
||||
String value = System.getenv(name);
|
||||
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
if (ObjectUtils.isEmpty(value)) {
|
||||
throw new IllegalStateException(String.format("Environment variable %s not set", name));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -43,7 +44,7 @@ public abstract class PathUtils {
|
||||
* @return {@code true} if the path is invalid, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isInvalidEncodedLocation(String location) {
|
||||
if (StringUtils.isEmpty(location)) {
|
||||
if (ObjectUtils.isEmpty(location)) {
|
||||
return false;
|
||||
}
|
||||
if (location.contains("%")) {
|
||||
|
||||
Reference in New Issue
Block a user