diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientProperties.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientProperties.java index fa579d56..3565b9a2 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientProperties.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientProperties.java @@ -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(); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java index 5bb435cd..073f1598 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptor.java @@ -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"); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java index b3a52831..1ce9a7f0 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java @@ -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(); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java index bfafdc5a..07883563 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepository.java @@ -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; } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryFactory.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryFactory.java index 50c891d3..681f9523 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryFactory.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryFactory.java @@ -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); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java index c560c773..6f72775f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepository.java @@ -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; } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java index 76d8ec0d..77dd92bb 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java @@ -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 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; diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index 3acd439d..129a0cbb 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -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()); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java index 0ebe2d04..4f7941e7 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepository.java @@ -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")) { diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java index ef4bc33f..5c8f49b3 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/vault/authentication/PcfClientAuthenticationProvider.java @@ -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)); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/PathUtils.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/PathUtils.java index ed065f22..dab98a6f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/PathUtils.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/PathUtils.java @@ -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("%")) {