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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Manifest key for the Atlassian plugin key entry
    static final String
    Manifest key for additional scan folders
    static final String
    Manifest key denoting Atlassian remote plugins

    Fields inherited from class com.atlassian.plugin.impl.AbstractPlugin

    pluginArtifact

    Fields inherited from interface com.atlassian.plugin.Plugin

    VERSION_1, VERSION_2, VERSION_3
  • Constructor Summary

    Constructors
    Constructor
    Description
    OsgiPlugin(String key, OsgiContainerManager mgr, com.atlassian.plugin.PluginArtifact artifact, com.atlassian.plugin.PluginArtifact originalPluginArtifact, com.atlassian.plugin.event.PluginEventManager pluginEventManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Disables the plugin by changing the bundle state back to resolved
    protected com.atlassian.plugin.PluginState
    Enables the plugin by setting the OSGi bundle state to enabled.
    org.osgi.framework.Bundle
    Returns OSGi Bundle that corresponds to the current plugin
     
    com.atlassian.plugin.module.ContainerAccessor
     
     
    com.atlassian.plugin.PluginDependencies
    Determines which plugin keys are dependencies based on tracing the wires, categorising them as mandatory, optional or dynamic.
    com.atlassian.plugin.InstallationMode
     
     
     
    protected void
    Installs the plugin artifact into OSGi
    boolean
     
    boolean
     
    boolean
     
    <T> Class<T>
    loadClass(String clazz, Class<?> callingClass)
     
    void
    onPluginContainerFailed(com.atlassian.plugin.event.events.PluginContainerFailedEvent event)
    Called when the plugin container for the bundle has failed to be created.
    void
    onPluginContainerRefresh(com.atlassian.plugin.event.events.PluginContainerRefreshedEvent event)
    Called when the plugin container for the bundle has been created or refreshed.
    void
    onPluginFrameworkShutdownEvent(com.atlassian.plugin.event.events.PluginFrameworkShutdownEvent event)
     
    void
    onPluginFrameworkShuttingDownEvent(com.atlassian.plugin.event.events.PluginFrameworkShuttingDownEvent event)
     
    void
    onPluginFrameworkStartedEvent(com.atlassian.plugin.event.events.PluginFrameworkStartedEvent event)
     
    void
    onServiceDependencyWaitEnded(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitEndedEvent event)
     
    void
    onServiceDependencyWaitEnded(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitTimedOutEvent event)
     
    void
    onServiceDependencyWaitStarting(com.atlassian.plugin.osgi.event.PluginServiceDependencyWaitStartingEvent event)
     
    void
     
    void
    Sets key to the specified value.
     
    protected void
    Uninstalls the bundle from the OSGi container

    Methods 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, uninstall

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Comparable

    compareTo

    Methods 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, uninstall

    Methods inherited from interface com.atlassian.plugin.Resourced

    getResourceDescriptor, getResourceDescriptors, getResourceLocation

    Methods inherited from interface com.atlassian.plugin.ScopeAware

    getScopeKey
  • Field Details

    • ATLASSIAN_PLUGIN_KEY

      public static final String ATLASSIAN_PLUGIN_KEY
      Manifest key for the Atlassian plugin key entry
      See Also:
    • ATLASSIAN_SCAN_FOLDERS

      public static final String ATLASSIAN_SCAN_FOLDERS
      Manifest key for additional scan folders
      See Also:
    • REMOTE_PLUGIN_KEY

      public static final String 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: OsgiBackedPlugin
      Returns OSGi Bundle that corresponds to the current plugin

      Note that Bundle could be not available on some of Plugin lifecycle stages. In that case method call results in IllegalPluginStateException

      Specified by:
      getBundle in interface OsgiBackedPlugin
      Returns:
      OSGi representation of the current plugin
    • getInstallationMode

      public com.atlassian.plugin.InstallationMode getInstallationMode()
      Specified by:
      getInstallationMode in interface com.atlassian.plugin.Plugin
      Overrides:
      getInstallationMode in class com.atlassian.plugin.impl.AbstractPlugin
    • isUninstallable

      public boolean isUninstallable()
      Specified by:
      isUninstallable in interface com.atlassian.plugin.Plugin
      Returns:
      true
    • isDynamicallyLoaded

      public boolean isDynamicallyLoaded()
      Specified by:
      isDynamicallyLoaded in interface com.atlassian.plugin.Plugin
      Returns:
      true
    • isDeleteable

      public boolean isDeleteable()
      Specified by:
      isDeleteable in interface com.atlassian.plugin.Plugin
      Returns:
      true
    • getDateInstalled

      public Date getDateInstalled()
      Specified by:
      getDateInstalled in interface com.atlassian.plugin.Plugin
      Overrides:
      getDateInstalled in class com.atlassian.plugin.impl.AbstractPlugin
    • setKey

      public void setKey(String key)
      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:
      setKey in interface com.atlassian.plugin.Plugin
      Overrides:
      setKey in class com.atlassian.plugin.impl.AbstractPlugin
    • loadClass

      public <T> Class<T> loadClass(String clazz, Class<?> callingClass) throws ClassNotFoundException
      Specified by:
      loadClass in interface com.atlassian.plugin.Plugin
      Type Parameters:
      T - The class type
      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
      com.atlassian.plugin.IllegalPluginStateException - if the bundle hasn't been created yet
    • getResource

      public URL getResource(String name)
      Specified by:
      getResource in interface com.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

      public InputStream getResourceAsStream(String name)
      Specified by:
      getResourceAsStream in interface com.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

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface com.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_OPTIONAL and PackageNamespace.RESOLUTION_DYNAMIC are mapped to optional and dynamic, respectively. Any others are mapped to mandatory.
      Specified by:
      getDependencies in interface com.atlassian.plugin.Plugin
      Overrides:
      getDependencies in class com.atlassian.plugin.impl.AbstractPlugin
      Returns:
      not null, possibly empty
      Since:
      4.0
      See Also:
      • Plugin.getDependencies()
    • toString

      public String toString()
      Overrides:
      toString in class com.atlassian.plugin.impl.AbstractPlugin
    • installInternal

      protected void installInternal()
      Installs the plugin artifact into OSGi
      Overrides:
      installInternal in class com.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:
      enableInternal in class com.atlassian.plugin.impl.AbstractPlugin
      Returns:
      PluginState.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)
      Throws:
      OsgiContainerException - If the underlying OSGi system threw an exception or we tried to enable the bundle when it was in an invalid state
      com.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:
      disableInternal in class com.atlassian.plugin.impl.AbstractPlugin
      Throws:
      OsgiContainerException - If the OSGi system threw an exception
      com.atlassian.plugin.IllegalPluginStateException - if the bundle hasn't been created yet
    • uninstallInternal

      protected void uninstallInternal()
      Uninstalls the bundle from the OSGi container
      Overrides:
      uninstallInternal in class com.atlassian.plugin.impl.AbstractPlugin
      Throws:
      OsgiContainerException - If the underlying OSGi system threw an exception
      com.atlassian.plugin.IllegalPluginStateException - if the bundle hasn't been created yet
    • getContainerAccessor

      public com.atlassian.plugin.module.ContainerAccessor getContainerAccessor()
      Specified by:
      getContainerAccessor in interface com.atlassian.plugin.module.ContainerManagedPlugin
    • resolve

      public void resolve()
      Specified by:
      resolve in interface com.atlassian.plugin.Plugin
      Overrides:
      resolve in class com.atlassian.plugin.impl.AbstractPlugin