com.atlassian.plugin
Class DefaultPluginManager

java.lang.Object
  extended by com.atlassian.plugin.DefaultPluginManager
All Implemented Interfaces:
PluginAccessor, PluginController, PluginManager

public class DefaultPluginManager
extends java.lang.Object
implements PluginManager

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

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

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


Field Summary
 
Fields inherited from interface com.atlassian.plugin.PluginManager
PLUGIN_DESCRIPTOR_FILENAME
 
Constructor Summary
DefaultPluginManager(PluginStateStore store, java.util.List pluginLoaders, ModuleDescriptorFactory moduleDescriptorFactory)
           
 
Method Summary
protected  void addPlugin(PluginLoader loader, Plugin plugin)
          Update the local plugin state and enable state aware modules
 void disablePlugin(java.lang.String key)
          Disable a plugin by key.
 void disablePluginModule(java.lang.String completeKey)
          Disable a plugin module by key.
protected  void disablePluginModuleState(ModuleDescriptor module, PluginStateStore stateStore)
           
protected  void disablePluginState(Plugin plugin, PluginStateStore stateStore)
           
 void enablePlugin(java.lang.String key)
          Enable a plugin by key.
 void enablePluginModule(java.lang.String completeKey)
          Enable a plugin module by key.
protected  void enablePluginModuleState(ModuleDescriptor module, PluginStateStore stateStore)
           
protected  void enablePluginState(Plugin plugin, PluginStateStore stateStore)
           
 java.io.InputStream getDynamicResourceAsStream(java.lang.String name)
          Retrieve a resource from a currently loaded (and active) dynamically loaded plugin.
 java.util.List getEnabledModuleDescriptorsByClass(java.lang.Class moduleDescriptorClass)
          Deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
 java.util.List getEnabledModuleDescriptorsByType(java.lang.String type)
          Deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
 java.util.List getEnabledModulesByClass(java.lang.Class moduleClass)
          Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
 java.util.List getEnabledModulesByClassAndDescriptor(java.lang.Class[] descriptorClasses, java.lang.Class moduleClass)
          Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
 java.util.List getEnabledModulesByClassAndDescriptor(java.lang.Class descriptorClass, java.lang.Class moduleClass)
          Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.
 Plugin getEnabledPlugin(java.lang.String pluginKey)
          Retrieve a given plugin if it is enabled.
 ModuleDescriptor getEnabledPluginModule(java.lang.String completeKey)
          Retrieve an enabled plugin module by complete module key.
 java.util.Collection getEnabledPlugins()
          Get all of the currently enabled plugins.
protected  java.util.List getEnabledStateAwareModuleKeys(Plugin plugin)
           
 java.util.Collection getModuleDescriptors(ModuleDescriptorPredicate moduleDescriptorPredicate)
          Gets all module descriptors of installed modules that match the given predicate.
 java.util.Collection getModules(ModuleDescriptorPredicate moduleDescriptorPredicate)
          Gets all installed modules that match the given predicate.
 Plugin getPlugin(java.lang.String key)
          Retrieve a given plugin (whether enabled or not).
 ModuleDescriptor getPluginModule(java.lang.String completeKey)
          Retrieve any plugin module by complete module key.
 java.io.InputStream getPluginResourceAsStream(java.lang.String pluginKey, java.lang.String resourcePath)
          Retrieve a resource from a currently loaded (and active) plugin.
 java.util.Collection getPlugins()
          Gets all of the currently installed plugins.
 java.util.Collection getPlugins(PluginPredicate pluginPredicate)
          Gets all installed plugins that match the given predicate.
protected  PluginManagerState getState()
           
protected  PluginStateStore getStore()
           
 void init()
          Initialize all plugins in all loaders
 java.lang.String installPlugin(PluginJar pluginJar)
          Installs a plugin and returns the plugin key
 boolean isPluginEnabled(java.lang.String key)
          Whether or not a given plugin is currently enabled.
 boolean isPluginModuleEnabled(java.lang.String completeKey)
          Whether or not a given plugin module is currently enabled.
 boolean isSystemPlugin(java.lang.String key)
           
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.
protected  void notifyUninstallPlugin(Plugin plugin)
           
