Skip to content

Commit 0a6d3f3

Browse files
committed
Polish
1 parent d5e1520 commit 0a6d3f3

File tree

4 files changed

+37
-38
lines changed

4 files changed

+37
-38
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientInstanceConfiguration.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ class HazelcastClientInstanceConfiguration {
3737
@Bean
3838
HazelcastInstance hazelcastInstance(HazelcastConnectionDetails hazelcastConnectionDetails) {
3939
ClientConfig config = hazelcastConnectionDetails.getClientConfig();
40-
if (StringUtils.hasText(config.getInstanceName())) {
41-
return HazelcastClient.getOrCreateHazelcastClient(config);
42-
}
43-
return HazelcastClient.newHazelcastClient(config);
40+
return (!StringUtils.hasText(config.getInstanceName())) ? HazelcastClient.newHazelcastClient(config)
41+
: HazelcastClient.getOrCreateHazelcastClient(config);
4442
}
4543

4644
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/PropertiesHazelcastConnectionDetails.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ private ClientConfig loadClientConfig(Resource configLocation) {
5555
try {
5656
URL configUrl = configLocation.getURL();
5757
String configFileName = configUrl.getPath().toLowerCase();
58-
if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
59-
return new YamlClientConfigBuilder(configUrl).build();
60-
}
61-
return new XmlClientConfigBuilder(configUrl).build();
58+
return (!isYaml(configFileName)) ? new XmlClientConfigBuilder(configUrl).build()
59+
: new YamlClientConfigBuilder(configUrl).build();
6260
}
6361
catch (IOException ex) {
6462
throw new UncheckedIOException("Failed to load Hazelcast config", ex);
6563
}
6664
}
6765

66+
private boolean isYaml(String configFileName) {
67+
return configFileName.endsWith(".yaml") || configFileName.endsWith(".yml");
68+
}
69+
6870
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/Binding.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,45 +65,44 @@ public String toString() {
6565
return this.value;
6666
}
6767

68+
/**
69+
* Whether the binding uses a sensitive container path.
70+
* @return whether the binding uses a sensitive container path
71+
* @since 3.4.0
72+
*/
73+
public boolean usesSensitiveContainerPath() {
74+
return SENSITIVE_CONTAINER_PATHS.contains(getContainerDestinationPath());
75+
}
76+
6877
/**
6978
* Returns the container destination path.
7079
* @return the container destination path
7180
*/
7281
String getContainerDestinationPath() {
73-
List<String> parts = split(this.value, ':', '\\');
74-
// Format is <host>:<container>:[<options>]
82+
List<String> parts = getParts();
7583
Assert.state(parts.size() >= 2, () -> "Expected 2 or more parts, but found %d".formatted(parts.size()));
7684
return parts.get(1);
7785
}
7886

79-
private List<String> split(String input, char delimiter, char notFollowedBy) {
80-
Assert.state(notFollowedBy != '\0', "notFollowedBy must not be the null terminator");
87+
private List<String> getParts() {
88+
// Format is <host>:<container>:[<options>]
8189
List<String> parts = new ArrayList<>();
82-
StringBuilder accumulator = new StringBuilder();
83-
for (int i = 0; i < input.length(); i++) {
84-
char c = input.charAt(i);
85-
char nextChar = (i + 1 < input.length()) ? input.charAt(i + 1) : '\0';
86-
if (c == delimiter && nextChar != notFollowedBy) {
87-
parts.add(accumulator.toString());
88-
accumulator.setLength(0);
90+
StringBuilder buffer = new StringBuilder();
91+
for (int i = 0; i < this.value.length(); i++) {
92+
char ch = this.value.charAt(i);
93+
char nextChar = (i + 1 < this.value.length()) ? this.value.charAt(i + 1) : '\0';
94+
if (ch == ':' && nextChar != '\\') {
95+
parts.add(buffer.toString());
96+
buffer.setLength(0);
8997
}
9098
else {
91-
accumulator.append(c);
99+
buffer.append(ch);
92100
}
93101
}
94-
parts.add(accumulator.toString());
102+
parts.add(buffer.toString());
95103
return parts;
96104
}
97105

98-
/**
99-
* Whether the binding uses a sensitive container path.
100-
* @return whether the binding uses a sensitive container path
101-
* @since 3.4.0
102-
*/
103-
public boolean usesSensitiveContainerPath() {
104-
return SENSITIVE_CONTAINER_PATHS.contains(getContainerDestinationPath());
105-
}
106-
107106
/**
108107
* Create a {@link Binding} with the specified value containing a host source,
109108
* container destination, and options.

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ void shouldFailIfBindingIsMalformed() {
107107

108108
@ParameterizedTest
109109
@CsvSource(textBlock = """
110-
/cnb, true
111-
/layers, true
112-
/workspace, true
113-
/something, false
114-
c:\\cnb, true
115-
c:\\layers, true
116-
c:\\workspace, true
117-
c:\\something, false
110+
/cnb, true
111+
/layers, true
112+
/workspace, true
113+
/something, false
114+
c:\\cnb, true
115+
c:\\layers, true
116+
c:\\workspace, true
117+
c:\\something, false
118118
""")
119119
void shouldDetectSensitiveContainerPaths(String containerPath, boolean sensitive) {
120120
Binding binding = Binding.from("/host", containerPath);

0 commit comments

Comments
 (0)