public ContainerManagedPlugin getPlugin(String action) { final ModuleDescriptor moduleDescriptor = registry.get(action); if(moduleDescriptor != null) { return (ContainerManagedPlugin) moduleDescriptor.getPlugin(); } return null; }
public void registerAction(String action, ModuleDescriptor moduleDescriptor) { Assertions.notNull("action", action); Assertions.notNull("moduleDescriptor", moduleDescriptor); if(!(moduleDescriptor.getPlugin() instanceof ContainerManagedPlugin)) { throw new IllegalArgumentException("Plugin must be container managed in order to be registered: " + moduleDescriptor.getPluginKey()); } registry.putIfAbsent(action, moduleDescriptor); }
public <T> T createModule(String name, ModuleDescriptor<T> moduleDescriptor) { if (moduleDescriptor.getPlugin() instanceof ContainerManagedPlugin) { ContainerManagedPlugin containerManagedPlugin = (ContainerManagedPlugin) moduleDescriptor.getPlugin(); return containerManagedPlugin.getContainerAccessor().getBean(name); } else { throw new IllegalArgumentException("Failed to resolve '" + name + "'. You cannot use 'bean' prefix with non spring plugins"); } }
public boolean matches(final ModuleDescriptor moduleDescriptor) { Plugin plugin = moduleDescriptor.getPlugin(); if (moduleDescriptor != null) { if(AbstractWorkflowModuleDescriptor.class.isAssignableFrom(moduleDescriptor.getClass()) && !moduleDescriptor.getPluginKey().equals("com.atlassian.jira.plugin.system.workflow"))//NON-NLS { AbstractWorkflowModuleDescriptor wfModuleDescriptor = (AbstractWorkflowModuleDescriptor) moduleDescriptor; final Class<?> workflowClassInDescriptor = wfModuleDescriptor.getImplementationClass(); return (workflowClassInDescriptor != null) && workflowClassInDescriptor.getName().equals(moduleClassname); } else if(!AbstractWorkflowModuleDescriptor.class.isAssignableFrom(moduleDescriptor.getClass())) { final Class<?> moduleClassInDescriptor = moduleDescriptor.getModuleClass(); return (null != moduleClassInDescriptor && moduleClassInDescriptor.getName().equals(moduleClassname)); } } return false; } }
<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)); } }
@Override public boolean isPluginInvolved(final ModuleDescriptor moduleDescriptor) { return pluginsInvolved.contains(toInfo(notNull("moduleDescriptor", moduleDescriptor).getPlugin())); }
private Plugin getPlugin(String key) { // Detecting if it's a web resource key or plugin key. if (key.contains(":")) { ModuleDescriptor<?> moduleDescriptor = integration.getPluginAccessor().getEnabledPluginModule(key); return checkNotNull(moduleDescriptor.getPlugin()); } else { return checkNotNull(integration.getPluginAccessor().getEnabledPlugin(key)); } }
@SuppressWarnings ({ "UnusedDeclaration" }) @EventListener public void pluginModuleEnabled(final PluginModuleEnabledEvent event) { if (jiraStarted.get() && affectsI18n().test(event.getModule().getPlugin())) { clearCaches(); } }
/** * 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); }
/** * Returns the module factory for a prefix, first using registered prefixes, then any from the plugin's container. * * @param moduleReference The module reference * @param moduleDescriptor The descriptor containing the module * @return The instance, can return null */ protected ModuleFactory getModuleFactoryForPrefix(final ModuleReference moduleReference, ModuleDescriptor<?> moduleDescriptor) { ModuleFactory moduleFactory = delegateModuleFactories.get(moduleReference.prefix); if (moduleFactory == null) { Plugin plugin = moduleDescriptor.getPlugin(); if (plugin instanceof ContainerManagedPlugin) { Collection<PrefixModuleFactory> containerFactories = ((ContainerManagedPlugin) plugin).getContainerAccessor().getBeansOfType(PrefixModuleFactory.class); for (PrefixModuleFactory prefixModuleFactory : containerFactories) { if (moduleReference.prefix.equals(prefixModuleFactory.getPrefix())) { moduleFactory = prefixModuleFactory; break; } } } } return moduleFactory; }
public void init(ModuleDescriptor moduleDescriptor) throws PluginParseException { this.plugin = moduleDescriptor.getPlugin(); final RendererComponentFactoryDescriptor descriptor = (RendererComponentFactoryDescriptor) moduleDescriptor; final Map params = descriptor.getParams(); if (params == null || StringUtils.isEmpty((String) params.get(RENDERER_COMPONENT_CLASS_PARAM))) { throw new PluginParseException("The plugin with key '" + descriptor.getCompleteKey() + "' is missing the required '" + RENDERER_COMPONENT_CLASS_PARAM + "' parameter."); } else { final String rendererComponentClassName = (String) params.get(RENDERER_COMPONENT_CLASS_PARAM); try { rendererComponentClass = moduleDescriptor.getPlugin().loadClass(rendererComponentClassName, getClass()); } catch (ClassNotFoundException e) { throw new PluginParseException("Could not load renderer component with class '" + rendererComponentClassName + "' for plugin with key '" + descriptor.getCompleteKey() + "'", e); } } }
private URL getSoyResourceURL(ModuleDescriptor moduleDescriptor, ResourceDescriptor resource) { final String sourceParam = resource.getParameter("source"); if ("webContextStatic".equalsIgnoreCase(sourceParam)) { try { return servletContextFactory.getServletContext().getResource(resource.getLocation()); } catch (MalformedURLException e) { log.error("Ignoring soy resource. Could not locate soy with location: " + resource.getLocation()); return null; } } return moduleDescriptor.getPlugin().getResource(resource.getLocation()); }
public <T> T createModule(final String name, final ModuleDescriptor<T> moduleDescriptor) throws PluginParseException { final Class<T> cls = getModuleClass(name, moduleDescriptor); final Plugin plugin = moduleDescriptor.getPlugin(); if (plugin instanceof ContainerManagedPlugin) { final ContainerManagedPlugin cmPlugin = (ContainerManagedPlugin) plugin; final ContainerAccessor containerAccessor = checkNotNull(cmPlugin.getContainerAccessor(), "Plugin container accessor is null. Plugin: %s. Module name: %s.", cmPlugin, name); return containerAccessor.createBean(cls); } else if (cls != null) { return hostContainer.create(cls); } return null; }
@PluginEventListener public void onPluginModuleAvailable(final PluginModuleAvailableEvent event) { enableConfiguredPluginModule(event.getModule().getPlugin(), event.getModule(), new HashSet<>()); }
/** * A module is determined to be optional if the host application has not * indicated to the plugins system that it is required. If the call to * {@code isOptional} with the module descriptor's plugin is {@code false}, * then this method will also return {@code false}. Also if the module * descriptor is annotated with * {@link com.atlassian.plugin.descriptors.CannotDisable} then it can not be * optional. */ public boolean isOptional(final ModuleDescriptor<?> moduleDescriptor) { checkNotNull(moduleDescriptor, "moduleDescriptor"); // It is not optional if the host application has marked it as required if (!optionalAccordingToHostApplication(moduleDescriptor)) { return false; } // A module can not be optional if it is marked // by the CannotDisable annotation if (!optionalAccordingToModuleDescriptorType(moduleDescriptor)) { return false; } // A module can only be optional if its parent plugin is not declared by // the host application as required return optionalAccordingToHostApplication(moduleDescriptor.getPlugin()); }
@Override public String getStaticPluginResourceUrl(ModuleDescriptor moduleDescriptor, String resourceName, UrlMode urlMode) { String pluginVersion = Config.getPluginVersionOrInstallTime(moduleDescriptor.getPlugin(), usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins); // "{base url}/s/{build num}/{system counter}/{plugin version}/_" final String staticUrlPrefix = getStaticResourcePrefix(pluginVersion, urlMode); // "/download/resources/plugin.key:module.key/resource.name" return staticUrlPrefix + getResourceUrl(moduleDescriptor.getCompleteKey(), resourceName); }
/** * 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; } } }
/** * Much of this code is copied from * {@link com.atlassian.plugin.webresource.WebResourceUrlProvider} * method : getStaticPluginResourceUrl() * @param moduleKey the module key * @param resource the resource * @return the absolute url */ public String getResourceUrl(String moduleKey, String resource ){ ModuleDescriptor<?> module = pluginAccessor.getEnabledPluginModule(moduleKey); final PluginInformation pluginInfo = module.getPlugin().getPluginInformation(); final String pluginVersion = pluginInfo != null ? pluginInfo.getVersion() : UNKNOWN; final String baseUrl = applicationProperties.getBaseUrl(UrlMode.ABSOLUTE) + STATIC_PREFIX + webResourceIntegration.getSystemBuildNumber() + PATH_SEPARATOR + webResourceIntegration.getSystemCounter() + PATH_SEPARATOR + pluginVersion + STATIC_SUFFIX; return baseUrl + DOWNLOAD_RESOURCES_PREFIX + moduleKey + PATH_SEPARATOR + resource; }
/** * Get not declared Resource. */ public Resource getModuleResource(String completeKey, String name) { // Confluence throws error if trying to query module with not complete key (with the plugin key for example). if (!isWebResourceKey(completeKey)) { return null; } ModuleDescriptor<?> moduleDescriptor = integration.getPluginAccessor().getEnabledPluginModule(completeKey); // In case of virtual context or super batch resource there would be null returned. if (moduleDescriptor == null) { return null; } ResourceLocation resourceLocation = moduleDescriptor.getResourceLocation(DOWNLOAD_PARAM_VALUE, name); if (resourceLocation == null) { return null; } Plugin plugin = moduleDescriptor.getPlugin(); Date updatedAt = (plugin.getDateLoaded() == null) ? new Date() : plugin.getDateLoaded(); PluginResourceContainer resourceContainer = new PluginResourceContainer(new Snapshot(this), completeKey, updatedAt, getPluginVersionOrInstallTime(plugin, usePluginInstallTimeInsteadOfTheVersionForSnapshotPlugins)); return buildResource(resourceContainer, resourceLocation); }