protected  void removeStateFromStore(PluginStateStore stateStore, Plugin plugin)
           
 int scanForNewPlugins()
          Search all loaders and add any new plugins you find.
 void setDescriptorParserFactory(DescriptorParserFactory descriptorParserFactory)
           
 void setPluginInstaller(PluginInstaller pluginInstaller)
          Set the plugin installation strategy for this manager
 void uninstall(Plugin plugin)
          Uninstall (delete) a plugin if possible.
protected  void unloadPlugin(Plugin plugin)
          Unload a plugin.
protected  void updatePlugin(Plugin oldPlugin, Plugin newPlugin)
          Replace an already loaded plugin with another version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPluginManager

public DefaultPluginManager(PluginStateStore store,
                            java.util.List pluginLoaders,
                            ModuleDescriptorFactory moduleDescriptorFactory)
Method Detail

init

public void init()
          throws PluginParseException
Initialize all plugins in all loaders

Specified by:
init in interface PluginManager
Throws:
PluginParseException

setPluginInstaller

public void setPluginInstaller(PluginInstaller pluginInstaller)
Set the plugin installation strategy for this manager

Parameters:
pluginInstaller -
See Also:
PluginInstaller

getStore

protected final PluginStateStore getStore()

installPlugin

public java.lang.String installPlugin(PluginJar pluginJar)
                               throws PluginParseException
Description copied from interface: PluginController
Installs a plugin and returns the plugin key

Specified by:
installPlugin in interface PluginController
Throws:
PluginParseException - if the plugin is not a valid plugin

scanForNewPlugins

public int scanForNewPlugins()
                      throws PluginParseException
Description copied from interface: PluginController
Search all loaders and add any new plugins you find.

Specified by:
scanForNewPlugins in interface PluginController
Returns:
The number of new plugins found.
Throws:
PluginParseException

uninstall

public void uninstall(Plugin plugin)
               throws PluginException
Uninstall (delete) a plugin if possible.

Be very careful when using this method, the plugin cannot be brought back.

Specified by:
uninstall in interface PluginController
Throws:
PluginException - if there was some problem uninstalling the plugin.

removeStateFromStore

protected void removeStateFromStore(PluginStateStore stateStore,
                                    Plugin plugin)

unloadPlugin

protected void unloadPlugin(Plugin plugin)
                     throws PluginException
Unload a plugin. Called when plugins are added locally, or remotely in a clustered application.

Throws:
PluginException

notifyUninstallPlugin

protected void notifyUninstallPlugin(Plugin plugin)

getState

protected PluginManagerState getState()

addPlugin

protected void addPlugin(PluginLoader loader,
                         Plugin plugin)
                  throws PluginParseException
Update the local plugin state and enable state aware modules

Parameters:
loader -
plugin -
Throws:
PluginParseException

updatePlugin

protected void updatePlugin(Plugin oldPlugin,
                            Plugin newPlugin)
                     throws PluginException
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

getPlugins

public java.util.Collection getPlugins()
Description copied from interface: PluginAccessor
Gets all of the currently installed plugins.

Specified by:
getPlugins in interface PluginAccessor
Returns:
a collection of installed Plugins.

getPlugins

public java.util.Collection getPlugins(PluginPredicate pluginPredicate)
Description copied from interface: PluginAccessor
Gets all installed plugins that match the given predicate.

Specified by:
getPlugins in interface PluginAccessor
Parameters:
pluginPredicate - the PluginPredicate to match.
Returns:
a collection of Plugins that match the given predicate.
Since:
0.17
See Also:
PluginAccessor.getPlugins(PluginPredicate)

getEnabledPlugins

public java.util.Collection getEnabledPlugins()
Description copied from interface: PluginAccessor
Get all of the currently enabled plugins.

Specified by:
getEnabledPlugins in interface PluginAccessor
Returns:
a collection of installed and enabled Plugins.
See Also:
PluginAccessor.getEnabledPlugins()

getModules

