Merge pull request #11121 from hanyong

* gh-11121:
  Polish "Support nested jar paths in loader.path"
  Support nested jar paths in loader.path
This commit is contained in:
Andy Wilkinson 2018-02-05 16:06:20 +00:00
commit 5510b5edab
2 changed files with 20 additions and 1 deletions

View File

@ -121,6 +121,8 @@ public class PropertiesLauncher extends Launcher {
private static final Pattern WORD_SEPARATOR = Pattern.compile("\\W+");
private static final String NESTED_ARCHIVE_SEPARATOR = "!" + File.separator;
private final File home;
private List<String> paths = new ArrayList<>();
@ -452,6 +454,7 @@ public class PropertiesLauncher extends Launcher {
private List<Archive> getClassPathArchives(String path) throws Exception {
String root = cleanupPath(stripFileUrlPrefix(path));
System.out.println(root);
List<Archive> lib = new ArrayList<>();
File file = new File(root);
if (!"/".equals(root)) {
@ -483,6 +486,9 @@ public class PropertiesLauncher extends Launcher {
}
private Archive getArchive(File file) throws IOException {
if (isNestedArchivePath(file)) {
return null;
}
String name = file.getName().toLowerCase();
if (name.endsWith(".jar") || name.endsWith(".zip")) {
return new JarFileArchive(file);
@ -490,6 +496,10 @@ public class PropertiesLauncher extends Launcher {
return null;
}
private boolean isNestedArchivePath(File file) {
return file.getPath().contains(NESTED_ARCHIVE_SEPARATOR);
}
private List<Archive> getNestedArchives(String path) throws Exception {
Archive parent = this.parent;
String root = path;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -213,6 +213,15 @@ public class PropertiesLauncherTests {
assertThat(archives).areExactly(1, endingWith("app.jar!/"));
}
@Test
public void testUserSpecifiedNestedJarPath() throws Exception {
System.setProperty("loader.path", "nested-jars/app.jar!/foo.jar");
System.setProperty("loader.main", "demo.Application");
PropertiesLauncher launcher = new PropertiesLauncher();
List<Archive> archives = launcher.getClassPathArchives();
assertThat(archives).hasSize(1).areExactly(1, endingWith("foo.jar!/"));
}
@Test
public void testUserSpecifiedDirectoryContainingJarFileWithNestedArchives()
throws Exception {