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>

public class OsgiPlugin extends AbstractPlugin implements OsgiBackedPlugin, 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 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

  • 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 InstallationMode getInstallationMode()
      Specified by:
      getInstallationMode in interface Plugin
      Overrides:
      getInstallationMode in class AbstractPlugin
    • isUninstallable

      public boolean isUninstallable()
      Specified by:
      isUninstallable in interface Plugin
      Returns:
      true
    • isDynamicallyLoaded

      public boolean isDynamicallyLoaded()
      Specified by:
      isDynamicallyLoaded in interface Plugin
      Returns:
      true
    • isDeleteable

      public boolean isDeleteable()
      Specified by:
      isDeleteable in interface Plugin
      Returns:
      true
    • getDateInstalled

      public Date getDateInstalled()
      Specified by:
      getDateInstalled in interface Plugin
      Overrides:
      getDateInstalled in class 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 Plugin
      Overrides:
      setKey in class AbstractPlugin
    • loadClass

      public <T> Class<T> loadClass(String clazz, Class<?> callingClass) throws ClassNotFoundException
      Specified by:
      loadClass in interface 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
      IllegalPluginStateException - if the bundle hasn't been created yet
    • getResource

      public URL getResource(String name)
      Specified by:
      getResource in interface Plugin
      Parameters:
      name - The resource name
      Returns:
      The resource URL, null if not found
      Throws:
      IllegalPluginStateException - if the bundle hasn't been created yet
    • getResourceAsStream

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

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface Plugin
      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

      public void onServiceDependencyWaitStarting(PluginServiceDependencyWaitStartingEvent event)
    • onServiceDependencyWaitEnded

      public void onServiceDependencyWaitEnded(PluginServiceDependencyWaitEndedEvent event)
    • onServiceDependencyWaitEnded

      public void onServiceDependencyWaitEnded(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:
      IllegalPluginStateException - If the plugin key hasn't been set yet
    • getDependencies

      @Nonnull public 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 Plugin
      Overrides:
      getDependencies in class AbstractPlugin
      Returns:
      not null, possibly empty
      Since:
      4.0
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class AbstractPlugin
    • installInternal

      protected void installInternal()
      Installs the plugin artifact into OSGi
      Overrides:
      installInternal in class AbstractPlugin
      Throws:
      IllegalPluginStateException - if the bundle hasn't been created yet
    • enableInternal

      protected PluginState enableInternal()
      Enables the plugin by setting the OSGi bundle state to enabled.
      Overrides:
      enableInternal in class 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
      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 AbstractPlugin
      Throws:
      OsgiContainerException - If the OSGi system threw an exception
      IllegalPluginStateException - if the bundle hasn't been created yet
    • uninstallInternal

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

      public ContainerAccessor getContainerAccessor()
      Specified by:
      getContainerAccessor in interface ContainerManagedPlugin
    • resolve

      public void resolve()
      Specified by:
      resolve in interface Plugin
      Overrides:
      resolve in class AbstractPlugin