Search in sources :

Example 11 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class PluginManager method extractPluginBundleFromJar.

// public void loadAllPluginsFromDirectoryOfJars(Path directory) throws
// PluginException, IOException {
// LOGGER.debug("Loading all plugins from " + directory.toString());
// if (!Files.isDirectory(directory)) {
// throw new PluginException("No directory: " + directory.toString());
// }
// for (Path file : PathUtils.list(directory)) {
// if (file.getFileName().toString().toLowerCase().endsWith(".jar")) {
// try {
// PluginBundleVersionIdentifier pluginBundleVersionIdentifier =
// PluginBundleVersionIdentifier.fromFileName(file.getFileName().toString());
// 
// loadPluginsFromJar(pluginBundleVersionIdentifier, file,
// extractPluginBundleFromJar(file),
// extractPluginBundleVersionFromJar(file));
// } catch (PluginException e) {
// LOGGER.error("", e);
// }
// }
// }
// }
public SPluginBundle extractPluginBundleFromJar(Path jarFilePath) throws PluginException {
    String filename = jarFilePath.getFileName().toString();
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
    try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
        String pomLocation = "META-INF/maven/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getGroupId() + "/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getArtifactId() + "/" + "pom.xml";
        ZipEntry pomEntry = jarFile.getEntry(pomLocation);
        if (pomEntry == null) {
            throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString() + ", " + pomLocation);
        }
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
        SPluginBundle sPluginBundle = new SPluginBundle();
        sPluginBundle.setOrganization(model.getOrganization().getName());
        sPluginBundle.setName(model.getName());
        return sPluginBundle;
    } catch (IOException e) {
        throw new PluginException(e);
    } catch (XmlPullParserException e) {
        throw new PluginException(e);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) PluginException(org.bimserver.shared.exceptions.PluginException) Model(org.apache.maven.model.Model) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 12 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class PluginManager method loadPlugins.

