java.lang.Object
   ↳ com.atlassian.plugin.impl.AbstractPlugin
     ↳ com.atlassian.plugin.osgi.factory.OsgiPlugin

Class Overview

Plugin that wraps an OSGi bundle that does contain a plugin descriptor. The actual bundle is not created until the install() method is invoked. Any attempt to access a method that requires a bundle will throw an IllegalPluginStateException. This class uses a OsgiPluginHelper to represent different behaviors of key methods in different states. OsgiPluginUninstalledHelper implements the methods when the plugin hasn't yet been installed into the OSGi container, while OsgiPluginInstalledHelper implements the methods when the bundle is available. This leaves this class to manage the PluginState and interactions with the event system.

Summary

Constants
String ATLASSIAN_PLUGIN_KEY
[Expand]
Inherited Fields
From interface com.atlassian.plugin.Plugin
Public Constructors
OsgiPlugin(String key, OsgiContainerManager mgr, PluginArtifact artifact, PluginArtifact originalPluginArtifact, PluginEventManager pluginEventManager)
Public Methods
<T> T autowire(Class<T> clazz)
Creates and autowires the class, using Spring's autodetection algorithm
void autowire(Object instance, AutowireCapablePlugin.AutowireStrategy autowireStrategy)
Autowires the instance
void autowire(Object instance)
Autowires the instance using Spring's autodetection algorithm
<T> T autowire(Class<T> clazz, AutowireCapablePlugin.AutowireStrategy autowireStrategy)
Creates and autowires the class
Bundle getBundle()
ClassLoader getClassLoader()
Get the classloader for the plugin.
ContainerAccessor getContainerAccessor()
PluginArtifact getPluginArtifact()
Set<String> getRequiredPlugins()
Determines which plugins are required for this one to operate based on tracing the "wires" or packages that are imported by this plugin.
URL getResource(String name)
Retrieve the URL of the resource from the plugin.
InputStream getResourceAsStream(String name)
Load a given resource from the plugin.
boolean isDeleteable()
Should the plugin file be deleted on unistall?
boolean isDynamicallyLoaded()
Whether or not this plugin is loaded dynamically at runtime.
boolean isUninstallable()
Whether or not this plugin can be 'uninstalled'.
<T> Class<T> loadClass(String clazz, Class<?> callingClass)
Get the plugin to load a specific class.
void onPluginFrameworkShutdownEvent(PluginFrameworkShutdownEvent event)
void onPluginFrameworkStartedEvent(PluginFrameworkStartedEvent event)
void onServiceDependencyWaitEnded(PluginServiceDependencyWaitEndedEvent event)
void onServiceDependencyWaitEnded(PluginServiceDependencyWaitTimedOutEvent event)
void onServiceDependencyWaitStarting(PluginServiceDependencyWaitStartingEvent event)
void onSpringContextFailed(PluginContainerFailedEvent event)
Called when the spring context for the bundle has failed to be created.
void onSpringContextRefresh(PluginContainerRefreshedEvent event)
Called when the spring context for the bundle has been created or refreshed.
String toString()
Protected Methods
synchronized void disableInternal()
Disables the plugin by changing the bundle state back to resolved
synchronized PluginState enableInternal()
Enables the plugin by setting the OSGi bundle state to enabled.
void installInternal()
Installs the plugin artifact into OSGi
void uninstallInternal()
Uninstalls the bundle from the OSGi container
[Expand]
Inherited Methods
From class com.atlassian.plugin.impl.AbstractPlugin
From class java.lang.Object
From interface com.atlassian.plugin.AutowireCapablePlugin
From interface com.atlassian.plugin.Plugin
From interface com.atlassian.plugin.PluginArtifactBackedPlugin
From interface com.atlassian.plugin.Resourced
From interface com.atlassian.plugin.module.ContainerManagedPlugin
From interface java.lang.Comparable

Constants

public static final String ATLASSIAN_PLUGIN_KEY

Constant Value: "Atlassian-Plugin-Key"

Public Constructors

public OsgiPlugin (String key, OsgiContainerManager mgr, PluginArtifact artifact, PluginArtifact originalPluginArtifact, PluginEventManager pluginEventManager)

Public Methods

public T autowire (Class<T> clazz)

Creates and autowires the class, using Spring's autodetection algorithm

Parameters
clazz The class to create
Returns
  • The created and wired bean
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public void autowire (Object instance, AutowireCapablePlugin.AutowireStrategy autowireStrategy)

Autowires the instance

