From 2a105031671a051d6e9ecbaf303f66932d178da2 Mon Sep 17 00:00:00 2001 From: Guo Du Date: Fri, 20 Dec 2013 12:25:38 +0000 Subject: [PATCH] fixed ExplodedArchive which fail on windows * when run 'java org.springframework.boot.loader.JarLauncher' Fixes gh-176 --- .../boot/loader/archive/ExplodedArchive.java | 12 ++++-------- .../boot/loader/archive/ExplodedArchiveTests.java | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java index a1e8114bfc..f789bc2e5a 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java @@ -39,7 +39,7 @@ import org.springframework.boot.loader.AsciiBytes; /** * {@link Archive} implementation backed by an exploded archive directory. - * + * * @author Phillip Webb */ public class ExplodedArchive extends Archive { @@ -72,11 +72,7 @@ public class ExplodedArchive extends Archive { private void buildEntries(File file) { if (!file.equals(this.root)) { - String name = file.getAbsolutePath().substring( - this.root.getAbsolutePath().length() + 1); - if (file.isDirectory()) { - name += "/"; - } + String name = file.toURI().getPath().substring(root.toURI().getPath().length()); FileEntry entry = new FileEntry(new AsciiBytes(name), file); this.entries.put(entry.getName(), entry); } @@ -92,7 +88,7 @@ public class ExplodedArchive extends Archive { @Override public URL getUrl() throws MalformedURLException { FilteredURLStreamHandler handler = new FilteredURLStreamHandler(); - return new URL("file", "", -1, this.root.getAbsolutePath() + "/", handler); + return new URL("file", "", -1, this.root.toURI().getPath(), handler); } @Override @@ -181,7 +177,7 @@ public class ExplodedArchive extends Archive { @Override protected URLConnection openConnection(URL url) throws IOException { String name = url.getPath().substring( - ExplodedArchive.this.root.getAbsolutePath().length() + 1); + ExplodedArchive.this.root.toURI().getPath().length()); if (ExplodedArchive.this.entries.containsKey(new AsciiBytes(name))) { return new URL(url.toString()).openConnection(); } diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java index 694cbd662a..1edb58f278 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java @@ -122,7 +122,7 @@ public class ExplodedArchiveTests { Map nestedEntries = getEntriesMap(nested); assertThat(nestedEntries.size(), equalTo(1)); assertThat(nested.getUrl().toString(), - equalTo("file:" + this.rootFolder.getPath() + File.separator + "d/")); + equalTo("file:" + this.rootFolder.toURI().getPath() + "d/")); } @Test