Class OsgiPlugin
java.lang.Object
com.atlassian.plugin.impl.AbstractPlugin
com.atlassian.plugin.osgi.factory.OsgiPlugin
- All Implemented Interfaces:
com.atlassian.plugin.module.ContainerManagedPlugin,OsgiBackedPlugin,com.atlassian.plugin.Plugin,com.atlassian.plugin.PluginInternal,com.atlassian.plugin.Resourced,com.atlassian.plugin.ScopeAware,Comparable<com.atlassian.plugin.Plugin>
public class OsgiPlugin
extends com.atlassian.plugin.impl.AbstractPlugin
implements OsgiBackedPlugin, com.atlassian.plugin.module.ContainerManagedPlugin
Plugin that wraps an OSGi bundle that does contain a plugin descriptor. The actual bundle is not created until the
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringManifest key for the Atlassian plugin key entrystatic final StringManifest key for additional scan foldersstatic final StringManifest key denoting Atlassian remote pluginsFields inherited from class com.atlassian.plugin.impl.AbstractPlugin
pluginArtifactFields inherited from interface com.atlassian.plugin.Plugin
VERSION_1, VERSION_2, VERSION_3 -
Constructor Summary
ConstructorsConstructorDescriptionOsgiPlugin(String key, OsgiContainerManager mgr, com.atlassian.plugin.PluginArtifact artifact, com.atlassian.plugin.PluginArtifact originalPluginArtifact, com.atlassian.plugin.event.PluginEventManager pluginEventManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDisables the plugin by changing the bundle state back to resolvedprotected com.atlassian.plugin.PluginStateEnables the plugin by setting the OSGi bundle state to enabled.org.osgi.framework.BundleReturnsOSGi Bundlethat corresponds to the current plugincom.atlassian.plugin.module.ContainerAccessorcom.atlassian.plugin.PluginDependenciesDetermines which plugin keys are dependencies based on tracing the wires, categorising them as mandatory, optional or dynamic.com.atlassian.plugin.InstallationModegetResource(String name) getResourceAsStream(String name) protected voidInstalls the plugin artifact into OSGibooleanbooleanboolean<T> Class<T>voidonPluginContainerFailed(com.atlassian.plugin.event.events.PluginContainerFailedEvent event) Called when the plugin container for the bundle has failed to be created.voidonPluginContainerRefresh(com.atlassian.plugin.event.events.PluginContainerRefreshedEvent event) Called when the plugin container for the bundle has been created or refreshed.voidonPluginFrameworkShutdownEvent(com.atlassian.plugin.event.events.PluginFrameworkShutdownEvent event) voidonPluginFrameworkShuttingDownEvent(com.atlassian.plugin.event.events.PluginFrameworkShuttingDownEvent event) voidonPluginFrameworkStartedEvent(com.atlassian.plugin.event.events.PluginFrameworkStartedEvent event) voidonServiceDependencyWaitEnded(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitEndedEvent event) voidonServiceDependencyWaitEnded(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitTimedOutEvent event) voidonServiceDependencyWaitStarting(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitStartingEvent event) voidresolve()voidSets key to the specified value.toString()protected voidUninstalls the bundle from the OSGi containerMethods inherited from class com.atlassian.plugin.impl.AbstractPlugin
addDynamicModuleDescriptor, addModuleDescriptor, cleanVersionString, close, compareAndSetPluginState, compareTo, containsSystemModule, disable, enable, getActivePermissions, getDateEnabled, getDateEnabling, getDateLoaded, getDynamicModuleDescriptors, getI18nNameKey, getKey, getLog, getModuleDescriptor, getModuleDescriptors, getModuleDescriptorsByModuleClass, getName, getPluginArtifact, getPluginInformation, getPluginState, getPluginsVersion, getRequiredPlugins, getResourceDescriptor, getResourceDescriptors, getResourceLocation, getScopeKey, hasAllPermissions, install, isBundledPlugin, isEnabledByDefault, isSystemPlugin, removeDynamicModuleDescriptor, removeModuleDescriptor, setBundledPlugin, setEnabledByDefault, setI18nNameKey, setName, setPluginInformation, setPluginState, setPluginsVersion, setResources, setSystemPlugin, uninstallMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface com.atlassian.plugin.Plugin
addModuleDescriptor, containsSystemModule, disable, enable, getActivePermissions, getDateEnabled, getDateEnabling, getDateLoaded, getI18nNameKey, getKey, getModuleDescriptor, getModuleDescriptors, getModuleDescriptorsByModuleClass, getName, getPluginArtifact, getPluginInformation, getPluginState, getPluginsVersion, hasAllPermissions, install, isBundledPlugin, isEnabledByDefault, isSystemPlugin, setEnabledByDefault, setI18nNameKey, setName, setPluginInformation, setPluginsVersion, setResources, setSystemPlugin, uninstallMethods inherited from interface com.atlassian.plugin.Resourced
getResourceDescriptor, getResourceDescriptors, getResourceLocationMethods inherited from interface com.atlassian.plugin.ScopeAware
getScopeKey
-
Field Details
-
ATLASSIAN_PLUGIN_KEY
Manifest key for the Atlassian plugin key entry- See Also:
-
ATLASSIAN_SCAN_FOLDERS
Manifest key for additional scan folders- See Also:
-
REMOTE_PLUGIN_KEY
Manifest key denoting Atlassian remote plugins- See Also:
-
-
Constructor Details
-
OsgiPlugin
public OsgiPlugin(String key, OsgiContainerManager mgr, com.atlassian.plugin.PluginArtifact artifact, com.atlassian.plugin.PluginArtifact originalPluginArtifact, com.atlassian.plugin.event.PluginEventManager pluginEventManager)
-
-
Method Details
-
getBundle
public org.osgi.framework.Bundle getBundle()Description copied from interface:OsgiBackedPluginReturnsOSGi Bundlethat corresponds to the current pluginNote that
Bundlecould be not available on some ofPluginlifecycle stages. In that case method call results inIllegalPluginStateException- Specified by:
getBundlein interfaceOsgiBackedPlugin- Returns:
OSGirepresentation of the current plugin
-
getInstallationMode
public com.atlassian.plugin.InstallationMode getInstallationMode()- Specified by:
getInstallationModein interfacecom.atlassian.plugin.Plugin- Overrides:
getInstallationModein classcom.atlassian.plugin.impl.AbstractPlugin
-
isUninstallable
public boolean isUninstallable()- Specified by:
isUninstallablein interfacecom.atlassian.plugin.Plugin- Returns:
- true
-
isDynamicallyLoaded
public boolean isDynamicallyLoaded()- Specified by:
isDynamicallyLoadedin interfacecom.atlassian.plugin.Plugin- Returns:
- true
-
isDeleteable
public boolean isDeleteable()- Specified by:
isDeleteablein interfacecom.atlassian.plugin.Plugin- Returns:
- true
-
getDateInstalled
- Specified by:
getDateInstalledin interfacecom.atlassian.plugin.Plugin- Overrides:
getDateInstalledin classcom.atlassian.plugin.impl.AbstractPlugin
-
setKey
Sets key to the specified value. This mutator is inherited from Plugin, but should not be used as OsgiPlugin does not support having its key modified after initialization.- Specified by:
setKeyin interfacecom.atlassian.plugin.Plugin- Overrides:
setKeyin classcom.atlassian.plugin.impl.AbstractPlugin
-
loadClass
- Specified by:
loadClassin interfacecom.atlassian.plugin.Plugin- Type Parameters:
T- The class type- Parameters:
clazz- The name of the class to be loadedcallingClass- 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 foundcom.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
getResource
- Specified by:
getResourcein interfacecom.atlassian.plugin.Plugin- Parameters:
name- The resource name- Returns:
- The resource URL, null if not found
- Throws:
com.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
getResourceAsStream
- Specified by:
getResourceAsStreamin interfacecom.atlassian.plugin.Plugin- Parameters:
name- The name of the resource to be loaded.- Returns:
- Null if not found
- Throws:
com.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
getClassLoader
- Specified by:
getClassLoaderin interfacecom.atlassian.plugin.Plugin- Returns:
- The classloader to load classes and resources from the bundle
- Throws:
com.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
onPluginContainerFailed
public void onPluginContainerFailed(com.atlassian.plugin.event.events.PluginContainerFailedEvent event) Called when the plugin container for the bundle has failed to be created. This means the bundle is still active, but the plugin container is not available, so the plugin will be disabled.- Parameters:
event- The plugin container failed event- Throws:
com.atlassian.plugin.IllegalPluginStateException- If the plugin key hasn't been set yet
-
onPluginFrameworkStartedEvent
public void onPluginFrameworkStartedEvent(com.atlassian.plugin.event.events.PluginFrameworkStartedEvent event) -
onPluginFrameworkShutdownEvent
public void onPluginFrameworkShutdownEvent(com.atlassian.plugin.event.events.PluginFrameworkShutdownEvent event) -
onPluginFrameworkShuttingDownEvent
public void onPluginFrameworkShuttingDownEvent(com.atlassian.plugin.event.events.PluginFrameworkShuttingDownEvent event) -
onServiceDependencyWaitStarting
public void onServiceDependencyWaitStarting(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitStartingEvent event) -
onServiceDependencyWaitEnded
public void onServiceDependencyWaitEnded(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitEndedEvent event) -
onServiceDependencyWaitEnded
public void onServiceDependencyWaitEnded(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitTimedOutEvent event) -
onPluginContainerRefresh
public void onPluginContainerRefresh(com.atlassian.plugin.event.events.PluginContainerRefreshedEvent event) Called when the plugin container 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:
com.atlassian.plugin.IllegalPluginStateException- If the plugin key hasn't been set yet
-
getDependencies
@Nonnull public com.atlassian.plugin.PluginDependencies getDependencies()Determines which plugin keys are dependencies based on tracing the wires, categorising them as mandatory, optional or dynamic.Namespace.RESOLUTION_OPTIONALandPackageNamespace.RESOLUTION_DYNAMICare mapped to optional and dynamic, respectively. Any others are mapped to mandatory.- Specified by:
getDependenciesin interfacecom.atlassian.plugin.Plugin- Overrides:
getDependenciesin classcom.atlassian.plugin.impl.AbstractPlugin- Returns:
- not null, possibly empty
- Since:
- 4.0
- See Also:
-
Plugin.getDependencies()
-
toString
- Overrides:
toStringin classcom.atlassian.plugin.impl.AbstractPlugin
-
installInternal
protected void installInternal()Installs the plugin artifact into OSGi- Overrides:
installInternalin classcom.atlassian.plugin.impl.AbstractPlugin- Throws:
com.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
enableInternal
protected com.atlassian.plugin.PluginState enableInternal()Enables the plugin by setting the OSGi bundle state to enabled.- Overrides:
enableInternalin classcom.atlassian.plugin.impl.AbstractPlugin- Returns:
PluginState.ENABLEDif the container is being refreshed orPluginState.ENABLINGif we are waiting on a plugin container (first time being activated, as all subsequent times are considered refreshes)- Throws:
OsgiContainerException- If the underlying OSGi system threw an exception or we tried to enable the bundle when it was in an invalid statecom.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
disableInternal
protected void disableInternal()Disables the plugin by changing the bundle state back to resolved- Overrides:
disableInternalin classcom.atlassian.plugin.impl.AbstractPlugin- Throws:
OsgiContainerException- If the OSGi system threw an exceptioncom.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
uninstallInternal
protected void uninstallInternal()Uninstalls the bundle from the OSGi container- Overrides:
uninstallInternalin classcom.atlassian.plugin.impl.AbstractPlugin- Throws:
OsgiContainerException- If the underlying OSGi system threw an exceptioncom.atlassian.plugin.IllegalPluginStateException- if the bundle hasn't been created yet
-
getContainerAccessor
public com.atlassian.plugin.module.ContainerAccessor getContainerAccessor()- Specified by:
getContainerAccessorin interfacecom.atlassian.plugin.module.ContainerManagedPlugin
-
resolve
public void resolve()- Specified by:
resolvein interfacecom.atlassian.plugin.Plugin- Overrides:
resolvein classcom.atlassian.plugin.impl.AbstractPlugin
-