public java.util.Collection getModules(ModuleDescriptorPredicate moduleDescriptorPredicate)
Description copied from interface: PluginAccessor
Gets all installed modules that match the given predicate.

Specified by:
getModules in interface PluginAccessor
Parameters:
moduleDescriptorPredicate - the ModuleDescriptorPredicate to match.
Returns:
a collection of modules as per ModuleDescriptor.getModule() that match the given predicate.
Since:
0.17
See Also:
PluginAccessor.getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)

getModuleDescriptors

public java.util.Collection getModuleDescriptors(ModuleDescriptorPredicate moduleDescriptorPredicate)
Description copied from interface: PluginAccessor
Gets all module descriptors of installed modules that match the given predicate.

Specified by:
getModuleDescriptors in interface PluginAccessor
Parameters:
moduleDescriptorPredicate - the ModuleDescriptorPredicate to match.
Returns:
a collection of ModuleDescriptors that match the given predicate.
Since:
0.17
See Also:
PluginAccessor.getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate)

getPlugin

public Plugin getPlugin(java.lang.String key)
Description copied from interface: PluginAccessor
Retrieve a given plugin (whether enabled or not).

Specified by:
getPlugin in interface PluginAccessor
Returns:
The enabled plugin, or null if that plugin does not exist.

getEnabledPlugin

public Plugin getEnabledPlugin(java.lang.String pluginKey)
Description copied from interface: PluginAccessor
Retrieve a given plugin if it is enabled.

Specified by:
getEnabledPlugin in interface PluginAccessor
Returns:
The enabled plugin, or null if that plugin does not exist or is disabled.

getPluginModule

public ModuleDescriptor getPluginModule(java.lang.String completeKey)
Description copied from interface: PluginAccessor
Retrieve any plugin module by complete module key.

Note: the module may or may not be disabled.

Specified by:
getPluginModule in interface PluginAccessor

getEnabledPluginModule

public ModuleDescriptor getEnabledPluginModule(java.lang.String completeKey)
Description copied from interface: PluginAccessor
Retrieve an enabled plugin module by complete module key.

Specified by:
getEnabledPluginModule in interface PluginAccessor

getEnabledModulesByClass

public java.util.List getEnabledModulesByClass(java.lang.Class moduleClass)
Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Retrieve all plugin modules that implement or extend a specific class.

Specified by:
getEnabledModulesByClass in interface PluginAccessor
Returns:
List of modules that implement or extend the given class.
See Also:
PluginAccessor.getEnabledModulesByClass(Class)

getEnabledModulesByClassAndDescriptor

public java.util.List getEnabledModulesByClassAndDescriptor(java.lang.Class[] descriptorClasses,
                                                            java.lang.Class moduleClass)
Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class as one of descriptorClazz

Specified by:
getEnabledModulesByClassAndDescriptor in interface PluginAccessor
Parameters:
descriptorClasses - @NotNull
moduleClass - @NotNull
Returns:
List of modules that implement or extend the given class. Empty list if none found
See Also:
PluginAccessor.getEnabledModulesByClassAndDescriptor(Class[], Class)

getEnabledModulesByClassAndDescriptor

public java.util.List getEnabledModulesByClassAndDescriptor(java.lang.Class descriptorClass,
                                                            java.lang.Class moduleClass)
