Remove try/finally, its not necessary here
This commit is contained in:
parent
f9598030fd
commit
b93af3c27c
|
@ -378,62 +378,56 @@ public class Bootstrap {
|
||||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||||
Class<?> classLoaderClass = classLoader.getClass();
|
Class<?> classLoaderClass = classLoader.getClass();
|
||||||
Method addURL = null;
|
Method addURL = null;
|
||||||
try {
|
while (!classLoaderClass.equals(Object.class)) {
|
||||||
while (!classLoaderClass.equals(Object.class)) {
|
try {
|
||||||
|
addURL = classLoaderClass.getDeclaredMethod("addURL", URL.class);
|
||||||
|
addURL.setAccessible(true);
|
||||||
|
break;
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// no method, try the parent
|
||||||
|
classLoaderClass = classLoaderClass.getSuperclass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addURL == null) {
|
||||||
|
logger.debug("failed to find addURL method on classLoader [" + classLoader + "] to add methods");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pluginsDirectory)) {
|
||||||
|
|
||||||
|
for (Path plugin : stream) {
|
||||||
|
// We check that subdirs are directories and readable
|
||||||
|
if (!isAccessibleDirectory(plugin, logger)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addURL = classLoaderClass.getDeclaredMethod("addURL", URL.class);
|
// add the root
|
||||||
addURL.setAccessible(true);
|
addURL.invoke(classLoader, plugin.toUri().toURL());
|
||||||
break;
|
// gather files to add
|
||||||
} catch (NoSuchMethodException e) {
|
List<Path> libFiles = Lists.newArrayList();
|
||||||
// no method, try the parent
|
libFiles.addAll(Arrays.asList(files(plugin)));
|
||||||
classLoaderClass = classLoaderClass.getSuperclass();
|
Path libLocation = plugin.resolve("lib");
|
||||||
}
|
if (Files.isDirectory(libLocation)) {
|
||||||
}
|
libFiles.addAll(Arrays.asList(files(libLocation)));
|
||||||
|
|
||||||
if (addURL == null) {
|
|
||||||
logger.debug("failed to find addURL method on classLoader [" + classLoader + "] to add methods");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(pluginsDirectory)) {
|
|
||||||
|
|
||||||
for (Path plugin : stream) {
|
|
||||||
// We check that subdirs are directories and readable
|
|
||||||
if (!isAccessibleDirectory(plugin, logger)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath());
|
PathMatcher matcher = PathUtils.getDefaultFileSystem().getPathMatcher(PLUGIN_LIB_PATTERN);
|
||||||
|
|
||||||
try {
|
// if there are jars in it, add it as well
|
||||||
// add the root
|
for (Path libFile : libFiles) {
|
||||||
addURL.invoke(classLoader, plugin.toUri().toURL());
|
if (!matcher.matches(libFile)) {
|
||||||
// gather files to add
|
continue;
|
||||||
List<Path> libFiles = Lists.newArrayList();
|
|
||||||
libFiles.addAll(Arrays.asList(files(plugin)));
|
|
||||||
Path libLocation = plugin.resolve("lib");
|
|
||||||
if (Files.isDirectory(libLocation)) {
|
|
||||||
libFiles.addAll(Arrays.asList(files(libLocation)));
|
|
||||||
}
|
}
|
||||||
|
addURL.invoke(classLoader, libFile.toUri().toURL());
|
||||||
PathMatcher matcher = PathUtils.getDefaultFileSystem().getPathMatcher(PLUGIN_LIB_PATTERN);
|
|
||||||
|
|
||||||
// if there are jars in it, add it as well
|
|
||||||
for (Path libFile : libFiles) {
|
|
||||||
if (!matcher.matches(libFile)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
addURL.invoke(classLoader, libFile.toUri().toURL());
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.warn("failed to add plugin [" + plugin + "]", e);
|
|
||||||
}
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.warn("failed to add plugin [" + plugin + "]", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
if (addURL != null) {
|
|
||||||
addURL.setAccessible(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue