From e919fd806f1d73482e788df4c479103bd2626a4b Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Wed, 19 Feb 2025 12:38:10 +0200 Subject: [PATCH] Polish ClassPath See gh-44355 Signed-off-by: Dmytro Nosan --- .../java/org/springframework/boot/maven/ClassPath.java | 10 +++++++--- .../org/springframework/boot/maven/ClassPathTests.java | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java index 7c4fe76ffec..52908db7137 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java @@ -79,6 +79,11 @@ final class ClassPath { return this.path; } + @Override + public String toString() { + return this.path; + } + private Path createArgFile() throws IOException { Path argFile = Files.createTempFile("spring-boot-", ".argfile"); argFile.toFile().deleteOnExit(); @@ -121,9 +126,8 @@ final class ClassPath { * @return a new {@link ClassPath} instance */ static ClassPath of(UnaryOperator getSystemProperty, List urls) { - boolean preferrArgFile = urls.size() > 1 && isWindows(getSystemProperty); - return new ClassPath(preferrArgFile, - urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR)); + boolean preferArgFile = urls.size() > 1 && isWindows(getSystemProperty); + return new ClassPath(preferArgFile, urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR)); } private static boolean isWindows(UnaryOperator getSystemProperty) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java index b06c06ea4b0..317c9d79fe2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java @@ -85,6 +85,14 @@ class ClassPathTests { assertThat(classPath.args(true)).containsExactly("-cp", path1 + File.pathSeparator + path2); } + @Test + void toStringShouldReturnClassPath(@TempDir Path temp) throws Exception { + Path path1 = temp.resolve("test1.jar"); + Path path2 = temp.resolve("test2.jar"); + ClassPath classPath = ClassPath.of(onLinux(), List.of(path1.toUri().toURL(), path2.toUri().toURL())); + assertThat(classPath.toString()).isEqualTo(path1 + File.pathSeparator + path2); + } + private UnaryOperator onWindows() { return Map.of("os.name", "windows")::get; }