Search in sources :

Example 26 with PluginException

use of org.bimserver.shared.exceptions.PluginException 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 27 with PluginException

use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.

the class PluginManager method getFirstDeserializer.

public DeserializerPlugin getFirstDeserializer(String extension, Schema schema, boolean onlyEnabled) throws PluginException {
    Collection<DeserializerPlugin> allDeserializerPlugins = getAllDeserializerPlugins(extension, onlyEnabled);
    Iterator<DeserializerPlugin> iterator = allDeserializerPlugins.iterator();
    while (iterator.hasNext()) {
        DeserializerPlugin next = iterator.next();
        if (!next.getSupportedSchemas().contains(schema)) {
            iterator.remove();
        }
    }
    if (allDeserializerPlugins.size() == 0) {
        throw new PluginException("No deserializers with extension " + extension + " found");
    }
    return allDeserializerPlugins.iterator().next();
}
Also used : PluginException(org.bimserver.shared.exceptions.PluginException) StreamingDeserializerPlugin(org.bimserver.plugins.deserializers.StreamingDeserializerPlugin) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin)

Example 28 with PluginException

use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.

the class PluginManager method extractPluginBundleVersionFromJar.

public SPluginBundleVersion extractPluginBundleVersionFromJar(Path jarFilePath, boolean isLocal) throws PluginException {
    String filename = jarFilePath.getFileName().toString();
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
    PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier();
    try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
        ZipEntry pomEntry = jarFile.getEntry("META-INF/maven/" + pluginBundleIdentifier.getGroupId() + "/" + pluginBundleIdentifier.getArtifactId() + "/" + "pom.xml");
        if (pomEntry == null) {
            throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString());
        }
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
        SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, isLocal);
        return sPluginBundleVersion;
    } catch (IOException e) {
        throw new PluginException(e);
    } catch (XmlPullParserException e) {
        throw new PluginException(e);
    }
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ZipEntry(java.util.zip.ZipEntry) PluginException(org.bimserver.shared.exceptions.PluginException) Model(org.apache.maven.model.Model) 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 29 with PluginException

use of org.bimserver.shared.exceptions.PluginException 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 30 with PluginException

use of org.bimserver.shared.exceptions.PluginException in project BIMserver by opensourceBIM.

the class ExtractFurniture method main.

public static void main(String[] args) {
    try {
        Path home = Paths.get("home");
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(home);
        DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
        Deserializer deserializer = deserializerPlugin.createDeserializer(null);
        MetaDataManager metaDataManager = new MetaDataManager(home.resolve("tmp"));
        PackageMetaData packageMetaData = metaDataManager.getPackageMetaData("ifc2x3tc1");
        deserializer.init(packageMetaData);
        IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/ADT-FZK-Haus-2005-2006.ifc"));
        model.fixOids(new IncrementingOidProvider());
        IfcFurnishingElement picknick = (IfcFurnishingElement) model.getByName(Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank");
        IfcModelInterface newModel = new BasicIfcModel(packageMetaData, null);
        ModelHelper modelHelper = new ModelHelper(pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM(CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")), newModel);
        modelHelper.copy(picknick, false);
        SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
        Serializer serializer = serializerPlugin.createSerializer(null);
        serializer.init(newModel, null, true);
        SerializerUtils.writeToFile(serializer, Paths.get("test.ifc"));
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DeserializeException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    } catch (SerializerException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) FileNotFoundException(java.io.FileNotFoundException) MetaDataManager(org.bimserver.emf.MetaDataManager) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) SerializerException(org.bimserver.plugins.serializers.SerializerException) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) Deserializer(org.bimserver.plugins.deserializers.Deserializer) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) Serializer(org.bimserver.plugins.serializers.Serializer)

Aggregations

PluginException (org.bimserver.shared.exceptions.PluginException)38 IOException (java.io.IOException)26 Path (java.nio.file.Path)19 ServiceException (org.bimserver.shared.exceptions.ServiceException)12 FileNotFoundException (java.io.FileNotFoundException)11 PluginManager (org.bimserver.plugins.PluginManager)10 DeserializerPlugin (org.bimserver.plugins.deserializers.DeserializerPlugin)10 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)9 UserException (org.bimserver.shared.exceptions.UserException)9 IfcModelInterface (org.bimserver.emf.IfcModelInterface)8 ChannelConnectionException (org.bimserver.shared.ChannelConnectionException)8 DatabaseRestartRequiredException (org.bimserver.database.DatabaseRestartRequiredException)7 DatabaseInitException (org.bimserver.database.berkeley.DatabaseInitException)7 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)7 Model (org.apache.maven.model.Model)6 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)6 MetaDataManager (org.bimserver.emf.MetaDataManager)6 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)6 SPluginInformation (org.bimserver.interfaces.objects.SPluginInformation)6 ServerException (org.bimserver.shared.exceptions.ServerException)6