@Override public void addModuleDescriptor(final ModuleDescriptor<?> moduleDescriptor) { descriptors.put(moduleDescriptor.getKey(), moduleDescriptor); }
public void addModuleDescriptor(final ModuleDescriptor<?> moduleDescriptor) { modules.put(moduleDescriptor.getKey(), moduleDescriptor); }
@Override public boolean removeDynamicModuleDescriptor(final ModuleDescriptor<?> module) { removeModuleDescriptor(module.getKey()); return dynamicModules.remove(module); }
private boolean isDisabled(ModuleDescriptor descriptor, RefChangeContext context) { return Boolean.valueOf(context.getConfiguration().getProperty(descriptor.getKey() + ".disabled", "false")); }
/** * Passes module descriptor elements back to the {@link OsgiPlugin} */ private void passModuleDescriptorToPlugin(final Plugin plugin, final Element element, final ModuleDescriptor<?> descriptor) { if (plugin instanceof OsgiPlugin) { final String key; if (descriptor == null) { key = element.attributeValue("key"); } else { key = descriptor.getKey(); } ((OsgiPlugin) plugin).addModuleDescriptorElement(key, element); } } }
/** * Gets a list of all the module keys in a plugin that require restart. Looks for the annotation * {@link RequiresRestart} on the plugin's module descriptors. * * @param plugin The plugin * @return A unique set of module keys * @since 2.5.0 */ public static Set<String> getPluginModulesThatRequireRestart(final Plugin plugin) { final Set<String> keys = new HashSet<>(); for (final ModuleDescriptor<?> descriptor : plugin.getModuleDescriptors()) { if (descriptor.getClass().getAnnotation(RequiresRestart.class) != null) { keys.add(descriptor.getKey()); } } return keys; }
/** * Registers descriptors. * * @param descriptors the module descriptors of the plugin * @return a representation of the descriptor registration */ public Registration registerDescriptors(Iterable<ModuleDescriptor<?>> descriptors) { final List<ServiceRegistration> registrations = newArrayList(); for (ModuleDescriptor<?> descriptor : descriptors) { ModuleDescriptor<?> existingDescriptor = descriptor.getPlugin().getModuleDescriptor(descriptor.getKey()); if (existingDescriptor != null) { log.error("Duplicate key '" + descriptor.getKey() + "' detected, disabling previous instance"); ((StateAware) existingDescriptor).disabled(); } log.debug("Registering descriptor {}", descriptor.getClass().getName()); registrations.add(bundleContext.registerService(ModuleDescriptor.class.getName(), descriptor, null)); } return new Registration(registrations); }
public List<String> listLocalization() { Plugin plugin = pluginAccessor.getPlugin(Constants.PLUGIN_KEY); Collection<ModuleDescriptor<?>> descriptors = plugin.getModuleDescriptors(); List<String> result = new ArrayList<>(); for (ModuleDescriptor<?> descriptor : descriptors) { if (descriptor.getKey().startsWith(LOCALIZATION_DESCRIPTOR_PREFIX)) { String webResourceId = descriptor.getCompleteKey(); if (StringUtils.isNotEmpty(webResourceId)) { String languageKey = webResourceId.substring(webResourceId.length() - 2, webResourceId.length()); result.add(languageKey.toLowerCase()); } } } return result; }
public void removedService(final ServiceReference serviceReference, final Object o) { if (serviceReference.getBundle() == bundle) { final ModuleDescriptor<?> descriptor = (ModuleDescriptor<?>) o; pluginEventManager.broadcast(new PluginModuleUnavailableEvent(descriptor)); plugin.clearModuleDescriptor(descriptor.getKey()); if (log.isInfoEnabled()) { log.info("Dynamically removed module descriptor: " + descriptor.getCompleteKey()); } } } }
public static boolean isPureSpeakeasyExtension(BundleContext bundleContext, Plugin plugin) { Bundle bundle = findBundleForPlugin(bundleContext, plugin.getKey()); // verify only speakeasy modules with known exceptions String stateIdentifier = String.valueOf(bundle.getLastModified()); for (ModuleDescriptor descriptor : plugin.getModuleDescriptors()) { if (!(descriptor instanceof DescriptorGenerator) // FIXME: these checks are hacks && !descriptor.getKey().endsWith(stateIdentifier) && !descriptor.getKey().endsWith("-modules") && !(descriptor instanceof UnloadableModuleDescriptor) && !"screenshot".equals(descriptor.getKey())) { return false; } } // ensure the plugin doesn't have any invalid characters that will screw up later operations like forking return isValidExtensionKey(plugin.getKey()); }
private <R> Optional<R> selectAndProcessForKey( final String completeModuleKey, final Function<Predicate<ModuleDescriptor>, List<R>> process ) { final ModuleCompleteKey moduleCompleteKey = new ModuleCompleteKey(completeModuleKey); if (!pluginRetrievalService.getPlugin().getKey().equals(moduleCompleteKey.getPluginKey())) { // The module isn't a connect module, so it can't be from an Addon, as they're all registered to this plugin return Optional.empty(); } else { final String justModuleKey = moduleCompleteKey.getModuleKey(); final List<R> selectedModules = process.apply( moduleDescriptor -> justModuleKey.equals(moduleDescriptor.getKey())); final int size = selectedModules.size(); if (0 == size) { return Optional.empty(); } else if (1 == size) { return Optional.of(selectedModules.get(0)); } else { // It's not worth trying to get more information here - if connect has two modules with the same key, // we're pretty far off the map and it's not clear what extra information would help. log.warn("Ambiguous query, multiple module descriptors for complete key '{}'", completeModuleKey); return Optional.empty(); } } }
/** * {@inheritDoc} */ public ThemeDefinition[] listBuiltinThemes() { Plugin plugin = pluginAccessor.getPlugin(Constants.PLUGIN_KEY); Collection<ModuleDescriptor<?>> descriptors = plugin.getModuleDescriptors(); List<ThemeDefinition> result = new ArrayList<>(); for (ModuleDescriptor<?> descriptor : descriptors) { if (descriptor.getKey().startsWith(THEME_DESCRIPTOR_PREFIX)) { List<ResourceDescriptor> resources = descriptor.getResourceDescriptors(); ResourceDescriptor first = resources.get(0); String location = first.getLocation(); String webResourceId = descriptor.getCompleteKey(); // Get panel look and feel Map<String, String> panelLookAndFeel = new HashMap<>(); for (Map.Entry<String, String> param : descriptor.getParams().entrySet()) { if (param.getKey().startsWith(LAYOUT_PREFIX)) { panelLookAndFeel.put(param.getKey(), param.getValue()); } } result.add(new ThemeDefinition(location, webResourceId, panelLookAndFeel)); } } return result.toArray(new ThemeDefinition[result.size()]); }
protected void notifyModuleEnabled(final ModuleDescriptor<?> module) { log.debug("Enabling {}", module.getKey()); broadcastIgnoreError(new PluginModuleEnablingEvent(module)); if (module instanceof StateAware) { ((StateAware) module).enabled(); } broadcastIgnoreError(new PluginModuleEnabledEvent(module)); }
private void publishModuleDisabledEvents(final ModuleDescriptor<?> module, final boolean persistent) { log.debug("Disabling {}", module.getKey()); broadcastIgnoreError(new PluginModuleDisablingEvent(module, persistent)); if (module instanceof StateAware) { ((StateAware) module).disabled(); } broadcastIgnoreError(new PluginModuleDisabledEvent(module, persistent)); }
@Override public ModuleDescriptor<?> addDynamicModule(final Plugin maybePluginInternal, final Element module) { final PluginInternal plugin = checkPluginInternal(maybePluginInternal); // identify the loader that loaded this plugin final PluginLoader pluginLoader = installedPluginsToPluginLoader.get(plugin); if (pluginLoader == null) { throw new PluginException("cannot locate PluginLoader that created plugin '" + plugin + "'"); } // attempt to create the module final ModuleDescriptor moduleDescriptor = pluginLoader.createModule(plugin, module, moduleDescriptorFactory); if (moduleDescriptor == null) { throw new PluginException("cannot add dynamic module of type '" + module.getName() + "' to plugin '" + plugin + "' as the PluginLoader does not know how to create the module"); } // check for duplicate module keys within the plugin; this is a safety-check as it should have been verified during module init if (plugin.getModuleDescriptor(moduleDescriptor.getKey()) != null) { throw new PluginException("duplicate module key '" + moduleDescriptor.getKey() + "' for plugin '" + plugin + "'"); } // add to the plugin if (!plugin.addDynamicModuleDescriptor(moduleDescriptor)) { throw new PluginException("cannot add dynamic module '" + moduleDescriptor.getKey() + "' to plugin '" + plugin + "' as it is already present"); } // enable the module only if the plugin is enabled and the module wasn't explicitly disabled by the user if (plugin.getPluginState() == PluginState.ENABLED && getState().isEnabled(moduleDescriptor)) { notifyModuleEnabled(moduleDescriptor); } return moduleDescriptor; }
<T> Class<T> getModuleClass(final String name, final ModuleDescriptor moduleDescriptor) throws ModuleClassNotFoundException { try { return moduleDescriptor.getPlugin().loadClass(name, null); } catch (ClassNotFoundException e) { throw new ModuleClassNotFoundException(name, moduleDescriptor.getPluginKey(), moduleDescriptor.getKey(), e, createErrorMsg(name)); } }
static PluginModule getModule(PluginAccessor pluginAccessor, ModuleDescriptor moduleDescriptor) { final PluginModule module = new PluginModule(); module.key = moduleDescriptor.getKey(); module.name = moduleDescriptor.getName(); module.description = moduleDescriptor.getDescription(); module.enabled = pluginAccessor.isPluginModuleEnabled(moduleDescriptor.getCompleteKey()); return module; } }
@Override public void removeDynamicModule(final Plugin maybePluginInternal, final ModuleDescriptor<?> module) { final PluginInternal plugin = checkPluginInternal(maybePluginInternal); // remove from the plugin if (!plugin.removeDynamicModuleDescriptor(module)) { throw new PluginException("cannot remove dynamic module '" + module.getKey() + "' from plugin '" + plugin + "' as it wasn't added by addDynamicModule"); } // disable it persistentStateModifier.disable(module); notifyModuleDisabled(module); // destroy it module.destroy(); }
/** * Reverts any current module descriptors that were provided from the factory being removed into {@link * UnrecognisedModuleDescriptor} instances. */ public void removedService(final ServiceReference serviceReference, final Object o) { final ListableModuleDescriptorFactory factory = (ListableModuleDescriptorFactory) o; for (final Class<? extends ModuleDescriptor> moduleDescriptorClass : factory.getModuleDescriptorClasses()) { for (final ModuleDescriptor<?> descriptor : getModuleDescriptorsByDescriptorClass(moduleDescriptorClass)) { if (plugin.getPluginState() == PluginState.ENABLED) { pluginEventManager.broadcast(new PluginModuleUnavailableEvent(descriptor)); log.info("Removed plugin module {} as its factory was uninstalled", descriptor.getCompleteKey()); } plugin.clearModuleDescriptor(descriptor.getKey()); if (plugin.isFrameworkShuttingDown()) { continue; } final UnrecognisedModuleDescriptor unrecognisedModuleDescriptor = new UnrecognisedModuleDescriptor(); final Element source = plugin.getModuleElements().get(descriptor.getKey()); if (source != null) { unrecognisedModuleDescriptor.init(plugin, source); unrecognisedModuleDescriptor.setErrorText(UnrecognisedModuleDescriptorFallbackFactory.DESCRIPTOR_TEXT); plugin.addModuleDescriptor(unrecognisedModuleDescriptor); if (plugin.getPluginState() == PluginState.ENABLED) { pluginEventManager.broadcast(new PluginModuleAvailableEvent(unrecognisedModuleDescriptor)); } } } } }
/** * Creates a new UnloadableModuleDescriptor based on an existing ModuleDescriptor, descriptor * * This method uses the information in an existing descriptor to construct a new UnloadableModuleDescriptor. * * @param plugin the Plugin the ModuleDescriptor belongs to * @param descriptor the ModuleDescriptor that reported an error * @param e the Throwable * @return a new UnloadableModuleDescriptor instance */ public static UnloadableModuleDescriptor createUnloadableModuleDescriptor(final Plugin plugin, final ModuleDescriptor<?> descriptor, final Throwable e) { final UnloadableModuleDescriptor unloadableDescriptor = new UnloadableModuleDescriptor(); unloadableDescriptor.setName(descriptor.getName()); unloadableDescriptor.setKey(descriptor.getKey()); unloadableDescriptor.setPlugin(plugin); final String errorMsg = constructErrorMessage(plugin, descriptor.getDisplayName(), (descriptor.getModuleClass() == null ? descriptor.getName() : descriptor.getModuleClass().getName()), e); unloadableDescriptor.setErrorText(errorMsg); return unloadableDescriptor; }