Class OsgiPlugin
java.lang.Object
com.atlassian.plugin.impl.AbstractPlugin
com.atlassian.plugin.osgi.factory.OsgiPlugin
- All Implemented Interfaces:
ContainerManagedPlugin,OsgiBackedPlugin,Plugin,PluginInternal,Resourced,ScopeAware,Comparable<Plugin>
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
pluginArtifact -
Constructor Summary
ConstructorsConstructorDescriptionOsgiPlugin(String key, OsgiContainerManager mgr, PluginArtifact artifact, PluginArtifact originalPluginArtifact, com.atlassian.plugin.event.PluginEventManager pluginEventManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDisables the plugin by changing the bundle state back to resolvedprotected PluginStateEnables the plugin by setting the OSGi bundle state to enabled.org.osgi.framework.BundleReturnsOSGi Bundlethat corresponds to the current pluginDetermines which plugin keys are dependencies based on tracing the wires, categorising them as mandatory, optional or dynamic.getResource(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) voidvoidvoidvoidresolve()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, PluginArtifact artifact, 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
- Specified by:
getInstallationModein interfacePlugin- Overrides:
getInstallationModein classAbstractPlugin
-
isUninstallable
public boolean isUninstallable()- Specified by:
isUninstallablein interfacePlugin- Returns:
- true
-
isDynamicallyLoaded
public boolean isDynamicallyLoaded()- Specified by:
isDynamicallyLoadedin interfacePlugin- Returns:
- true
-
isDeleteable
public boolean isDeleteable()- Specified by:
isDeleteablein interfacePlugin- Returns:
- true
-
getDateInstalled
- Specified by:
getDateInstalledin interfacePlugin- Overrides:
getDateInstalledin classAbstractPlugin
-
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 interfacePlugin- Overrides:
setKeyin classAbstractPlugin
-
loadClass
- Specified by:
loadClassin interfacePlugin- 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 foundIllegalPluginStateException- if the bundle hasn't been created yet
-
getResource
- Specified by:
getResourcein interfacePlugin- Parameters:
name- The resource name- Returns:
- The resource URL, null if not found
- Throws:
IllegalPluginStateException- if the bundle hasn't been created yet
-
getResourceAsStream
- Specified by:
getResourceAsStreamin interfacePlugin- 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
-
getClassLoader
- Specified by:
getClassLoaderin interfacePlugin- Returns:
- The classloader to load classes and resources from the bundle
- Throws:
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:
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
-
onServiceDependencyWaitEnded
-
onServiceDependencyWaitEnded
-
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:
IllegalPluginStateException- If the plugin key hasn't been set yet
-
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 interfacePlugin- Overrides:
getDependenciesin classAbstractPlugin- Returns:
- not null, possibly empty
- Since:
- 4.0
- See Also:
-
toString
- Overrides:
toStringin classAbstractPlugin
-
installInternal
protected void installInternal()Installs the plugin artifact into OSGi- Overrides:
installInternalin classAbstractPlugin- Throws:
IllegalPluginStateException- if the bundle hasn't been created yet
-
enableInternal
Enables the plugin by setting the OSGi bundle state to enabled.- Overrides:
enableInternalin classAbstractPlugin- 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 stateIllegalPluginStateException- 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 classAbstractPlugin- Throws:
OsgiContainerException- If the OSGi system threw an exceptionIllegalPluginStateException- if the bundle hasn't been created yet
-
uninstallInternal
protected void uninstallInternal()Uninstalls the bundle from the OSGi container- Overrides:
uninstallInternalin classAbstractPlugin- Throws:
OsgiContainerException- If the underlying OSGi system threw an exceptionIllegalPluginStateException- if the bundle hasn't been created yet
-
getContainerAccessor
- Specified by:
getContainerAccessorin interfaceContainerManagedPlugin
-
resolve
public void resolve()- Specified by:
resolvein interfacePlugin- Overrides:
resolvein classAbstractPlugin
-