Parameters
instance The object to autowire
autowireStrategy The autowire strategy, must not be constructor
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public void autowire (Object instance)

Autowires the instance using Spring's autodetection algorithm

Parameters
instance The object to inject
Throws
IllegalPluginStateException if the bundle hasn't been created yet
IllegalStateException

public T autowire (Class<T> clazz, AutowireCapablePlugin.AutowireStrategy autowireStrategy)

Creates and autowires the class

Parameters
clazz The class to create
autowireStrategy The autowire strategy
Returns
  • The created and wired bean
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public Bundle getBundle ()

Returns
  • The active bundle
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public ClassLoader getClassLoader ()

Get the classloader for the plugin.

Returns
  • The classloader to load classes and resources from the bundle
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public ContainerAccessor getContainerAccessor ()

public PluginArtifact getPluginArtifact ()

public Set<String> getRequiredPlugins ()

Determines which plugins are required for this one to operate based on tracing the "wires" or packages that are imported by this plugin. Bundles that provide those packages are determined to be required plugins.

Returns
  • A set of bundle symbolic names, or plugin keys. Empty set if none.

public URL getResource (String name)

Retrieve the URL of the resource from the plugin.

Parameters
name The resource name
Returns
  • The resource URL, null if not found
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public InputStream getResourceAsStream (String name)

Load a given resource from the plugin. Plugins that are loaded dynamically will need to implement this in a way that loads the resource from the same context as the plugin. Static plugins can just pull them from their own classloader.

Parameters
name The name of the resource to be loaded.
Returns
  • Null if not found
Throws
IllegalPluginStateException if the bundle hasn't been created yet

public boolean isDeleteable ()

Should the plugin file be deleted on unistall?

Returns
  • true

public boolean isDynamicallyLoaded ()

Whether or not this plugin is loaded dynamically at runtime.

Returns
  • true

public boolean isUninstallable ()

Whether or not this plugin can be 'uninstalled'.

Returns
  • true

public Class<T> loadClass (String clazz, Class<?> callingClass)

Get the plugin to load a specific class.

Parameters
clazz The name of the class to be loaded
callingClass The class calling the loading (used to help find a classloader)
Returns
  • The class instance, loaded from the OSGi bundle
Throws
ClassNotFoundException If the class cannot be found
IllegalPluginStateException if the bundle hasn't been created yet

public void onPluginFrameworkShutdownEvent (PluginFrameworkShutdownEvent event)

public void onPluginFrameworkStartedEvent (PluginFrameworkStartedEvent event)

public void onServiceDependencyWaitEnded (PluginServiceDependencyWaitEndedEvent event)

public void onServiceDependencyWaitEnded (PluginServiceDependencyWaitTimedOutEvent event)

public void onServiceDependencyWaitStarting (PluginServiceDependencyWaitStartingEvent event)

public void onSpringContextFailed (PluginContainerFailedEvent event)

Called when the spring context for the bundle has failed to be created. This means the bundle is still active, but the Spring context is not available, so for our purposes, the plugin shouldn't be enabled.

Parameters
event The plugin container failed event
Throws
IllegalPluginStateException If the plugin key hasn't been set yet

public void onSpringContextRefresh (PluginContainerRefreshedEvent event)

Called when the spring context for the bundle has been created or refreshed. If this is the first time the context has been refreshed, then it is a new context. Otherwise, this means that the bundle has been reloaded, usually due to a dependency upgrade.

Parameters
event The event
Throws
IllegalPluginStateException If the plugin key hasn't been set yet

public String toString ()

Protected Methods

protected synchronized void disableInternal ()

Disables the plugin by changing the bundle state back to resolved

Throws
OsgiContainerException If the OSGi system threw an exception
IllegalPluginStateException if the bundle hasn't been created yet

protected synchronized PluginState enableInternal ()

Enables the plugin by setting the OSGi bundle state to enabled.

Returns
  • ENABLEDif spring isn't necessory or ENABLING if we are waiting on a spring context
Throws
OsgiContainerException If the underlying OSGi system threw an exception or we tried to enable the bundle when it was in an invalid state
IllegalPluginStateException if the bundle hasn't been created yet

protected void installInternal ()

Installs the plugin artifact into OSGi

Throws
IllegalPluginStateException if the bundle hasn't been created yet

protected void uninstallInternal ()

Uninstalls the bundle from the OSGi container

Throws
OsgiContainerException If the underlying OSGi system threw an exception
IllegalPluginStateException if the bundle hasn't been created yet