mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Normalize search path in PropertiesLauncher
* Windows: allow absolute file paths without file:/// prefix * All: only add nested archives (not directories), so loader.path=lib/* behaves the same as -classpath=lib/* (except for adding zip files) Fixes gh-1352
This commit is contained in:
parent
ccfc47091c
commit
8e84151f8f
@ -456,7 +456,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
String root = cleanupPath(stripFileUrlPrefix(path));
|
||||
List<Archive> lib = new ArrayList<Archive>();
|
||||
File file = new File(root);
|
||||
if (!root.startsWith("/")) {
|
||||
if (!isAbsolutePath(root)) {
|
||||
file = new File(this.home, root);
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
@ -479,6 +479,11 @@ public class PropertiesLauncher extends Launcher {
|
||||
return lib;
|
||||
}
|
||||
|
||||
private boolean isAbsolutePath(String root) {
|
||||
// Windows contains ":" others start with "/"
|
||||
return root.contains(":") || root.startsWith("/");
|
||||
}
|
||||
|
||||
private Archive getArchive(File file) throws IOException {
|
||||
String name = file.getName().toLowerCase();
|
||||
if (name.endsWith(".jar") || name.endsWith(".zip")) {
|
||||
@ -534,6 +539,10 @@ public class PropertiesLauncher extends Launcher {
|
||||
|
||||
private String cleanupPath(String path) {
|
||||
path = path.trim();
|
||||
// No need for current dir path
|
||||
if (path.startsWith("./")) {
|
||||
path = path.substring(2);
|
||||
}
|
||||
if (path.toLowerCase().endsWith(".jar") || path.toLowerCase().endsWith(".zip")) {
|
||||
return path;
|
||||
}
|
||||
@ -542,14 +551,10 @@ public class PropertiesLauncher extends Launcher {
|
||||
}
|
||||
else {
|
||||
// It's a directory
|
||||
if (!path.endsWith("/")) {
|
||||
if (!path.endsWith("/") && !path.equals(".")) {
|
||||
path = path + "/";
|
||||
}
|
||||
}
|
||||
// No need for current dir path
|
||||
if (path.startsWith("./")) {
|
||||
path = path.substring(2);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@ -593,8 +598,7 @@ public class PropertiesLauncher extends Launcher {
|
||||
|
||||
@Override
|
||||
public boolean matches(Entry entry) {
|
||||
return entry.isDirectory() || entry.getName().endsWith(DOT_JAR)
|
||||
|| entry.getName().endsWith(DOT_ZIP);
|
||||
return entry.getName().endsWith(DOT_JAR) || entry.getName().endsWith(DOT_ZIP);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,17 @@ public class PropertiesLauncherTests {
|
||||
waitFor("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedJarPathWithDot() throws Exception {
|
||||
System.setProperty("loader.path", "./jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]", ReflectionTestUtils.getField(launcher, "paths")
|
||||
.toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedClassLoader() throws Exception {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
|
Loading…
Reference in New Issue
Block a user