Skip to content

Commit 0a399e4

Browse files
committed
Merge branch '4.0.x' into 4.1.x
Closes gh-51089
2 parents bce125b + 3f48c2b commit 0a399e4

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

loader/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/PropertiesLauncher.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ public class PropertiesLauncher extends Launcher {
136136

137137
private final File homeDirectory;
138138

139-
private final List<String> paths;
140-
141139
private final Properties properties = new Properties();
142140

143141
public PropertiesLauncher() throws Exception {
@@ -148,7 +146,6 @@ public PropertiesLauncher() throws Exception {
148146
this.archive = archive;
149147
this.homeDirectory = getHomeDirectory();
150148
initializeProperties();
151-
this.paths = getPaths();
152149
this.classPathIndex = getClassPathIndex(this.archive);
153150
}
154151

@@ -292,11 +289,9 @@ private void addToSystemProperties() {
292289
}
293290
}
294291

295-
private List<String> getPaths() throws Exception {
292+
private List<String> resolvePaths() throws Exception {
296293
String path = getProperty(PATH);
297-
List<String> paths = (path != null) ? parsePathsProperty(path) : Collections.emptyList();
298-
debug.log("Nested archive paths: %s", this.paths);
299-
return paths;
294+
return (path != null) ? parsePathsProperty(path) : Collections.emptyList();
300295
}
301296

302297
private List<String> parsePathsProperty(String commaSeparatedPaths) {
@@ -470,7 +465,9 @@ private static String capitalize(String str) {
470465
@Override
471466
protected Set<URL> getClassPathUrls() throws Exception {
472467
Set<URL> urls = new LinkedHashSet<>();
473-
for (String path : getPaths()) {
468+
List<String> paths = resolvePaths();
469+
debug.log("Nested archive paths: %s", paths);
470+
for (String path : paths) {
474471
path = cleanupPath(handleUrl(path));
475472
urls.addAll(getClassPathUrlsForPath(path));
476473
}

loader/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/PropertiesLauncherTests.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void testUserSpecifiedConfigName() throws Exception {
127127
System.setProperty("loader.config.name", "foo");
128128
this.launcher = new PropertiesLauncher();
129129
assertThat(this.launcher.getMainClass()).isEqualTo("my.Application");
130-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[etc/]");
130+
assertThat(resolvedPaths()).containsExactly("etc/");
131131
}
132132

133133
@Test
@@ -141,14 +141,14 @@ void testRootOfClasspathFirst() throws Exception {
141141
void testUserSpecifiedDotPath() throws Exception {
142142
System.setProperty("loader.path", ".");
143143
this.launcher = new PropertiesLauncher();
144-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[.]");
144+
assertThat(resolvedPaths()).containsExactly(".");
145145
}
146146

147147
@Test
148148
void testUserSpecifiedSlashPath() throws Exception {
149149
System.setProperty("loader.path", "jars/");
150150
this.launcher = new PropertiesLauncher();
151-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/]");
151+
assertThat(resolvedPaths()).containsExactly("jars/");
152152
Set<URL> urls = this.launcher.getClassPathUrls();
153153
assertThat(urls).areExactly(1, endingWith("app.jar"));
154154
}
@@ -158,7 +158,7 @@ void testUserSpecifiedWildcardPath() throws Exception {
158158
System.setProperty("loader.path", "jars/*");
159159
System.setProperty("loader.main", "demo.Application");
160160
this.launcher = new PropertiesLauncher();
161-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/]");
161+
assertThat(resolvedPaths()).containsExactly("jars/");
162162
this.launcher.launch(new String[0]);
163163
waitFor("Hello World");
164164
}
@@ -168,7 +168,7 @@ void testUserSpecifiedJarPath() throws Exception {
168168
System.setProperty("loader.path", "jars/app.jar");
169169
System.setProperty("loader.main", "demo.Application");
170170
this.launcher = new PropertiesLauncher();
171-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
171+
assertThat(resolvedPaths()).containsExactly("jars/app.jar");
172172
this.launcher.launch(new String[0]);
173173
waitFor("Hello World");
174174
}
@@ -177,8 +177,7 @@ void testUserSpecifiedJarPath() throws Exception {
177177
void testUserSpecifiedRootOfJarPath() throws Exception {
178178
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/");
179179
this.launcher = new PropertiesLauncher();
180-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
181-
.hasToString("[jar:file:./src/test/resources/nested-jars/app.jar!/]");
180+
assertThat(resolvedPaths()).containsExactly("jar:file:./src/test/resources/nested-jars/app.jar!/");
182181
Set<URL> urls = this.launcher.getClassPathUrls();
183182
assertThat(urls).areExactly(1, endingWith("foo.jar!/"));
184183
assertThat(urls).areExactly(1, endingWith("app.jar!/"));
@@ -216,8 +215,7 @@ void testUserSpecifiedNestedJarPath() throws Exception {
216215
System.setProperty("loader.path", "nested-jars/nested-jar-app.jar!/BOOT-INF/classes/");
217216
System.setProperty("loader.main", "demo.Application");
218217
this.launcher = new PropertiesLauncher();
219-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
220-
.hasToString("[nested-jars/nested-jar-app.jar!/BOOT-INF/classes/]");
218+
assertThat(resolvedPaths()).containsExactly("nested-jars/nested-jar-app.jar!/BOOT-INF/classes/");
221219
this.launcher.launch(new String[0]);
222220
waitFor("Hello World");
223221
}
@@ -236,7 +234,7 @@ void testUserSpecifiedJarPathWithDot() throws Exception {
236234
System.setProperty("loader.path", "./jars/app.jar");
237235
System.setProperty("loader.main", "demo.Application");
238236
this.launcher = new PropertiesLauncher();
239-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
237+
assertThat(resolvedPaths()).containsExactly("jars/app.jar");
240238
this.launcher.launch(new String[0]);
241239
waitFor("Hello World");
242240
}
@@ -246,7 +244,7 @@ void testUserSpecifiedClassLoader() throws Exception {
246244
System.setProperty("loader.path", "jars/app.jar");
247245
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
248246
this.launcher = new PropertiesLauncher();
249-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
247+
assertThat(resolvedPaths()).containsExactly("jars/app.jar");
250248
this.launcher.launch(new String[0]);
251249
waitFor("Hello World");
252250
}
@@ -256,8 +254,7 @@ void testUserSpecifiedClassPathOrder() throws Exception {
256254
System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar");
257255
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
258256
this.launcher = new PropertiesLauncher();
259-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
260-
.hasToString("[more-jars/app.jar, jars/app.jar]");
257+
assertThat(resolvedPaths()).containsExactly("more-jars/app.jar", "jars/app.jar");
261258
this.launcher.launch(new String[0]);
262259
waitFor("Hello Other World");
263260
}
@@ -309,7 +306,7 @@ void testSystemPropertiesSet() throws Exception {
309306
void testArgsEnhanced() throws Exception {
310307
System.setProperty("loader.args", "foo");
311308
this.launcher = new PropertiesLauncher();
312-
assertThat(Arrays.asList(this.launcher.getArgs("bar"))).hasToString("[foo, bar]");
309+
assertThat(Arrays.asList(this.launcher.getArgs("bar"))).containsExactly("foo", "bar");
313310
}
314311

315312
@Test
@@ -325,8 +322,7 @@ void testLoadPathCustomizedUsingManifest() throws Exception {
325322
manifest.write(manifestStream);
326323
}
327324
this.launcher = new PropertiesLauncher();
328-
assertThat((List<String>) ReflectionTestUtils.getField(this.launcher, "paths")).containsExactly("/foo.jar",
329-
"/bar/");
325+
assertThat(resolvedPaths()).containsExactly("/foo.jar", "/bar/");
330326
}
331327

332328
@Test
@@ -447,6 +443,10 @@ private List<File> getExpectedFilesWithExtraLibs(File parent) {
447443
return expected;
448444
}
449445

446+
private List<String> resolvedPaths() {
447+
return ReflectionTestUtils.invokeMethod(this.launcher, "resolvePaths");
448+
}
449+
450450
private Condition<URL> endingWith(String value) {
451451
return new Condition<>() {
452452

0 commit comments

Comments
 (0)