Skip to content

Polish ClassPath #44355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ private String classPathArg(boolean allowArgFile) {
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();
Expand Down Expand Up @@ -121,9 +126,8 @@ static ClassPath of(List<URL> urls) {
* @return a new {@link ClassPath} instance
*/
static ClassPath of(UnaryOperator<String> getSystemProperty, List<URL> 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<String> getSystemProperty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ void argsWhenMultipleUrlsNotOnWindowsUsesPath(@TempDir Path temp) throws Excepti
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<String> onWindows() {
return Map.of("os.name", "windows")::get;
}
Expand Down