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()); } } }
private Class<?> getPluginInterfaceClass(Plugin plugin) { for (Class<?> pluginInterface : plugin.getClass().getInterfaces()) { if (pluginInterface != Plugin.class && Plugin.class.isAssignableFrom(pluginInterface)) { return pluginInterface; } } if (plugin.getClass().getSuperclass() != Object.class) { for (Class<?> pluginInterface : plugin.getClass().getSuperclass().getInterfaces()) { if (pluginInterface != Plugin.class && Plugin.class.isAssignableFrom(pluginInterface)) { return pluginInterface; } } if (plugin.getClass().getSuperclass().getSuperclass() != Object.class) { for (Class<?> pluginInterface : plugin.getClass().getSuperclass().getSuperclass().getInterfaces()) { if (pluginInterface != Plugin.class && Plugin.class.isAssignableFrom(pluginInterface)) { return pluginInterface; } } } return plugin.getClass().getSuperclass(); } return plugin.getClass(); }