Commit 8e84151f authored by Dave Syer's avatar Dave Syer

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
parent ccfc4709
...@@ -456,7 +456,7 @@ public class PropertiesLauncher extends Launcher { ...@@ -456,7 +456,7 @@ public class PropertiesLauncher extends Launcher {
String root = cleanupPath(stripFileUrlPrefix(path)); String root = cleanupPath(stripFileUrlPrefix(path));
List<Archive> lib = new ArrayList<Archive>(); List<Archive> lib = new ArrayList<Archive>();
File file = new File(root); File file = new File(root);
if (!root.startsWith("/")) { if (!isAbsolutePath(root)) {
file = new File(this.home, root); file = new File(this.home, root);
} }
if (file.isDirectory()) { if (file.isDirectory()) {
...@@ -479,6 +479,11 @@ public class PropertiesLauncher extends Launcher { ...@@ -479,6 +479,11 @@ public class PropertiesLauncher extends Launcher {
return lib; return lib;
} }
private boolean isAbsolutePath(String root) {
// Windows contains ":" others start with "/"
return root.contains(":") || root.startsWith("/");
}
private Archive getArchive(File file) throws IOException { private Archive getArchive(File file) throws IOException {
String name = file.getName().toLowerCase(); String name = file.getName().toLowerCase();
if (name.endsWith(".jar") || name.endsWith(".zip")) { if (name.endsWith(".jar") || name.endsWith(".zip")) {
...@@ -534,6 +539,10 @@ public class PropertiesLauncher extends Launcher { ...@@ -534,6 +539,10 @@ public class PropertiesLauncher extends Launcher {
private String cleanupPath(String path) { private String cleanupPath(String path) {
path = path.trim(); 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")) { if (path.toLowerCase().endsWith(".jar") || path.toLowerCase().endsWith(".zip")) {
return path; return path;
} }
...@@ -542,14 +551,10 @@ public class PropertiesLauncher extends Launcher { ...@@ -542,14 +551,10 @@ public class PropertiesLauncher extends Launcher {
} }
else { else {
// It's a directory // It's a directory
if (!path.endsWith("/")) { if (!path.endsWith("/") && !path.equals(".")) {
path = path + "/"; path = path + "/";
} }
} }
// No need for current dir path
if (path.startsWith("./")) {
path = path.substring(2);
}
return path; return path;
} }
...@@ -593,8 +598,7 @@ public class PropertiesLauncher extends Launcher { ...@@ -593,8 +598,7 @@ public class PropertiesLauncher extends Launcher {
@Override @Override
public boolean matches(Entry entry) { public boolean matches(Entry entry) {
return entry.isDirectory() || entry.getName().endsWith(DOT_JAR) return entry.getName().endsWith(DOT_JAR) || entry.getName().endsWith(DOT_ZIP);
|| entry.getName().endsWith(DOT_ZIP);
} }
} }
......
...@@ -112,6 +112,17 @@ public class PropertiesLauncherTests { ...@@ -112,6 +112,17 @@ public class PropertiesLauncherTests {
waitFor("Hello World"); 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 @Test
public void testUserSpecifiedClassLoader() throws Exception { public void testUserSpecifiedClassLoader() throws Exception {
System.setProperty("loader.path", "jars/app.jar"); System.setProperty("loader.path", "jars/app.jar");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment