Commit f0f73a4e authored by Dave Syer's avatar Dave Syer

Current directory (lodaer.path=.) pathology workaround

It turns out that loader.path=. was pathological and before this
change ended up making the classpath empty (loader.path=.,lib/
would have fixed it). With this change the old behaviour is still
supported, but if the only user-supplied path entry is "." (or
empty) then it is now kept, and translates into the root of the
current archive if running as "java -jar ...".

Fixes gh-270
parent 083cb388
......@@ -64,7 +64,7 @@ public class JarCommandIT {
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
"jar.groovy");
invocation.await();
assertEquals(0, invocation.getErrorOutput().length());
assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
assertTrue(jar.exists());
Process process = new JavaExecutable().processBuilder("-jar",
......
......@@ -310,12 +310,18 @@ public class PropertiesLauncher extends Launcher {
List<String> paths = new ArrayList<String>();
for (String path : commaSeparatedPaths.split(",")) {
path = cleanupPath(path);
// Empty path is always on the classpath so no need for it to be explicitly
// listed here
// Empty path (i.e. the archive itself if running from a JAR) is always added
// to the classpath so no need for it to be explicitly listed
if (!(path.equals(".") || path.equals(""))) {
paths.add(path);
}
}
if (paths.isEmpty()) {
// On the other hand, we don't want a completely empty path. If the app is
// running from an archive (java -jar) then this will make sure the archive
// itself is included at the very least.
paths.add(".");
}
return paths;
}
......@@ -453,12 +459,12 @@ public class PropertiesLauncher extends Launcher {
}
if (file.isDirectory()) {
this.logger.info("Adding classpath entries from " + file);
Archive archive = new ExplodedArchive(file);
Archive archive = new ExplodedArchive(file, false);
lib.add(archive);
}
Archive archive = getArchive(file);
if (archive != null) {
this.logger.info("Adding classpath entries from nested " + archive.getUrl()
this.logger.info("Adding classpath entries from archive " + archive.getUrl()
+ root);
lib.add(archive);
}
......
......@@ -85,9 +85,9 @@ public class ExplodedArchive extends Archive {
this.entries.put(entry.getName(), entry);
}
if (file.isDirectory()) {
if (this.recursive) {
for (File child : file.listFiles()) {
if (!SKIPPED_NAMES.contains(child.getName())) {
for (File child : file.listFiles()) {
if (!SKIPPED_NAMES.contains(child.getName())) {
if (file.equals(this.root) || this.recursive) {
buildEntries(child);
}
}
......
......@@ -83,7 +83,14 @@ public class PropertiesLauncherTests {
}
@Test
public void testUserSpecifiedPath() throws Exception {
public void testUserSpecifiedDotPath() throws Exception {
System.setProperty("loader.path", ".");
PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[.]", ReflectionTestUtils.getField(launcher, "paths").toString());
}
@Test
public void testUserSpecifiedWildcardPath() throws Exception {
System.setProperty("loader.path", "jars/*");
System.setProperty("loader.main", "demo.Application");
PropertiesLauncher launcher = new PropertiesLauncher();
......
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