From c1b34d0307babd60cb4da623ff3699cc2dcf2986 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Wed, 20 Mar 2019 01:41:07 +0800 Subject: [PATCH 1/2] Prefer file: to jar:file: URLs in launcher See gh-16248 --- .../springframework/boot/loader/archive/ExplodedArchive.java | 2 +- .../org/springframework/boot/loader/JarLauncherTests.java | 4 +--- .../springframework/boot/loader/PropertiesLauncherTests.java | 2 +- .../org/springframework/boot/loader/WarLauncherTests.java | 4 +--- .../boot/loader/archive/ExplodedArchiveTests.java | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java index 9454b1094e..7e4318a463 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java @@ -117,7 +117,7 @@ public class ExplodedArchive implements Archive { protected Archive getNestedArchive(Entry entry) throws IOException { File file = ((FileEntry) entry).getFile(); return (file.isDirectory() ? new ExplodedArchive(file) - : new JarFileArchive(file)); + : new JarFileArchive(file, file.toURI().toURL())); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java index 440d6e6343..12cb41b2b6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java @@ -44,9 +44,7 @@ public class JarLauncherTests extends AbstractExecutableArchiveLauncherTests { assertThat(archives).hasSize(2); assertThat(getUrls(archives)).containsOnly( new File(explodedRoot, "BOOT-INF/classes").toURI().toURL(), - new URL("jar:" - + new File(explodedRoot, "BOOT-INF/lib/foo.jar").toURI().toURL() - + "!/")); + new File(explodedRoot, "BOOT-INF/lib/foo.jar").toURI().toURL()); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index e29b0ae3db..a8736d4b12 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -142,7 +142,7 @@ public class PropertiesLauncherTests { assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()) .isEqualTo("[jars/]"); List archives = launcher.getClassPathArchives(); - assertThat(archives).areExactly(1, endingWith("app.jar!/")); + assertThat(archives).areExactly(1, endingWith("app.jar")); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java index 94231ab02e..77f55bf62c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java @@ -44,9 +44,7 @@ public class WarLauncherTests extends AbstractExecutableArchiveLauncherTests { assertThat(archives).hasSize(2); assertThat(getUrls(archives)).containsOnly( new File(explodedRoot, "WEB-INF/classes").toURI().toURL(), - new URL("jar:" - + new File(explodedRoot, "WEB-INF/lib/foo.jar").toURI().toURL() - + "!/")); + new File(explodedRoot, "WEB-INF/lib/foo.jar").toURI().toURL()); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java index 0e2b73ac1a..648477740a 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/ExplodedArchiveTests.java @@ -127,7 +127,7 @@ public class ExplodedArchiveTests { Entry entry = getEntriesMap(this.archive).get("nested.jar"); Archive nested = this.archive.getNestedArchive(entry); assertThat(nested.getUrl().toString()) - .isEqualTo("jar:" + this.rootFolder.toURI() + "nested.jar!/"); + .isEqualTo(this.rootFolder.toURI() + "nested.jar"); } @Test From 5639685770c0c656e3190ff8c042aadfb311da0c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 29 Apr 2019 14:38:22 +0100 Subject: [PATCH 2/2] Polish "Prefer file: to jar:file: URLs in launcher" See gh-16248 --- .../boot/loader/archive/ExplodedArchive.java | 4 ++-- .../boot/loader/archive/JarFileArchive.java | 4 ++-- .../org/springframework/boot/loader/JarLauncherTests.java | 2 +- .../boot/loader/PropertiesLauncherTests.java | 8 ++++---- .../org/springframework/boot/loader/WarLauncherTests.java | 2 +- .../boot/loader/archive/JarFileArchiveTests.java | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java index 7e4318a463..8b5b6d43be 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/ExplodedArchive.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,7 +117,7 @@ public class ExplodedArchive implements Archive { protected Archive getNestedArchive(Entry entry) throws IOException { File file = ((FileEntry) entry).getFile(); return (file.isDirectory() ? new ExplodedArchive(file) - : new JarFileArchive(file, file.toURI().toURL())); + : new JarFileArchive(file)); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java index 461969e579..fd90f9157d 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public class JarFileArchive implements Archive { private File tempUnpackFolder; public JarFileArchive(File file) throws IOException { - this(file, null); + this(file, file.toURI().toURL()); } public JarFileArchive(File file, URL url) throws IOException { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java index 12cb41b2b6..1d5ff669d5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/JarLauncherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index a8736d4b12..5f33aceed2 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -176,7 +176,7 @@ public class PropertiesLauncherTests { .isEqualTo("[jar:file:./src/test/resources/nested-jars/app.jar!/]"); List archives = launcher.getClassPathArchives(); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); - assertThat(archives).areExactly(1, endingWith("app.jar!/")); + assertThat(archives).areExactly(1, endingWith("app.jar")); } @Test @@ -185,7 +185,7 @@ public class PropertiesLauncherTests { PropertiesLauncher launcher = new PropertiesLauncher(); List archives = launcher.getClassPathArchives(); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); - assertThat(archives).areExactly(1, endingWith("app.jar!/")); + assertThat(archives).areExactly(1, endingWith("app.jar")); } @Test @@ -204,7 +204,7 @@ public class PropertiesLauncherTests { PropertiesLauncher launcher = new PropertiesLauncher(); List archives = launcher.getClassPathArchives(); assertThat(archives).areExactly(1, endingWith("foo.jar!/")); - assertThat(archives).areExactly(1, endingWith("app.jar!/")); + assertThat(archives).areExactly(1, endingWith("app.jar")); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java index 77f55bf62c..00f932b6a8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/WarLauncherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java index 669b36edba..464cf55ca8 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public class JarFileArchiveTests { @Test public void getUrl() throws Exception { URL url = this.archive.getUrl(); - assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFileUrl + "!/"); + assertThat(url.toString()).isEqualTo(this.rootJarFileUrl); } @Test