@Override public RegistrationStrategy<E> get() { throw new PluginException("Class " + getModuleClassName() + " is not implementing extractor for comment, issue or change history"); } }, new Function<Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>>, RegistrationStrategy<E>>()
@DELETE @Produces({APPLICATION_XML, APPLICATION_JSON}) public Response uninstallPlugin() { try { pluginController.uninstall(plugin); return Status.ok() .plugin(RpmPlugin.KEY, RpmPlugin.VERSION) .message("Plugin " + plugin.getKey() + " has been uninstalled") .response(); } catch (PluginException e) { return Status.forbidden() .plugin(RpmPlugin.KEY, RpmPlugin.VERSION) .message(e.getMessage()) .response(); } }
@Override public ModuleDescriptor<?> createModule(final Plugin plugin, final Element module, final ModuleDescriptorFactory moduleDescriptorFactory) { if (plugin instanceof UnloadablePlugin) { throw new PluginException("cannot create modules for an UnloadablePlugin"); } return null; } }
public void removePlugin(final Plugin plugin) throws PluginException { throw new PluginException("This PluginLoader does not support removal."); } }
@Override public ModuleDescriptor<?> createModule(final Plugin plugin, final Element module, final ModuleDescriptorFactory moduleDescriptorFactory) { if (plugin instanceof XmlDynamicPlugin) { // It is possible to implement this, however this plugin type is not widely used and has no test coverage. // If a use case emerges, we can revisit. throw new PluginException("cannot create modules for an XmlDynamicPlugin"); } return null; } }
@Override protected void uninstallInternal() { throw new PluginException("Static plugins cannot be uninstalled"); } }
public void removePlugin(final Plugin plugin) throws PluginException { throw new PluginException("This PluginLoader does not support removal."); }
private void handleSpringMethodInvocationError(final InvocationTargetException e) { if (e.getCause() instanceof Error) { throw (Error) e.getCause(); } else if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { // Should never happen as Spring methods only throw runtime exceptions throw new PluginException("Unable to invoke createBean", e.getCause()); } }
@Override public <T> T injectBean(T bean) { try { nativeAutowireBeanMethod.invoke(nativeBeanFactory, bean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); } catch (final IllegalAccessException e) { // Should never happen throw new PluginException("Unable to access autowireBeanProperties method", e); } catch (final InvocationTargetException e) { handleSpringMethodInvocationError(e); } return bean; }
public <T> Collection<T> getBeansOfType(Class<T> interfaceClass) { try { //noinspection unchecked Map<String, T> beans = (Map<String, T>) nativeGetBeansOfTypeMethod.invoke(nativeBeanFactory, interfaceClass); return beans.values(); } catch (final IllegalAccessException e) { // Should never happen throw new PluginException("Unable to access getBeansOfType method", e); } catch (final InvocationTargetException e) { handleSpringMethodInvocationError(e); return null; } }
private PluginLoader ensurePluginAndLoaderSupportsUninstall(final Plugin plugin) { if (!plugin.isUninstallable()) { throw new PluginException("Plugin is not uninstallable: " + plugin); } final PluginLoader loader = installedPluginsToPluginLoader.get(plugin); if ((loader != null) && !loader.supportsRemoval()) { throw new PluginException("Not uninstalling plugin - loader doesn't allow removal. Plugin: " + plugin); } return loader; }
public void remove(final DeploymentUnit unit) throws PluginException { throw new PluginException("Cannot remove files in a file-list scanner: " + unit.getPath()); } }
@Override public <T> T getBean(final String id) { try { //noinspection unchecked return (T) nativeGetBeanMethod.invoke(nativeBeanFactory, id); } catch (final IllegalAccessException e) { // Should never happen throw new PluginException("Unable to access getBean method", e); } catch (final InvocationTargetException e) { handleSpringMethodInvocationError(e); return null; } }
private DeploymentUnit findMatchingDeploymentUnit(final Plugin plugin) throws PluginException { DeploymentUnit deploymentUnit = null; for (final Map.Entry<DeploymentUnit, Plugin> entry : plugins.entrySet()) { // no, you don't want to use entry.getValue().equals(plugin) here as it breaks upgrades where it is a new // version of the plugin but the key and version number hasn't changed, and hence, equals() will always return // true if (entry.getValue() == plugin) { deploymentUnit = entry.getKey(); break; } } if (deploymentUnit == null) { throw new PluginException("This pluginLoader has no memory of deploying the plugin you are trying remove: [" + plugin.getName() + "]"); } return deploymentUnit; }
public AddProjectHook addProjectHook() { if (Strings.isNullOrEmpty(addProjectHookClass)) { return null; } Object module = moduleFactory.createModule(addProjectHookClass, moduleDescriptor); try { return (AddProjectHook) module; } catch (ClassCastException ex) { throw new PluginException("The class '" + addProjectHookClass + "' is not an instance of AddProjectHook.", ex); } } }
public <T> T createBean(final Class<T> clazz) { try { final int autowiringMode = useLegacyWiringAutodetectionMode ? resolveAutowiringMode(clazz) : AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR; return clazz.cast(nativeCreateBeanMethod.invoke(nativeBeanFactory, clazz, autowiringMode, false)); } catch (final IllegalAccessException e) { // Should never happen throw new PluginException("Unable to access createBean method", e); } catch (final InvocationTargetException e) { handleSpringMethodInvocationError(e); return null; } }
public DefaultSpringContainerAccessor(final Object applicationContext) { Object beanFactory = null; try { final Method m = applicationContext.getClass().getMethod("getAutowireCapableBeanFactory"); beanFactory = m.invoke(applicationContext); } catch (final NoSuchMethodException e) { // Should never happen throw new PluginException("Cannot find getAutowireCapableBeanFactory method on " + applicationContext.getClass(), e); } catch (final IllegalAccessException e) { // Should never happen throw new PluginException("Cannot access getAutowireCapableBeanFactory method", e); } catch (final InvocationTargetException e) { handleSpringMethodInvocationError(e); } nativeBeanFactory = beanFactory; try { nativeCreateBeanMethod = beanFactory.getClass().getMethod("createBean", Class.class, int.class, boolean.class); nativeAutowireBeanMethod = beanFactory.getClass().getMethod("autowireBeanProperties", Object.class, int.class, boolean.class); nativeGetBeanMethod = beanFactory.getClass().getMethod("getBean", String.class); nativeGetBeansOfTypeMethod = beanFactory.getClass().getMethod("getBeansOfType", Class.class); checkState(Stream.of(nativeGetBeansOfTypeMethod, nativeAutowireBeanMethod, nativeCreateBeanMethod, nativeGetBeanMethod).allMatch(Objects::nonNull)); } catch (final NoSuchMethodException e) { // Should never happen throw new PluginException("Cannot find one or more methods on registered bean factory: " + nativeBeanFactory, e); } useLegacyWiringAutodetectionMode = Boolean.getBoolean(USE_LEGACY_WIRING_AUTODETECTION_MODE); }
public void addResource(String path, String name) { try { ResourceDescriptor resource = resourceDescriptorFactory.createResource(plugin, name, path, Optional.empty()); addToResources(resource); } catch (FileNotFoundException e) { throw new PluginException(String.format("File for '%s' does not exist at location: %s", name, path)); } }
public void remove(final DeploymentUnit unit) throws PluginException { final File file = unit.getPath(); try { //Rather than using File.delete(), which returns a boolean without giving much information on //what actually failed when false is returned, use Files.delete(Path) so that exceptions will //be thrown, allowing them to be handled accordingly. //Note that exceptions, like AccessDeniedException and NoSuchFileException, are documented as //"optional specific exceptions" that the underlying FileSystemProvider _can_ throw; they're //not mandated by Files.delete(Path). In practice, however, these exceptions tend to be quite //reliable. Files.delete(file.toPath()); } catch (final AccessDeniedException e) { log.info("Plugin file <{}> exists but we do not have permission to remove it. Ignoring.", file.getAbsolutePath()); } catch (final FileNotFoundException | NoSuchFileException e) { log.debug("Plugin file <{}> doesn't exist to delete. Ignoring.", file.getAbsolutePath()); } catch (final IOException e) { throw new PluginException("Unable to delete plugin file: " + file.getAbsolutePath()); } clear(file); } }
@Override public void enabled() { // Note that components loaded as plugins2 will use the com.atlassian.plugin.osgi.factory.descriptor.ComponentModuleDescriptor if (interfaceClazzName != null) { // Load the interfaceClazz now that the OSGi bundle will be available. try { interfaceClazz = plugin.loadClass(interfaceClazzName, getClass()); } catch (final Exception e) { throw new PluginException("Unable to load interface class: " + interfaceClazzName, e); } } super.enabled(); }