use of org.bimserver.plugins.classloaders.JarClassLoader in project BIMserver by opensourceBIM.
the class PluginManager method loadPluginsFromJar.
public PluginBundle loadPluginsFromJar(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, Path file, SPluginBundle sPluginBundle, SPluginBundleVersion pluginBundleVersion, ClassLoader parentClassLoader) throws PluginException {
PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier();
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
throw new PluginException("Plugin " + pluginBundleIdentifier.getHumanReadable() + " already loaded (version " + pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion() + ")");
}
LOGGER.debug("Loading plugins from " + file.toString());
if (!Files.exists(file)) {
throw new PluginException("Not a file: " + file.toString());
}
FileJarClassLoader jarClassLoader = null;
try {
jarClassLoader = new FileJarClassLoader(this, parentClassLoader, file);
jarClassLoaders.add(jarClassLoader);
final JarClassLoader finalLoader = jarClassLoader;
InputStream pluginStream = jarClassLoader.getResourceAsStream("plugin/plugin.xml");
if (pluginStream == null) {
jarClassLoader.close();
throw new PluginException("No plugin/plugin.xml found in " + file.getFileName().toString());
}
PluginDescriptor pluginDescriptor = getPluginDescriptor(pluginStream);
if (pluginDescriptor == null) {
jarClassLoader.close();
throw new PluginException("No plugin descriptor could be created");
}
LOGGER.debug(pluginDescriptor.toString());
URI fileUri = file.toAbsolutePath().toUri();
URI jarUri = new URI("jar:" + fileUri.toString());
ResourceLoader resourceLoader = new ResourceLoader() {
@Override
public InputStream load(String name) {
return finalLoader.getResourceAsStream(name);
}
};
return loadPlugins(pluginBundleVersionIdentifier, resourceLoader, jarClassLoader, jarUri, file.toAbsolutePath().toString(), pluginDescriptor, PluginSourceType.JAR_FILE, new HashSet<org.bimserver.plugins.Dependency>(), sPluginBundle, pluginBundleVersion);
} catch (Exception e) {
if (jarClassLoader != null) {
try {
jarClassLoader.close();
} catch (IOException e1) {
LOGGER.error("", e1);
}
}
throw new PluginException(e);
}
}
Aggregations