Deprecated. since 0.17, use getModules(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Retrieve all plugin modules that implement or extend a specific class, and has a descriptor class as the descriptorClazz

Specified by:
getEnabledModulesByClassAndDescriptor in interface PluginAccessor
Parameters:
descriptorClass - @NotNull
moduleClass - @NotNull
Returns:
List of modules that implement or extend the given class. Empty list if none found
See Also:
PluginAccessor.getEnabledModulesByClassAndDescriptor(Class, Class)

getEnabledModuleDescriptorsByClass

public java.util.List getEnabledModuleDescriptorsByClass(java.lang.Class moduleDescriptorClass)
Deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Get all enabled module descriptors that have a specific descriptor class.

Specified by:
getEnabledModuleDescriptorsByClass in interface PluginAccessor
Returns:
List of ModuleDescriptors that implement or extend the given class.
See Also:
PluginAccessor.getEnabledModuleDescriptorsByClass(Class)

getEnabledModuleDescriptorsByType

public java.util.List getEnabledModuleDescriptorsByType(java.lang.String type)
                                                 throws PluginParseException,
                                                        java.lang.IllegalArgumentException
Deprecated. since 0.17, use getModuleDescriptors(com.atlassian.plugin.predicate.ModuleDescriptorPredicate) with an appropriate predicate instead.

Description copied from interface: PluginAccessor
Get all enabled module descriptors that have a specific descriptor type.

Specified by:
getEnabledModuleDescriptorsByType in interface PluginAccessor
Returns:
List of ModuleDescriptors that are of a given type.
Throws:
PluginParseException
java.lang.IllegalArgumentException
See Also:
PluginAccessor.getEnabledModuleDescriptorsByType(String)

enablePlugin

public void enablePlugin(java.lang.String key)
Description copied from interface: PluginController
Enable a plugin by key.

Specified by:
enablePlugin in interface PluginController

enablePluginState

protected void enablePluginState(Plugin plugin,
                                 PluginStateStore stateStore)

notifyPluginEnabled

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.


disablePlugin

public void disablePlugin(java.lang.String key)
Description copied from interface: PluginController
Disable a plugin by key.

Specified by:
disablePlugin in interface PluginController

disablePluginState

protected void disablePluginState(Plugin plugin,
                                  PluginStateStore stateStore)

getEnabledStateAwareModuleKeys

protected java.util.List getEnabledStateAwareModuleKeys(Plugin plugin)

notifyPluginDisabled

protected void notifyPluginDisabled(Plugin plugin)

disablePluginModule

public void disablePluginModule(java.lang.String completeKey)
Description copied from interface: PluginController
Disable a plugin module by key.

Specified by:
disablePluginModule in interface PluginController

disablePluginModuleState

protected void disablePluginModuleState(ModuleDescriptor module,
                                        PluginStateStore stateStore)

notifyModuleDisabled

protected void notifyModuleDisabled(ModuleDescriptor module)

enablePluginModule

public void enablePluginModule(java.lang.String completeKey)
Description copied from interface: PluginController
Enable a plugin module by key.

Specified by:
enablePluginModule in interface PluginController

enablePluginModuleState

protected void enablePluginModuleState(ModuleDescriptor module,
                                       PluginStateStore stateStore)

notifyModuleEnabled

protected void notifyModuleEnabled(ModuleDescriptor module)

isPluginModuleEnabled

public boolean isPluginModuleEnabled(java.lang.String completeKey)
Description copied from interface: PluginAccessor
Whether or not a given plugin module is currently enabled. This also checks if the plugin it is contained within is enabled also

Specified by:
isPluginModuleEnabled in interface PluginAccessor
See Also:
PluginAccessor.isPluginEnabled(String)

isPluginEnabled

public boolean isPluginEnabled(java.lang.String key)
Description copied from interface: PluginAccessor
Whether or not a given plugin is currently enabled.

Specified by:
isPluginEnabled in interface PluginAccessor

getDynamicResourceAsStream

public java.io.InputStream getDynamicResourceAsStream(java.lang.String name)
Description copied from interface: PluginAccessor
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.

Specified by:
getDynamicResourceAsStream in interface PluginAccessor
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

getPluginResourceAsStream

public java.io.InputStream getPluginResourceAsStream(java.lang.String pluginKey,
                                                     java.lang.String resourcePath)
Description copied from interface: PluginAccessor
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.

Specified by:
getPluginResourceAsStream in interface PluginAccessor

isSystemPlugin

public boolean isSystemPlugin(java.lang.String key)
Specified by:
isSystemPlugin in interface PluginAccessor
Returns:
true if the plugin is a system plugin.

setDescriptorParserFactory

public void setDescriptorParserFactory(DescriptorParserFactory descriptorParserFactory)


Copyright © 2008 Atlassian Software Systems Pty Ltd. All Rights Reserved.