public class OsgiPlugin extends AbstractPlugin implements AutowireCapablePlugin, ContainerManagedPlugin
AbstractPlugin.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.AutowireCapablePlugin.AutowireStrategy| Modifier and Type | Field and Description |
|---|---|
static String |
ATLASSIAN_PLUGIN_KEY
Manifest key for the Atlassian plugin key entry
|
static String |
REMOTE_PLUGIN_KEY
Manifest key denoting Atlassian remote plugins
|
NAME_COMPARATOR, VERSION_1, VERSION_2, VERSION_3| Constructor and Description |
|---|
OsgiPlugin(String key,
OsgiContainerManager mgr,
PluginArtifact artifact,
PluginArtifact originalPluginArtifact,
PluginEventManager pluginEventManager) |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
autowire(Class<T> clazz)
Creates and autowires the class, preferring constructor inject, then falling back to private field and setter
|
<T> T |
autowire(Class<T> clazz,
AutowireCapablePlugin.AutowireStrategy autowireStrategy)
Creates and autowires the class
|
void |
autowire(Object instance)
Autowires the instance using plugin container's default injection algorithm
|
void |
autowire(Object instance,
AutowireCapablePlugin.AutowireStrategy autowireStrategy)
Autowires the instance
|
protected void |
disableInternal()
Disables the plugin by changing the bundle state back to resolved
|
protected PluginState |
enableInternal()
Enables the plugin by setting the OSGi bundle state to enabled.
|
org.osgi.framework.Bundle |
getBundle() |
ClassLoader |
getClassLoader()
Get the classloader for the plugin.
|
ContainerAccessor |
getContainerAccessor() |
Date |
getDateInstalled()
The date this plugin was installed into the system, is the same as the loaded date for non artifact backed plugins
|
InstallationMode |
getInstallationMode()
Gets the installation mode
|
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.
|
protected void |
installInternal()
Installs the plugin artifact into OSGi
|
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 |
onPluginContainerFailed(PluginContainerFailedEvent event)
Called when the plugin container for the bundle has failed to be created.
|
void |
onPluginContainerRefresh(PluginContainerRefreshedEvent event)
Called when the plugin container for the bundle has been created or refreshed.
|
void |
onPluginFrameworkShutdownEvent(PluginFrameworkShutdownEvent event) |
void |
onPluginFrameworkStartedEvent(PluginFrameworkStartedEvent event) |
void |
onServiceDependencyWaitEnded(PluginServiceDependencyWaitEndedEvent event) |
void |
onServiceDependencyWaitEnded(PluginServiceDependencyWaitTimedOutEvent event) |
void |
onServiceDependencyWaitStarting(PluginServiceDependencyWaitStartingEvent event) |
String |
toString() |
protected void |
uninstallInternal()
Uninstalls the bundle from the OSGi container
|
addModuleDescriptor, close, compareAndSetPluginState, compareTo, containsSystemModule, disable, enable, getActivePermissions, getDateLoaded, getI18nNameKey, getKey, getLog, getModuleDescriptor, getModuleDescriptors, getModuleDescriptorsByModuleClass, getName, getPluginInformation, getPluginState, getPluginsVersion, getResourceDescriptor, getResourceDescriptors, getResourceDescriptors, getResourceLocation, hasAllPermissions, install, isBundledPlugin, isEnabled, isEnabledByDefault, isSystemPlugin, removeModuleDescriptor, setEnabled, setEnabledByDefault, setI18nNameKey, setKey, setName, setPluginInformation, setPluginState, setPluginsVersion, setResources, setSystemPlugin, uninstallclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddModuleDescriptor, close, containsSystemModule, disable, enable, getActivePermissions, getDateLoaded, getI18nNameKey, getKey, getModuleDescriptor, getModuleDescriptors, getModuleDescriptorsByModuleClass, getName, getPluginInformation, getPluginState, getPluginsVersion, hasAllPermissions, install, isBundledPlugin, isEnabled, isEnabledByDefault, isSystemPlugin, setEnabled, setEnabledByDefault, setI18nNameKey, setKey, setName, setPluginInformation, setPluginsVersion, setResources, setSystemPlugin, uninstallgetResourceDescriptor, getResourceDescriptors, getResourceDescriptors, getResourceLocationcompareTopublic static final String ATLASSIAN_PLUGIN_KEY
public static final String REMOTE_PLUGIN_KEY
public OsgiPlugin(String key, OsgiContainerManager mgr, PluginArtifact artifact, PluginArtifact originalPluginArtifact, PluginEventManager pluginEventManager)
public org.osgi.framework.Bundle getBundle()
throws IllegalPluginStateException
IllegalPluginStateException - if the bundle hasn't been created yetpublic InstallationMode getInstallationMode()
PlugingetInstallationMode in interface PlugingetInstallationMode in class AbstractPluginpublic boolean isUninstallable()
PluginisUninstallable in interface Pluginpublic boolean isDynamicallyLoaded()
PluginisDynamicallyLoaded in interface Pluginpublic boolean isDeleteable()
PluginisDeleteable in interface Pluginpublic Date getDateInstalled()
PlugingetDateInstalled in interface PlugingetDateInstalled in class AbstractPluginpublic PluginArtifact getPluginArtifact()
getPluginArtifact in interface PluginArtifactBackedPluginPluginArtifact used to create this plugin instance. Cannot be null.public <T> Class<T> loadClass(String clazz, Class<?> callingClass) throws ClassNotFoundException, IllegalPluginStateException
PluginloadClass in interface PluginT - The class typeclazz - The name of the class to be loadedcallingClass - The class calling the loading (used to help find a classloader)ClassNotFoundException - If the class cannot be foundIllegalPluginStateException - if the bundle hasn't been created yetpublic URL getResource(String name) throws IllegalPluginStateException
PlugingetResource in interface Pluginname - The resource nameIllegalPluginStateException - if the bundle hasn't been created yetpublic InputStream getResourceAsStream(String name) throws IllegalPluginStateException
PlugingetResourceAsStream in interface Pluginname - The name of the resource to be loaded.IllegalPluginStateException - if the bundle hasn't been created yetpublic ClassLoader getClassLoader() throws IllegalPluginStateException
PlugingetClassLoader in interface PluginIllegalPluginStateException - if the bundle hasn't been created yetpublic void onPluginContainerFailed(PluginContainerFailedEvent event) throws IllegalPluginStateException
event - The plugin container failed eventIllegalPluginStateException - If the plugin key hasn't been set yetpublic void onPluginFrameworkStartedEvent(PluginFrameworkStartedEvent event)
public void onPluginFrameworkShutdownEvent(PluginFrameworkShutdownEvent event)
public void onServiceDependencyWaitStarting(PluginServiceDependencyWaitStartingEvent event)
public void onServiceDependencyWaitEnded(PluginServiceDependencyWaitEndedEvent event)
public void onServiceDependencyWaitEnded(PluginServiceDependencyWaitTimedOutEvent event)
public void onPluginContainerRefresh(PluginContainerRefreshedEvent event) throws IllegalPluginStateException
event - The eventIllegalPluginStateException - If the plugin key hasn't been set yetpublic <T> T autowire(Class<T> clazz) throws IllegalPluginStateException
autowire in interface AutowireCapablePluginclazz - The class to createIllegalPluginStateException - if the bundle hasn't been created yetpublic <T> T autowire(Class<T> clazz, AutowireCapablePlugin.AutowireStrategy autowireStrategy) throws IllegalPluginStateException
autowire in interface AutowireCapablePluginclazz - The class to createautowireStrategy - The autowire strategyIllegalPluginStateException - if the bundle hasn't been created yetpublic void autowire(Object instance) throws IllegalStateException
autowire in interface AutowireCapablePlugininstance - The object to injectIllegalPluginStateException - if the bundle hasn't been created yetIllegalStateExceptionpublic void autowire(Object instance, AutowireCapablePlugin.AutowireStrategy autowireStrategy) throws IllegalPluginStateException
autowire in interface AutowireCapablePlugininstance - The object to autowireautowireStrategy - The autowire strategy, must not be constructorIllegalPluginStateException - if the bundle hasn't been created yetpublic Set<String> getRequiredPlugins() throws IllegalPluginStateException
getRequiredPlugins in interface PlugingetRequiredPlugins in class AbstractPluginIllegalPluginStateExceptionpublic String toString()
toString in class AbstractPluginprotected void installInternal()
throws IllegalPluginStateException
installInternal in class AbstractPluginIllegalPluginStateException - if the bundle hasn't been created yetprotected PluginState enableInternal() throws OsgiContainerException, IllegalPluginStateException
enableInternal in class AbstractPluginPluginState.ENABLEDif the container is being refreshed or PluginState.ENABLING if we are waiting
on a plugin container (first time being activated, as all subsequent times are considered refreshes)OsgiContainerException - If the underlying OSGi system threw an exception or we tried to enable the bundle
when it was in an invalid stateIllegalPluginStateException - if the bundle hasn't been created yetprotected void disableInternal()
throws OsgiContainerException,
IllegalPluginStateException
disableInternal in class AbstractPluginOsgiContainerException - If the OSGi system threw an exceptionIllegalPluginStateException - if the bundle hasn't been created yetprotected void uninstallInternal()
throws OsgiContainerException,
IllegalPluginStateException
uninstallInternal in class AbstractPluginOsgiContainerException - If the underlying OSGi system threw an exceptionIllegalPluginStateException - if the bundle hasn't been created yetpublic ContainerAccessor getContainerAccessor()
getContainerAccessor in interface ContainerManagedPluginCopyright © 2014 Atlassian. All rights reserved.