public class

DefaultPluginManager

extends Object
implements PluginAccessor PluginController PluginSystemLifecycle
java.lang.Object
   ↳ com.atlassian.plugin.manager.DefaultPluginManager
Known Direct Subclasses

Class Overview

This implementation delegates the initiation and classloading of plugins to a list of PluginLoaders and records the state of plugins in a PluginPersistentStateStore.

This class is responsible for enabling and disabling plugins and plugin modules and reflecting these state changes in the PluginPersistentStateStore.

An interesting quirk in the design is that installPlugin(com.atlassian.plugin.PluginArtifact) explicitly stores the plugin via a PluginInstaller, whereas uninstall(Plugin) relies on the underlying PluginLoader to remove the plugin if necessary.

Summary

Public Constructors
DefaultPluginManager(PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager)
Public Methods
void disablePlugin(String key)
Disables the plugin with the given key.
void disablePluginModule(String completeKey)
Disable a plugin module by key.
void disablePluginWithoutPersisting(String key)
Disables the plugin with the given key without persisting the disabled state.
@Deprecated void enablePlugin(String key)
This method is deprecated. since 2.5.0, use {#link enablePlugins(String... keys)} instead
void enablePluginModule(String completeKey)
Enable a plugin module by key.
void enablePlugins(String... keys)
Enable a set of plugins by key.
PluginsClassLoader getClassLoader()
Retrieve the class loader responsible for loading classes and resources from plugins.
Class<?> getDynamicPluginClass(String className)
Retrieve a class from a currently loaded (and active) dynamically loaded plugin.
InputStream getDynamicResourceAsStream(String name)
Retrieve a resource from a currently loaded (and active) dynamically loaded plugin.
<D extends ModuleDescriptor<?>> List<D> getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz)
This method has been reverted to pre PLUG-40 to fix performance issues that were encountered during load testing.
<D extends ModuleDescriptor<?>> List<D> getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz, boolean verbose)
Get all enabled module descriptors that have a specific descriptor class.
@Deprecated <M> List<ModuleDescriptor<M>> getEnabledModuleDescriptorsByType(String type)
This method is deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
<M> List<M> getEnabledModulesByClass(Class<M> moduleClass)
Retrieve all plugin modules that implement or extend a specific class.
@Deprecated <M> List<M> getEnabledModulesByClassAndDescriptor(Class<ModuleDescriptor<M>> descriptorClass, Class<M> moduleClass)
This method is deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
@Deprecated <M> List<M> getEnabledModulesByClassAndDescriptor(Class[]<ModuleDescriptor<M>> descriptorClasses, Class<M> moduleClass)
This method is deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
Plugin getEnabledPlugin(String pluginKey)
Retrieve a given plugin if it is enabled.
ModuleDescriptor<?> getEnabledPluginModule(String completeKey)
Retrieve an enabled plugin module by complete module key.
Collection<Plugin> getEnabledPlugins()
Get all of the currently enabled plugins.
<M> Collection<ModuleDescriptor<M>> getModuleDescriptors(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
Gets all module descriptors of installed modules that match the given predicate.
<M> Collection<M> getModules(ModuleDescriptorPredicate<M> moduleDescriptorPredicate)
Gets all installed modules that match the given predicate.
Plugin getPlugin(String key)
Retrieve a given plugin (whether enabled or not).
ModuleDescriptor<?> getPluginModule(String completeKey)
Retrieve any plugin module by complete module key.
InputStream getPluginResourceAsStream(String pluginKey, String resourcePath)
Retrieve a resource from a currently loaded (and active) plugin.
PluginRestartState getPluginRestartState(String key)
Gets the state of the plugin upon restart.
Collection<Plugin> getPlugins(PluginPredicate pluginPredicate)
Gets all installed plugins that match the given predicate.
Collection<Plugin> getPlugins()
Gets all of the currently installed plugins.
void init()
Initialise the plugin system.
String installPlugin(PluginArtifact pluginArtifact)
Installs a plugin and returns the plugin key
Set<String> installPlugins(PluginArtifact... pluginArtifacts)
Installs multiple plugins and returns the list of plugin keys.
boolean isPluginEnabled(String key)
This method checks to see if the plugin is enabled based on the state manager and the plugin.
boolean isPluginModuleEnabled(String completeKey)
Whether or not a given plugin module is currently enabled.
boolean isSystemPlugin(String key)
void onPluginContainerUnavailable(PluginContainerUnavailableEvent event)
void onPluginModuleAvailable(PluginModuleAvailableEvent event)
void onPluginModuleUnavailable(PluginModuleUnavailableEvent event)
void onPluginRefresh(PluginRefreshedEvent event)
void revertRestartRequiredChange(String pluginKey)
Restores the state of any plugin requiring a restart that had been removed, upgraded, or installed.
int scanForNewPlugins()
Search all loaders and add any new plugins you find.
@Deprecated void setDescriptorParserFactory(DescriptorParserFactory descriptorParserFactory)
This method is deprecated. Since 2.0.0.beta2
void setPluginInstaller(PluginInstaller pluginInstaller)
Set the plugin installation strategy for this manager
void shutdown()
Fires the shutdown event
void uninstall(Plugin plugin)
Uninstalls the given plugin, emitting disabled and uninstalled events as it does so.
final void warmRestart()
Restart all plugins by disabling and enabling them in the order they were loaded (by plugin loader)
Protected Methods
@Deprecated void addPlugin(PluginLoader loader, Plugin plugin)
This method is deprecated. Since 2.0.2, use #addPlugins(PluginLoader,Collection...) instead
void addPlugins(PluginLoader loader, Collection<Plugin> pluginsToInstall)
Update the local plugin state and enable state aware modules.
void disablePluginInternal(String key, boolean persistDisabledState)
void disablePluginModuleState(ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)
void disablePluginState(Plugin plugin, PluginPersistentStateStore stateStore)
void enablePluginModuleState(ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)
void enablePluginState(Plugin plugin, PluginPersistentStateStore stateStore)
PluginPersistentState getState()
final PluginPersistentStateStore getStore()
void notifyModuleDisabled(ModuleDescriptor<?> module)
void notifyModuleEnabled(ModuleDescriptor<?> module)
void notifyPluginDisabled(Plugin plugin)
void notifyPluginEnabled(Plugin plugin)
Called on all clustered application nodes, rather than enablePlugin(String) to just update the local state, state aware modules and loaders, but not affect the global plugin state.
void notifyUninstallPlugin(Plugin plugin)
void onUpdateRequiresRestartState(String pluginKey, PluginRestartState pluginRestartState)
void removeStateFromStore(PluginPersistentStateStore stateStore, Plugin plugin)
void uninstallNoEvent(Plugin plugin)
Preforms an uninstallation without broadcasting the uninstallation event.
void unloadPlugin(Plugin plugin)
Unload a plugin.
void updatePlugin(Plugin oldPlugin, Plugin newPlugin)
Replace an already loaded plugin with another version.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.plugin.PluginAccessor
From interface com.atlassian.plugin.PluginController
From interface com.atlassian.plugin.PluginSystemLifecycle

Public Constructors

public DefaultPluginManager (PluginPersistentStateStore store, List<PluginLoader> pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory, PluginEventManager pluginEventManager)

Public Methods

public void disablePlugin (String key)

Disables the plugin with the given key.

Calling this method will persist the disabled state so that the plugin will also be disabled on next startup. This would normally be used when a user manually disables a plugin.

If you extend DefaultPluginManager and override this method, you will also need to override disablePluginWithoutPersisting(String).

Parameters
key The plugin key.

public void disablePluginModule (String completeKey)

Disable a plugin module by key.

Parameters
completeKey The "complete key" of the plugin module.

public void disablePluginWithoutPersisting (String key)

Disables the plugin with the given key without persisting the disabled state.

Calling this method will NOT persist the disabled state so that the framework will try to enable the plugin on next startup. This is used when a plugin has errors on startup.

If you extend DefaultPluginManager and override disablePlugin(String), you will also need to override this method.

Parameters
key The plugin key.

@Deprecated public void enablePlugin (String key)

This method is deprecated.
since 2.5.0, use {#link enablePlugins(String... keys)} instead

Enable a plugin by key.

Parameters
key The plugin key.

public void enablePluginModule (String completeKey)

Enable a plugin module by key.

Parameters
completeKey The "complete key" of the plugin module.

public void enablePlugins (String... keys)

Enable a set of plugins by key. This will implicitly and recursively enable all dependent plugins.

Parameters
keys The plugin keys. Must not be null.

public PluginsClassLoader getClassLoader ()

Retrieve the class loader responsible for loading classes and resources from plugins.

Returns
  • the class loader

public Class<?> getDynamicPluginClass (String className)

Retrieve a class from a currently loaded (and active) dynamically loaded plugin. Will return the first class found, so plugins with overlapping class names will behave eratically.

Parameters
className the name of the class to retrieve
Returns
  • the dynamically loaded class that matches that name

public InputStream getDynamicResourceAsStream (String name)

Retrieve a resource from a currently loaded (and active) dynamically loaded plugin. Will return the first resource found, so plugins with overlapping resource names will behave eratically.

Parameters
name the path to the resource to retrieve
Returns
  • the dynamically loaded resource that matches that path, or null if no such resource is found

public List<D> getEnabledModuleDescriptorsByClass (Class<D> descriptorClazz)

This method has been reverted to pre PLUG-40 to fix performance issues that were encountered during load testing. This should be reverted to the state it was in at 54639 when the fundamental issue leading to this slowdown has been corrected (that is, slowness of PluginClassLoader).

Parameters
descriptorClazz module descriptor class
Returns

public List<D> getEnabledModuleDescriptorsByClass (Class<D> descriptorClazz, boolean verbose)

Get all enabled module descriptors that have a specific descriptor class.

Parameters
descriptorClazz module descriptor class
verbose log verbose messages flag
Returns

@Deprecated public List<ModuleDescriptor<M>> getEnabledModuleDescriptorsByType (String type)

This method is deprecated.
since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Get all enabled module descriptors that have a specific descriptor type.

Returns

public List<M> getEnabledModulesByClass (Class<M> moduleClass)

Retrieve all plugin modules that implement or extend a specific class.

Returns
  • List of modules that implement or extend the given class.

@Deprecated public List<M> getEnabledModulesByClassAndDescriptor (Class<ModuleDescriptor<M>> descriptorClass, Class<M> moduleClass)

This method is deprecated.
since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class as the descriptorClazz

Parameters
descriptorClass @NotNull
moduleClass @NotNull
Returns
  • List of modules that implement or extend the given class. Empty list if none found

@Deprecated public List<M> getEnabledModulesByClassAndDescriptor (Class[]<ModuleDescriptor<M>> descriptorClasses, Class<M> moduleClass)

This method is deprecated.
since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class as one of descriptorClazz

Parameters
descriptorClasses @NotNull
moduleClass @NotNull
Returns
  • List of modules that implement or extend the given class. Empty list if none found

public Plugin getEnabledPlugin (String pluginKey)

Retrieve a given plugin if it is enabled.

Returns
  • The enabled plugin, or null if that plugin does not exist or is disabled.

public ModuleDescriptor<?> getEnabledPluginModule (String completeKey)

Retrieve an enabled plugin module by complete module key.

public Collection<Plugin> getEnabledPlugins ()

Get all of the currently enabled plugins.

Returns
  • a collection of installed and enabled Plugins.

public Collection<ModuleDescriptor<M>> getModuleDescriptors (ModuleDescriptorPredicate<M> moduleDescriptorPredicate)

Gets all module descriptors of installed modules that match the given predicate.

Parameters
moduleDescriptorPredicate the ModuleDescriptorPredicate to match.
Returns

public Collection<M> getModules (ModuleDescriptorPredicate<M> moduleDescriptorPredicate)

Gets all installed modules that match the given predicate.

Parameters
moduleDescriptorPredicate the ModuleDescriptorPredicate to match.
Returns
  • a collection of modules as per getModule() that match the given predicate.

public Plugin getPlugin (String key)

Retrieve a given plugin (whether enabled or not).

Parameters
key The plugin key. Cannot be null.
Returns
  • The enabled plugin, or null if that plugin does not exist.

public ModuleDescriptor<?> getPluginModule (String completeKey)

Retrieve any plugin module by complete module key.

Note: the module may or may not be disabled.

public InputStream getPluginResourceAsStream (String pluginKey, String resourcePath)

Retrieve a resource from a currently loaded (and active) plugin. For statically loaded plugins, this just means pulling the resource from the PluginManager's classloader. For dynamically loaded plugins, this means retrieving the resource from the plugin's private classloader.

public PluginRestartState getPluginRestartState (String key)

Gets the state of the plugin upon restart. Only useful for plugins that contain module descriptors with the \@RestartRequired annotation, and therefore, cannot be dynamically installed, upgraded, or removed at runtime

Parameters
key The plugin key
Returns
  • The state of the plugin on restart

public Collection<Plugin> getPlugins (PluginPredicate pluginPredicate)

Gets all installed plugins that match the given predicate.

Parameters
pluginPredicate the PluginPredicate to match.
Returns
  • a collection of Plugins that match the given predicate.

public Collection<Plugin> getPlugins ()

Gets all of the currently installed plugins.

Returns
  • a collection of installed Plugins.

public void init ()

Initialise the plugin system. This must be called before anything else.

public String installPlugin (PluginArtifact pluginArtifact)

Installs a plugin and returns the plugin key

Parameters
pluginArtifact The plugin artifact to install
Returns
  • The plugin key

public Set<String> installPlugins (PluginArtifact... pluginArtifacts)

Installs multiple plugins and returns the list of plugin keys. All plugin artifacts must be for valid plugins or none will be installed.

Parameters
pluginArtifacts The list of plugin artifacts to install
Returns
  • A list of plugin keys

public boolean isPluginEnabled (String key)

This method checks to see if the plugin is enabled based on the state manager and the plugin.

Parameters
key The plugin key
Returns
  • True if the plugin is enabled

public boolean isPluginModuleEnabled (String completeKey)

Whether or not a given plugin module is currently enabled. This also checks if the plugin it is contained within is enabled also

public boolean isSystemPlugin (String key)

public void onPluginContainerUnavailable (PluginContainerUnavailableEvent event)

public void onPluginModuleAvailable (PluginModuleAvailableEvent event)

public void onPluginModuleUnavailable (PluginModuleUnavailableEvent event)

public void onPluginRefresh (PluginRefreshedEvent event)

public void revertRestartRequiredChange (String pluginKey)

Restores the state of any plugin requiring a restart that had been removed, upgraded, or installed. If marked as removed, the mark will be deleted. If marked as upgrade, an attempt to restore the original plugin artifact will be made. If marked as install, the artifact will be deleted.

Parameters
pluginKey The plugin key to revert
Throws
PluginException If the revert cannot be completed

public int scanForNewPlugins ()

Search all loaders and add any new plugins you find.

Returns
  • The number of new plugins found.

@Deprecated public void setDescriptorParserFactory (DescriptorParserFactory descriptorParserFactory)

This method is deprecated.
Since 2.0.0.beta2

public void setPluginInstaller (PluginInstaller pluginInstaller)

Set the plugin installation strategy for this manager

Parameters
pluginInstaller the plugin installation strategy to use
See Also

public void shutdown ()

Fires the shutdown event

Throws
IllegalStateException if already shutdown or already in the process of shutting down.

public void uninstall (Plugin plugin)

Uninstalls the given plugin, emitting disabled and uninstalled events as it does so.

Parameters
plugin the plugin to uninstall.
Throws
PluginException If the plugin or loader doesn't support uninstallation

public final void warmRestart ()

Restart all plugins by disabling and enabling them in the order they were loaded (by plugin loader)

Protected Methods

@Deprecated protected void addPlugin (PluginLoader loader, Plugin plugin)

This method is deprecated.
Since 2.0.2, use #addPlugins(PluginLoader,Collection...) instead

protected void addPlugins (PluginLoader loader, Collection<Plugin> pluginsToInstall)

Update the local plugin state and enable state aware modules.

If there is an existing plugin with the same key, the version strings of the existing plugin and the plugin provided to this method will be parsed and compared. If the installed version is newer than the provided version, it will not be changed. If the specified plugin's version is the same or newer, the existing plugin state will be saved and the plugin will be unloaded before the provided plugin is installed. If the existing plugin cannot be unloaded a PluginException will be thrown.

Parameters
loader the loader used to load this plugin
pluginsToInstall the plugins to add
Throws
PluginParseException if the plugin cannot be parsed

protected void disablePluginInternal (String key, boolean persistDisabledState)

protected void disablePluginModuleState (ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)

protected void disablePluginState (Plugin plugin, PluginPersistentStateStore stateStore)

protected void enablePluginModuleState (ModuleDescriptor<?> module, PluginPersistentStateStore stateStore)

protected void enablePluginState (Plugin plugin, PluginPersistentStateStore stateStore)

protected PluginPersistentState getState ()

protected final PluginPersistentStateStore getStore ()

protected void notifyModuleDisabled (ModuleDescriptor<?> module)

protected void notifyModuleEnabled (ModuleDescriptor<?> module)

protected void notifyPluginDisabled (Plugin plugin)

protected void notifyPluginEnabled (Plugin plugin)

Called on all clustered application nodes, rather than enablePlugin(String) to just update the local state, state aware modules and loaders, but not affect the global plugin state.

Parameters
plugin the plugin being enabled

protected void notifyUninstallPlugin (Plugin plugin)

protected void onUpdateRequiresRestartState (String pluginKey, PluginRestartState pluginRestartState)

protected void removeStateFromStore (PluginPersistentStateStore stateStore, Plugin plugin)

protected void uninstallNoEvent (Plugin plugin)

Preforms an uninstallation without broadcasting the uninstallation event.

Parameters
plugin The plugin to uninstall

protected void unloadPlugin (Plugin plugin)

Unload a plugin. Called when plugins are added locally, or remotely in a clustered application.

Parameters
plugin the plugin to remove
Throws
PluginException if the plugin cannot be uninstalled

protected void updatePlugin (Plugin oldPlugin, Plugin newPlugin)

Replace an already loaded plugin with another version. Relevant stored configuration for the plugin will be preserved.

Parameters
oldPlugin Plugin to replace
newPlugin New plugin to install
Throws
PluginException if the plugin cannot be updated