Skip to content

Commit 0e55165

Browse files
committed
Merge pull request #44355 from nosan
* pr/44355: Polish ClassPath Closes gh-44355
2 parents cfc12bf + e919fd8 commit 0e55165

File tree

2 files changed

+15
-3
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src

2 files changed

+15
-3
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ private String classPathArg(boolean allowArgFile) {
7979
return this.path;
8080
}
8181

82+
@Override
83+
public String toString() {
84+
return this.path;
85+
}
86+
8287
private Path createArgFile() throws IOException {
8388
Path argFile = Files.createTempFile("spring-boot-", ".argfile");
8489
argFile.toFile().deleteOnExit();
@@ -121,9 +126,8 @@ static ClassPath of(List<URL> urls) {
121126
* @return a new {@link ClassPath} instance
122127
*/
123128
static ClassPath of(UnaryOperator<String> getSystemProperty, List<URL> urls) {
124-
boolean preferrArgFile = urls.size() > 1 && isWindows(getSystemProperty);
125-
return new ClassPath(preferrArgFile,
126-
urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR));
129+
boolean preferArgFile = urls.size() > 1 && isWindows(getSystemProperty);
130+
return new ClassPath(preferArgFile, urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR));
127131
}
128132

129133
private static boolean isWindows(UnaryOperator<String> getSystemProperty) {

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ void argsWhenMultipleUrlsNotOnWindowsUsesPath(@TempDir Path temp) throws Excepti
8585
assertThat(classPath.args(true)).containsExactly("-cp", path1 + File.pathSeparator + path2);
8686
}
8787

88+
@Test
89+
void toStringShouldReturnClassPath(@TempDir Path temp) throws Exception {
90+
Path path1 = temp.resolve("test1.jar");
91+
Path path2 = temp.resolve("test2.jar");
92+
ClassPath classPath = ClassPath.of(onLinux(), List.of(path1.toUri().toURL(), path2.toUri().toURL()));
93+
assertThat(classPath.toString()).isEqualTo(path1 + File.pathSeparator + path2);
94+
}
95+
8896
private UnaryOperator<String> onWindows() {
8997
return Map.of("os.name", "windows")::get;
9098
}

0 commit comments

Comments
 (0)