@SuppressWarnings({ "unchecked", "rawtypes" })
private PluginBundle loadPlugins(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, ResourceLoader resourceLoader, ClassLoader classLoader, URI location, String classLocation, PluginDescriptor pluginDescriptor, PluginSourceType pluginType, Set<org.bimserver.plugins.Dependency> dependencies, SPluginBundle sPluginBundle, SPluginBundleVersion sPluginBundleVersion) throws PluginException {
    sPluginBundle.setInstalledVersion(sPluginBundleVersion);
    PluginBundle pluginBundle = new PluginBundleImpl(pluginBundleVersionIdentifier, sPluginBundle, sPluginBundleVersion, pluginDescriptor);
    if (classLoader != null && classLoader instanceof Closeable) {
        pluginBundle.addCloseable((Closeable) classLoader);
    }
    for (AbstractPlugin pluginImplementation : pluginDescriptor.getPlugins()) {
        if (pluginImplementation instanceof JavaPlugin) {
            JavaPlugin javaPlugin = (JavaPlugin) pluginImplementation;
            String interfaceClassName = javaPlugin.getInterfaceClass().trim().replace("\n", "");
            try {
                Class interfaceClass = getClass().getClassLoader().loadClass(interfaceClassName);
                if (javaPlugin.getImplementationClass() != null) {
                    String implementationClassName = javaPlugin.getImplementationClass().trim().replace("\n", "");
                    try {
                        Class implementationClass = classLoader.loadClass(implementationClassName);
                        Plugin plugin = (Plugin) implementationClass.newInstance();
                        pluginBundle.add(loadPlugin(pluginBundle, interfaceClass, location, classLocation, plugin, classLoader, pluginType, pluginImplementation, dependencies, plugin.getClass().getName()));
                    } catch (NoClassDefFoundError e) {
                        throw new PluginException("Implementation class '" + implementationClassName + "' not found", e);
                    } catch (ClassNotFoundException e) {
                        throw new PluginException("Implementation class '" + e.getMessage() + "' not found in " + location, e);
                    } catch (InstantiationException e) {
                        throw new PluginException(e);
                    } catch (IllegalAccessException e) {
                        throw new PluginException(e);
                    }
                }
            } catch (ClassNotFoundException e) {
                throw new PluginException("Interface class '" + interfaceClassName + "' not found", e);
            } catch (Error e) {
                throw new PluginException(e);
            }
        } else if (pluginImplementation instanceof org.bimserver.plugins.WebModulePlugin) {
            org.bimserver.plugins.WebModulePlugin webModulePlugin = (org.bimserver.plugins.WebModulePlugin) pluginImplementation;
            JsonWebModule jsonWebModule = new JsonWebModule(webModulePlugin);
            pluginBundle.add(loadPlugin(pluginBundle, WebModulePlugin.class, location, classLocation, jsonWebModule, classLoader, pluginType, pluginImplementation, dependencies, webModulePlugin.getIdentifier()));
        }
    }
    pluginBundleIdentifierToPluginBundle.put(pluginBundleVersionIdentifier.getPluginBundleIdentifier(), pluginBundle);
    pluginBundleVersionIdentifierToPluginBundle.put(pluginBundleVersionIdentifier, pluginBundle);
    pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.put(pluginBundleVersionIdentifier.getPluginBundleIdentifier(), pluginBundleVersionIdentifier);
    return pluginBundle;
}
Also used : Closeable(java.io.Closeable) PluginException(org.bimserver.shared.exceptions.PluginException) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) ModelCheckerPlugin(org.bimserver.plugins.modelchecker.ModelCheckerPlugin) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) ModelComparePlugin(org.bimserver.plugins.modelcompare.ModelComparePlugin) ObjectIDMPlugin(org.bimserver.plugins.objectidms.ObjectIDMPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) MessagingStreamingSerializerPlugin(org.bimserver.plugins.serializers.MessagingStreamingSerializerPlugin) ServicePlugin(org.bimserver.plugins.services.ServicePlugin) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) RenderEnginePlugin(org.bimserver.plugins.renderengine.RenderEnginePlugin) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) QueryEnginePlugin(org.bimserver.plugins.queryengine.QueryEnginePlugin) MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) StillImageRenderPlugin(org.bimserver.plugins.stillimagerenderer.StillImageRenderPlugin) ModelMergerPlugin(org.bimserver.plugins.modelmerger.ModelMergerPlugin)

Example 13 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getPluginBundle.

public SPluginBundle getPluginBundle(String version) {
    try {
        Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(versionArtifact);
        request.setRepositories(mavenPluginRepository.getRepositories());
        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
        File pomFile = resolveArtifact.getArtifact().getFile();
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = null;
        try (FileReader fileReader = new FileReader(pomFile)) {
            model = mavenreader.read(fileReader);
        }
        SPluginBundle sPluginBundle = new SPluginBundle();
        sPluginBundle.setOrganization(model.getOrganization().getName());
        sPluginBundle.setName(model.getName());
        return sPluginBundle;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) FileNotFoundException(java.io.FileNotFoundException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 14 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class LocalMavenPluginBundle method getPluginBundle.

@Override
public SPluginBundle getPluginBundle() {
    SPluginBundle result = new SPluginBundle();
    result.setName(model.getName());
    result.setOrganization(model.getOrganization().getName());
    return result;
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle)

Aggregations

SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)14 IOException (java.io.IOException)8 PluginException (org.bimserver.shared.exceptions.PluginException)6 Model (org.apache.maven.model.Model)5 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)5 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)5 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)5 FileNotFoundException (java.io.FileNotFoundException)4 Path (java.nio.file.Path)4 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)4 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)4 UserException (org.bimserver.shared.exceptions.UserException)4 FileReader (java.io.FileReader)3 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)3 JAXBException (javax.xml.bind.JAXBException)3 PluginBundle (org.bimserver.plugins.PluginBundle)3 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)3 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)3 ObjectIDMException (org.bimserver.plugins.objectidms.ObjectIDMException)3 ArrayList (java.util.ArrayList)2