private void updatePlugins(DatabaseSession session) throws BimserverDatabaseException { Collection<Plugin> allPlugins = pluginManager.getAllPlugins(false); for (Plugin plugin : allPlugins) { Condition pluginCondition = new AttributeCondition( StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(), new StringLiteral(plugin.getClass().getName())); Map<Long, PluginDescriptor> results = session.query(pluginCondition, PluginDescriptor.class, Query.getDefault()); if (results.size() == 0) { PluginContext pluginContext = pluginManager.getPluginContext(plugin); PluginDescriptor pluginDescriptor = session.create(PluginDescriptor.class); pluginDescriptor.setPluginClassName(plugin.getClass().getName()); pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName()); pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion()); pluginDescriptor.setLocation(pluginContext.getLocation().toString()); pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName()); pluginDescriptor.setEnabled(true); // New plugins are enabled by default } else if (results.size() == 1) { PluginContext pluginContext = pluginManager.getPluginContext(plugin); PluginDescriptor pluginDescriptor = results.values().iterator().next(); pluginDescriptor.setPluginClassName(plugin.getClass().getName()); pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName()); pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion()); pluginDescriptor.setLocation(pluginContext.getLocation().toString()); pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName()); session.store(pluginDescriptor); pluginManager.getPluginContext(plugin).setEnabled(pluginDescriptor.getEnabled(), false); } else { LOGGER.error( "Multiple plugin descriptor objects found with the same name: " + plugin.getClass().getName()); } } }
@Override public void service(HttpServletRequest request, HttpServletResponse response) { try { InputStream resourceAsInputStream = pluginContext.getResourceAsInputStream(request.getPathInfo()); if (resourceAsInputStream != null) { IOUtils.copy(resourceAsInputStream, response.getOutputStream()); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }