Search in sources :

Example 1 with JarClassLoader

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);
    }
}
Also used : FakeClosingInputStream(org.bimserver.utils.FakeClosingInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) PluginException(org.bimserver.shared.exceptions.PluginException) Dependency(org.eclipse.aether.graph.Dependency) IOException(java.io.IOException) URI(java.net.URI) ObjectIDMException(org.bimserver.plugins.objectidms.ObjectIDMException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) PluginException(org.bimserver.shared.exceptions.PluginException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) FileJarClassLoader(org.bimserver.plugins.classloaders.FileJarClassLoader) JarClassLoader(org.bimserver.plugins.classloaders.JarClassLoader) FileJarClassLoader(org.bimserver.plugins.classloaders.FileJarClassLoader)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)1 JarInputStream (java.util.jar.JarInputStream)1 JAXBException (javax.xml.bind.JAXBException)1 FileJarClassLoader (org.bimserver.plugins.classloaders.FileJarClassLoader)1 JarClassLoader (org.bimserver.plugins.classloaders.JarClassLoader)1 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)1 ObjectIDMException (org.bimserver.plugins.objectidms.ObjectIDMException)1 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)1 PluginException (org.bimserver.shared.exceptions.PluginException)1 ServiceException (org.bimserver.shared.exceptions.ServiceException)1 UserException (org.bimserver.shared.exceptions.UserException)1 FakeClosingInputStream (org.bimserver.utils.FakeClosingInputStream)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)1 Dependency (org.eclipse.aether.graph.Dependency)1