Refine search
/** * Safely extracts the module instance from the given module descriptor. This method will disable any plugin it * can't successfully extract the module instance from. * * @since 5.0.0 */ <M> M getModule(ModuleDescriptor<M> descriptor) { if (descriptor == null || descriptor.isBroken()) { return null; } try { return descriptor.getModule(); } catch (final RuntimeException ex) { final String pluginKey = descriptor.getPlugin().getKey(); log.error("Exception when retrieving plugin module {}, disabling plugin {}", descriptor.getCompleteKey(), pluginKey, ex); descriptor.setBroken(); // Don't persist: don't want to create a snowflake config in Cloud instance, // and the module might work following restart if something has changed. pluginController.disablePluginWithoutPersisting(pluginKey); return null; } } }
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 Collection<ResourceDescriptor> getResourceBundleLocations(final Plugin plugin) { final List<ResourceDescriptor> locations = Lists.newArrayList(); Iterables.addAll(locations, Iterables.filter(plugin.getResourceDescriptors(), filter)); for (final ModuleDescriptor<?> moduleDescriptor : plugin.getModuleDescriptors()) { try { Iterables.addAll(locations, Iterables.filter(moduleDescriptor.getResourceDescriptors(), filter)); } catch (final RuntimeException re) { if (log.isDebugEnabled()) { log.debug(format("FAILED plugin module resource descriptors: pluginKey: %s; moduleKey: %s; mode: %s", plugin.getKey(), moduleDescriptor.getCompleteKey(), getModeString()), re); } } } return locations; }
private static <M> Optional<M> getModuleSafely(final ModuleDescriptor<M> moduleDescriptor) { try { // If getModule returns null, this is an error, and Optional.of will NullPointerException in this case, // which will be caught below, get logged, and an Optional.empty returned. return Optional.of(moduleDescriptor.getModule()); } catch (final RuntimeException runtime) { log.error("Failed to getModule() for '{}': {}", moduleDescriptor.getCompleteKey(), runtime.getMessage(), runtime); return Optional.empty(); } }
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; } }
<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)); } }
final UnloadablePlugin newPlugin = new UnloadablePlugin(); newPlugin.setName(oldPlugin.getName()); newPlugin.setKey(oldPlugin.getKey()); newPlugin.setI18nNameKey(oldPlugin.getI18nNameKey()); newPlugin.setUninstallable(oldPlugin.isUninstallable()); newPlugin.setDeletable(oldPlugin.isDeleteable()); if ((unloadableDescriptor != null) && descriptor.getKey().equals(unloadableDescriptor.getKey())) { continue;
for (Iterator j = plugin.getResourceDescriptors("i18n").iterator(); j.hasNext();) for (Iterator iterator = plugin.getModuleDescriptors().iterator(); iterator.hasNext();) for (Iterator iterator1 = moduleDescriptor.getResourceDescriptors("i18n").iterator(); iterator1 .hasNext();) log.error("Unable to load i18n resources for: " + plugin.getName() + "(" + plugin.getKey() + ") " + e.toString(), e);
public Plugin configurePlugin(final ModuleDescriptorFactory moduleDescriptorFactory, final Plugin plugin) throws PluginParseException { plugin.setName(descriptorReader.getPluginName()); plugin.setKey(getKey()); plugin.setPluginsVersion(getPluginsVersion()); plugin.setSystemPlugin(isSystemPlugin()); plugin.setI18nNameKey(descriptorReader.getI18nPluginNameKey().orElseGet(plugin::getI18nNameKey)); if (plugin.getKey().indexOf(":") > 0) { throw new PluginParseException("Plugin keys cannot contain ':'. Key is '" + plugin.getKey() + "'"); } plugin.setEnabledByDefault(descriptorReader.isEnabledByDefault()); plugin.setResources(descriptorReader.getResources()); plugin.setPluginInformation(createPluginInformation()); for (Element module : descriptorReader.getModules(plugin.getInstallationMode())) { final ModuleDescriptor<?> moduleDescriptor = createModuleDescriptor(plugin, module, moduleDescriptorFactory); // If we're not loading the module descriptor, null is returned, so we skip it if (moduleDescriptor == null) { continue; } if (plugin.getModuleDescriptor(moduleDescriptor.getKey()) != null) { throw new PluginParseException("Found duplicate key '" + moduleDescriptor.getKey() + "' within plugin '" + plugin.getKey() + "'"); } plugin.addModuleDescriptor(moduleDescriptor); // If we have any unloadable modules, also create an unloadable plugin, which will make it clear that there was a problem if (moduleDescriptor instanceof UnloadableModuleDescriptor) { log.error("There were errors loading the plugin '" + plugin.getName() + "'. The plugin has been disabled."); return UnloadablePluginFactory.createUnloadablePlugin(plugin); } } return plugin; }
public void removeState(final Plugin plugin) { apply(builder -> { builder.removeState(plugin.getKey()); for (final ModuleDescriptor<?> moduleDescriptor : plugin.getModuleDescriptors()) { builder.removeState(moduleDescriptor.getCompleteKey()); } }); } }
ModuleDescriptor<?> moduleDescriptor = otherPlugin.getModuleDescriptor(module.getResourceKey()); if (!(moduleDescriptor instanceof WebResourceModuleDescriptor)) { log.error("Failed to register new code macro language " + List<ResourceDescriptor> resourceDescriptors = moduleDescriptor.getResourceDescriptors(); if (resourceDescriptors.size() == 0) { log.error("Failed to register new code macro language " + descriptor.getCompleteKey() + " because its related web-resource module " + moduleDescriptor.getCompleteKey() + " had no declared resources."); return descriptor; } else if (resourceDescriptors.size() > 1) { log.warn("More than one declared resource found in web-resource module " + moduleDescriptor.getCompleteKey() + " a single resource will be selected " + "non-deterministically."); return descriptor; ClassLoader classLoader = otherPlugin.getClassLoader(); InputStream brushFile = null; try { language = languageParser.parseRegisteredLanguage(reader, module.getFriendlyName()); language.setWebResource(moduleDescriptor.getCompleteKey()); } catch (InvalidLanguageException e) { log.error("Language file from plugin " + otherPlugin.getKey() +
@Override public void contribute(final ImmutableMap.Builder<String, Object> builder, final String name, final Object value) { if (value instanceof Plugin) builder.put(name + ".key", ((Plugin) value).getKey()); if (value instanceof ModuleDescriptor) builder.put(name + ".key", ((ModuleDescriptor<?>) value).getCompleteKey()); } }
@Override public int compare(ModuleDescriptor o1, ModuleDescriptor o2) { return o1.getCompleteKey().compareTo(o2.getCompleteKey()); } }
@Override public Optional<ConnectIFrame> fetchConnectIFrame(String addonKey, String moduleKey, Optional<String> optionalClassifier) { if (moduleKey.startsWith(addonKey + ModuleKeyUtils.ADDON_MODULE_SEPARATOR)) { log.info("ACDEV-2694: connect iframe requested for module " + addonKey + ":" + moduleKey); } ModuleDescriptor moduleDescriptor = pluginAccessor.getEnabledPluginModule( new ModuleCompleteKey(pluginRetrievalService.getPlugin().getKey(), ConnectIFrameModuleDescriptor.getModuleKey(addonKey, moduleKey, optionalClassifier)).getCompleteKey()); if (moduleDescriptor != null) { return Optional.of((ConnectIFrame)moduleDescriptor.getModule()); } return Optional.empty(); } }
} catch (NoClassDefFoundError error) { log.error("Detected an error (NoClassDefFoundError) instantiating the module for plugin '" + moduleDescriptor.getPlugin().getKey() + "'" + " for module '" + moduleDescriptor.getKey() + "': " + error.getMessage() + ". This error is usually caused by your" + " plugin using a imported component class that itself relies on other packages in the product. You can probably fix this by" + " adding the missing class's package to your <Import-Package> instructions; for more details on how to fix this, see https://developer.atlassian.com/display/DOCS/NoClassDefFoundError ."); throw error; } catch (LinkageError error) { log.error("Detected an error (LinkageError) instantiating the module for plugin '" + moduleDescriptor.getPlugin().getKey() + "'" + " for module '" + moduleDescriptor.getKey() + "': " + error.getMessage() + ". This error is usually caused by your" + " plugin including copies of libraries in META-INF/lib unnecessarily. For more details on how to fix this, see" + " https://developer.atlassian.com/x/EgAN ."); throw error; } catch (RuntimeException ex) {
/** * {@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()]); }
public boolean isFinished() { for (ModuleDescriptor desc : plugin.getModuleDescriptors()) { if (!pluginAccessor.isPluginModuleEnabled(desc.getCompleteKey()) && desc instanceof UnrecognisedModuleDescriptor) { return false; } } return true; }
@Override public Map<Plugin, Set<String>> getRequiredPlugins(JiraWorkflow workflow) { Map<Plugin, Set<String>> pluginExtensionMap = new HashMap<Plugin, Set<String>>(); Set<String> extensionClassnames = getExtensionClassnames(workflow); for (String classname : extensionClassnames) { Collection<ModuleDescriptor> moduleDescriptors = moduleDescriptorLocator.getEnabledModuleDescriptorsByModuleClassname(classname); for (ModuleDescriptor moduleDescriptor : moduleDescriptors) { Plugin plugin = moduleDescriptor.getPlugin(); //make sure we ignore old v1 SYSTEM plugins (may not have the system flag set) if(plugin.getKey().startsWith("com.atlassian.jira.plugin.system"))//NON-NLS { continue; } if (!pluginExtensionMap.containsKey(plugin)) { pluginExtensionMap.put(plugin, new HashSet<String>()); } pluginExtensionMap.get(plugin).add(classname); } } return pluginExtensionMap; }
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(); } } }
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; }