@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + descriptor.getPluginId().hashCode(); return result; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } PluginWrapper other = (PluginWrapper) obj; if (!descriptor.getPluginId().equals(other.descriptor.getPluginId())) { return false; } return true; }
/** * The plugin label is used in logging and it's a string in format {@code pluginId@pluginVersion}. */ protected String getPluginLabel(PluginDescriptor pluginDescriptor) { return pluginDescriptor.getPluginId() + "@" + pluginDescriptor.getVersion(); }
/** * Shortcut */ public String getPluginId() { return getDescriptor().getPluginId(); }
private String getDependencyVersionSupport(PluginDescriptor dependent, String dependencyId) { List<PluginDependency> dependencies = dependent.getDependencies(); for (PluginDependency dependency : dependencies) { if (dependencyId.equals(dependency.getPluginId())) { return dependency.getPluginVersionSupport(); } } throw new IllegalStateException("Cannot find a dependency with id '" + dependencyId + "' for plugin '" + dependent.getPluginId() + "'"); }
@Override public String loadPlugin(Path pluginPath) { if ((pluginPath == null) || Files.notExists(pluginPath)) { throw new IllegalArgumentException(String.format("Specified plugin %s does not exist!", pluginPath)); } log.debug("Loading plugin from '{}'", pluginPath); try { PluginWrapper pluginWrapper = loadPluginFromPath(pluginPath); // try to resolve the loaded plugin together with other possible plugins that depend on this plugin resolvePlugins(); return pluginWrapper.getDescriptor().getPluginId(); } catch (PluginException e) { log.error(e.getMessage(), e); } return null; }
@Override public Map<String, Set<String>> readPluginsStorages() { log.debug("Reading extensions storages from plugins"); Map<String, Set<String>> result = new LinkedHashMap<>(); List<PluginWrapper> plugins = pluginManager.getPlugins(); for (PluginWrapper plugin : plugins) { String pluginId = plugin.getDescriptor().getPluginId(); log.debug("Reading extensions storages for plugin '{}'", pluginId); final Set<String> bucket = new HashSet<>(); try { Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource()); if (urls.hasMoreElements()) { collectExtensions(urls, bucket); } else { log.debug("Cannot find '{}'", getExtensionsResource()); } debugExtensions(bucket); result.put(pluginId, bucket); } catch (IOException | URISyntaxException e) { log.error(e.getMessage(), e); } } return result; }
@Override public Map<String, Set<String>> readPluginsStorages() { log.debug("Reading extensions storages from plugins"); Map<String, Set<String>> result = new LinkedHashMap<>(); List<PluginWrapper> plugins = pluginManager.getPlugins(); for (PluginWrapper plugin : plugins) { String pluginId = plugin.getDescriptor().getPluginId(); log.debug("Reading extensions storage from plugin '{}'", pluginId); Set<String> bucket = new HashSet<>(); try { Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource()); if (urls.hasMoreElements()) { collectExtensions(urls, bucket); } else { log.debug("Cannot find '{}'", getExtensionsResource()); } debugExtensions(bucket); result.put(pluginId, bucket); } catch (IOException e) { log.error(e.getMessage(), e); } } return result; }
/** * Override this to change the validation criteria. * * @param descriptor the plugin descriptor to validate * @throws PluginException if validation fails */ protected void validatePluginDescriptor(PluginDescriptor descriptor) throws PluginException { if (StringUtils.isNullOrEmpty(descriptor.getPluginId())) { throw new PluginException("Field 'id' cannot be empty"); } if (descriptor.getVersion() == null) { throw new PluginException("Field 'version' cannot be empty"); } }
for (PluginDescriptor plugin : plugins) { addPlugin(plugin); pluginByIds.put(plugin.getPluginId(), plugin); String pluginId = plugin.getPluginId(); String existingVersion = plugin.getVersion();
if (isPluginDisabled(pluginDescriptor.getPluginId())) { log.info("Plugin '{}' is disabled", pluginPath); pluginWrapper.setPluginState(PluginState.DISABLED); pluginId = pluginDescriptor.getPluginId();
private void addPlugin(PluginDescriptor descriptor) { String pluginId = descriptor.getPluginId(); List<PluginDependency> dependencies = descriptor.getDependencies(); if (dependencies.isEmpty()) { dependenciesGraph.addVertex(pluginId); dependentsGraph.addVertex(pluginId); } else { boolean edgeAdded = false; for (PluginDependency dependency : dependencies) { // Don't register optional plugins in the dependency graph to avoid automatic disabling of the plugin, // if an optional dependency is missing. if (!dependency.isOptional()) { edgeAdded = true; dependenciesGraph.addEdge(pluginId, dependency.getPluginId()); dependentsGraph.addEdge(dependency.getPluginId(), pluginId); } } // Register the plugin without dependencies, if all of its dependencies are optional. if (!edgeAdded) { dependenciesGraph.addVertex(pluginId); dependentsGraph.addVertex(pluginId); } } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + descriptor.getPluginId().hashCode(); return result; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } PluginWrapper other = (PluginWrapper) obj; if (!descriptor.getPluginId().equals(other.descriptor.getPluginId())) { return false; } return true; }
/** * The plugin label is used in logging and it's a string in format {@code pluginId@pluginVersion}. */ protected String getPluginLabel(PluginDescriptor pluginDescriptor) { return pluginDescriptor.getPluginId() + "@" + pluginDescriptor.getVersion(); }
/** * Shortcut */ public String getPluginId() { return getDescriptor().getPluginId(); }
private String getDependencyVersionSupport(PluginDescriptor dependent, String dependencyId) { List<PluginDependency> dependencies = dependent.getDependencies(); for (PluginDependency dependency : dependencies) { if (dependencyId.equals(dependency.getPluginId())) { return dependency.getPluginVersionSupport(); } } throw new IllegalStateException("Cannot find a dependency with id '" + dependencyId + "' for plugin '" + dependent.getPluginId() + "'"); }
@Override public String loadPlugin(Path pluginPath) { if ((pluginPath == null) || Files.notExists(pluginPath)) { throw new IllegalArgumentException(String.format("Specified plugin %s does not exist!", pluginPath)); } log.debug("Loading plugin from '{}'", pluginPath); try { PluginWrapper pluginWrapper = loadPluginFromPath(pluginPath); // try to resolve the loaded plugin together with other possible plugins that depend on this plugin resolvePlugins(); return pluginWrapper.getDescriptor().getPluginId(); } catch (PluginException e) { log.error(e.getMessage(), e); } return null; }
/** * show the started plugins */ public void showStartedPlugins() { List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins(); for (PluginWrapper plugin : startedPlugins) { PluginDescriptor descriptor = plugin.getDescriptor(); String pluginId = plugin.getDescriptor().getPluginId(); String msg = String.format( "Extensions added by plugin id:'%s' version:'%s' %s:", pluginId, descriptor.getVersion(), descriptor.getPluginDescription()); if (debug) LOGGER.log(Level.INFO, msg); Set<String> extensionClassNames = pluginManager .getExtensionClassNames(pluginId); for (String extension : extensionClassNames) { msg = " " + extension; if (debug) LOGGER.log(Level.INFO, msg); } } }
/** * Override this to change the validation criteria. * * @param descriptor the plugin descriptor to validate * @throws PluginException if validation fails */ protected void validatePluginDescriptor(PluginDescriptor descriptor) throws PluginException { if (StringUtils.isNullOrEmpty(descriptor.getPluginId())) { throw new PluginException("Field 'id' cannot be empty"); } if (descriptor.getVersion() == null) { throw new PluginException("Field 'version' cannot be empty"); } }