From daad886703f9714ea0915f15bd5a8a12355139f0 Mon Sep 17 00:00:00 2001 From: Corneil du Plessis Date: Thu, 7 Nov 2024 16:01:56 +0200 Subject: [PATCH] Updated toLowerCase() to toLowerCase(Locale.ROOT) and toUpperCase() to toUpperCase(Locale.ROOT) Fixes #489 --- .../spi/cloudfoundry/AbstractCloudFoundryDeployer.java | 3 ++- .../deployer/spi/cloudfoundry/CfEnvAwareResource.java | 3 ++- .../cloudfoundry/expression/QuartzCronExpression.java | 2 +- .../spi/kubernetes/AbstractKubernetesDeployer.java | 3 ++- .../deployer/spi/kubernetes/DefaultContainerFactory.java | 5 +++-- .../spi/kubernetes/DeploymentPropertiesResolver.java | 5 +++-- .../deployer/spi/kubernetes/KubernetesAppDeployer.java | 7 ++++--- .../deployer/spi/kubernetes/KubernetesTaskLauncher.java | 3 ++- .../deployer/spi/kubernetes/support/RelaxedNames.java | 6 +++--- .../cloud/deployer/spi/local/LocalDeployerUtils.java | 4 +++- .../local/LocalAppDeployerEnvironmentIntegrationTests.java | 3 ++- .../deployer/spi/kubernetes/DefaultContainerFactory.java | 4 ++-- .../deployer/spi/kubernetes/KubernetesAppDeployer.java | 6 +++--- .../cloud/deployer/spi/local/LocalDeployerUtils.java | 2 +- .../local/LocalAppDeployerEnvironmentIntegrationTests.java | 2 +- 15 files changed, 34 insertions(+), 24 deletions(-) diff --git a/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/AbstractCloudFoundryDeployer.java b/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/AbstractCloudFoundryDeployer.java index 7210c1b1..90dfcdfc 100644 --- a/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/AbstractCloudFoundryDeployer.java +++ b/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/AbstractCloudFoundryDeployer.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -317,7 +318,7 @@ protected void deleteLocalApplicationResourceFile(AppDeploymentRequest appDeploy * Delete maven resources if property is set. */ private Optional fileToDelete(Resource resource) throws IOException { - String scheme = resource.getURI().getScheme().toLowerCase(); + String scheme = resource.getURI().getScheme().toLowerCase(Locale.ROOT); if (scheme.startsWith("http")) { return Optional.of(resource.getFile()); } diff --git a/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareResource.java b/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareResource.java index 1f975392..11ece089 100644 --- a/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareResource.java +++ b/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareResource.java @@ -25,6 +25,7 @@ import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Optional; import org.apache.commons.logging.Log; @@ -120,7 +121,7 @@ static class CfEnvResolver { static boolean hasCfEnv(CfEnvAwareResource app ) { try { - String scheme = app.getURI().getScheme().toLowerCase(); + String scheme = app.getURI().getScheme().toLowerCase(Locale.ROOT); if (scheme.equals("docker")) { return false; } diff --git a/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/expression/QuartzCronExpression.java b/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/expression/QuartzCronExpression.java index f8be61fa..52b6c799 100644 --- a/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/expression/QuartzCronExpression.java +++ b/spring-cloud-deployer-cloudfoundry/src/main/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/expression/QuartzCronExpression.java @@ -106,7 +106,7 @@ public QuartzCronExpression(String cronExpression) throws ParseException { throw new IllegalArgumentException("cronExpression cannot be null"); } - this.cronExpression = cronExpression.toUpperCase(Locale.US); + this.cronExpression = cronExpression.toUpperCase(Locale.ROOT); buildExpression(this.cronExpression); } diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/AbstractKubernetesDeployer.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/AbstractKubernetesDeployer.java index ffb1dd90..6bcf0c15 100755 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/AbstractKubernetesDeployer.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/AbstractKubernetesDeployer.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -349,7 +350,7 @@ String createDeploymentId(AppDeploymentRequest request) { deploymentId = String.format("%s-%s", groupId, request.getDefinition().getName()); } // Kubernetes does not allow . in the name and does not allow uppercase in the name - return deploymentId.replace('.', '-').toLowerCase(); + return deploymentId.replace('.', '-').toLowerCase(Locale.ROOT); } /** diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java index ee5b251a..5968f2bc 100644 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -126,7 +127,7 @@ public Container create(ContainerConfiguration containerConfiguration) { break; case shell: for (String key : request.getDefinition().getProperties().keySet()) { - String envVar = key.replace('.', '_').toUpperCase(); + String envVar = key.replace('.', '_').toUpperCase(Locale.ROOT); envVarsMap.put(envVar, request.getDefinition().getProperties().get(key)); envVarsMap.putAll(appAdminCredentials); @@ -144,7 +145,7 @@ public Container create(ContainerConfiguration containerConfiguration) { } String cmdLineArgValue = cmdLineArg.substring(cmdLineArg.indexOf("=") + 1); - envVarsMap.put(cmdLineArgKey.replace('.', '_').toUpperCase(), cmdLineArgValue); + envVarsMap.put(cmdLineArgKey.replace('.', '_').toUpperCase(Locale.ROOT), cmdLineArgValue); } break; } diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java index 5256d489..b638b20f 100644 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -1048,7 +1049,7 @@ EntryPointStyle determineEntryPointStyle(Map deploymentPropertie if (deployerPropertyValue != null) { try { - entryPointStyle = EntryPointStyle.valueOf(deployerPropertyValue.toLowerCase()); + entryPointStyle = EntryPointStyle.valueOf(deployerPropertyValue.toLowerCase(Locale.ROOT)); } catch (IllegalArgumentException ignore) { } @@ -1067,7 +1068,7 @@ ProbeType determineProbeType(Map deploymentProperties) { this.propertyPrefix + ".probeType", null); if (StringUtils.hasText(deployerPropertyValue)) { - probeType = ProbeType.valueOf(deployerPropertyValue.toUpperCase()); + probeType = ProbeType.valueOf(deployerPropertyValue.toUpperCase(Locale.ROOT)); } return probeType; diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java index 2c6b3df5..e7029698 100755 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -364,7 +365,7 @@ protected void createService(AppDeploymentRequest request) { if (createLoadBalancer == null) { isCreateLoadBalancer = properties.isCreateLoadBalancer(); } else { - if ("true".equals(createLoadBalancer.toLowerCase())) { + if ("true".equals(createLoadBalancer.toLowerCase(Locale.ROOT))) { isCreateLoadBalancer = true; } } @@ -379,7 +380,7 @@ protected void createService(AppDeploymentRequest request) { if (createNodePort != null) { spec.withType("NodePort"); - if (!"true".equals(createNodePort.toLowerCase())) { + if (!"true".equals(createNodePort.toLowerCase(Locale.ROOT))) { try { Integer nodePort = Integer.valueOf(createNodePort); servicePort.setNodePort(nodePort); @@ -462,7 +463,7 @@ private String formatServiceName(AppDeploymentRequest request, String appName) { String serviceName = groupId == null ? String.format("%s", appName) : String.format("%s-%s", groupId, appName); - return serviceName.replace('.', '-').toLowerCase(); + return serviceName.replace('.', '-').toLowerCase(Locale.ROOT); } private Set addAdditionalServicePorts(String additionalServicePorts) { diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java index 11458b00..ad97df12 100755 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; @@ -231,7 +232,7 @@ protected String createDeploymentId(AppDeploymentRequest request) { String hashid = hashids.encode(idToEncode); String deploymentId = name + "-" + hashid; // Kubernetes does not allow . in the name and does not allow uppercase in the name - return deploymentId.replace('.', '-').toLowerCase(); + return deploymentId.replace('.', '-').toLowerCase(Locale.ROOT); } diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/support/RelaxedNames.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/support/RelaxedNames.java index 3feb60e7..2d5544f9 100644 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/support/RelaxedNames.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/support/RelaxedNames.java @@ -90,7 +90,7 @@ public String apply(String value) { @Override public String apply(String value) { - return (value.isEmpty() ? value : value.toLowerCase(Locale.ENGLISH)); + return (value.isEmpty() ? value : value.toLowerCase(Locale.ROOT)); } }, @@ -99,7 +99,7 @@ public String apply(String value) { @Override public String apply(String value) { - return (value.isEmpty() ? value : value.toUpperCase(Locale.ENGLISH)); + return (value.isEmpty() ? value : value.toUpperCase(Locale.ROOT)); } }; @@ -224,7 +224,7 @@ private static String separatedToCamelCase(String value, } StringBuilder builder = new StringBuilder(); for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) { - field = (caseInsensitive ? field.toLowerCase(Locale.ENGLISH) : field); + field = (caseInsensitive ? field.toLowerCase(Locale.ROOT) : field); builder.append( builder.length() != 0 ? StringUtils.capitalize(field) : field); } diff --git a/spring-cloud-deployer-local/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java b/spring-cloud-deployer-local/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java index 415fc839..6eb4cfb0 100644 --- a/spring-cloud-deployer-local/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java +++ b/spring-cloud-deployer-local/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java @@ -16,6 +16,8 @@ package org.springframework.cloud.deployer.spi.local; +import java.util.Locale; + /** * Deployer utility functions. * @@ -33,6 +35,6 @@ public class LocalDeployerUtils { protected static boolean isWindows() { String osName = System.getProperty("os.name"); - return osName != null && osName.toLowerCase().startsWith("windows"); + return osName != null && osName.toLowerCase(Locale.ROOT).startsWith("windows"); } } diff --git a/spring-cloud-deployer-local/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java b/spring-cloud-deployer-local/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java index e1153295..63bdb828 100644 --- a/spring-cloud-deployer-local/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java +++ b/spring-cloud-deployer-local/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java @@ -23,6 +23,7 @@ import java.time.Duration; import java.util.Collections; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; @@ -283,7 +284,7 @@ public void testActuatorOperations() { Collections.singletonMap("configuredLevel", "debug"), Object.class); loggers = actuatorOperations .getFromActuator(deploymentId, id, "/loggers/org.springframework", Map.class); - assertThat(((String)loggers.get("configuredLevel")).toLowerCase()).isEqualTo("debug"); + assertThat(((String)loggers.get("configuredLevel")).toLowerCase(Locale.ROOT)).isEqualTo("debug"); } diff --git a/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java b/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java index ee5b251a..89182999 100644 --- a/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java +++ b/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DefaultContainerFactory.java @@ -126,7 +126,7 @@ public Container create(ContainerConfiguration containerConfiguration) { break; case shell: for (String key : request.getDefinition().getProperties().keySet()) { - String envVar = key.replace('.', '_').toUpperCase(); + String envVar = key.replace('.', '_').toUpperCase(Locale.ROOT); envVarsMap.put(envVar, request.getDefinition().getProperties().get(key)); envVarsMap.putAll(appAdminCredentials); @@ -144,7 +144,7 @@ public Container create(ContainerConfiguration containerConfiguration) { } String cmdLineArgValue = cmdLineArg.substring(cmdLineArg.indexOf("=") + 1); - envVarsMap.put(cmdLineArgKey.replace('.', '_').toUpperCase(), cmdLineArgValue); + envVarsMap.put(cmdLineArgKey.replace('.', '_').toUpperCase(Locale.ROOT), cmdLineArgValue); } break; } diff --git a/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java b/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java index 2c6b3df5..66483b77 100755 --- a/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java +++ b/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java @@ -364,7 +364,7 @@ protected void createService(AppDeploymentRequest request) { if (createLoadBalancer == null) { isCreateLoadBalancer = properties.isCreateLoadBalancer(); } else { - if ("true".equals(createLoadBalancer.toLowerCase())) { + if ("true".equals(createLoadBalancer.toLowerCase(Locale.ROOT))) { isCreateLoadBalancer = true; } } @@ -379,7 +379,7 @@ protected void createService(AppDeploymentRequest request) { if (createNodePort != null) { spec.withType("NodePort"); - if (!"true".equals(createNodePort.toLowerCase())) { + if (!"true".equals(createNodePort.toLowerCase(Locale.ROOT))) { try { Integer nodePort = Integer.valueOf(createNodePort); servicePort.setNodePort(nodePort); @@ -462,7 +462,7 @@ private String formatServiceName(AppDeploymentRequest request, String appName) { String serviceName = groupId == null ? String.format("%s", appName) : String.format("%s-%s", groupId, appName); - return serviceName.replace('.', '-').toLowerCase(); + return serviceName.replace('.', '-').toLowerCase(Locale.ROOT); } private Set addAdditionalServicePorts(String additionalServicePorts) { diff --git a/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java b/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java index 415fc839..84695344 100644 --- a/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java +++ b/src/main/java/org/springframework/cloud/deployer/spi/local/LocalDeployerUtils.java @@ -33,6 +33,6 @@ public class LocalDeployerUtils { protected static boolean isWindows() { String osName = System.getProperty("os.name"); - return osName != null && osName.toLowerCase().startsWith("windows"); + return osName != null && osName.toLowerCase(Locale.ROOT).startsWith("windows"); } } diff --git a/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java b/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java index afa2f8e1..cc14934a 100644 --- a/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java +++ b/src/test/java/org/springframework/cloud/deployer/spi/local/LocalAppDeployerEnvironmentIntegrationTests.java @@ -283,7 +283,7 @@ public void testActuatorOperations() { Collections.singletonMap("configuredLevel", "debug"), Object.class); loggers = actuatorOperations .getFromActuator(deploymentId, id, "/loggers/org.springframework", Map.class); - assertThat(((String)loggers.get("configuredLevel")).toLowerCase()).isEqualTo("debug"); + assertThat(((String)loggers.get("configuredLevel")).toLowerCase(Locale.ROOT)).isEqualTo("debug"); }