Class ComponentAccessor

java.lang.Object
com.atlassian.jira.component.ComponentAccessor

@PublicApi public class ComponentAccessor extends Object
Provides static methods for accessing JIRA's managed components — that is, the components in the PicoContainer.

Normally, developers should get the dependencies injected into the constructor of the calling class by Pico; however, this utility provides access for when that is impossible or impractical. Examples include:

  • Components with circular dependencies between them, as one of them must be resolved first without the other dependency available for injection yet
  • Classes that are not injectable components but are instead explicitly constructed in a long chain of classes that would not otherwise need the target component
  • Static-only utility classes, which are never constructed at all

Plugin developers that are trying to figure out how to fix an IllegalStateException that they are getting in a unit test should read the documentation for the MockComponentWorker in the jira-tests artifact for instructions.

Since:
v4.3
  • Constructor Details

    • ComponentAccessor

      public ComponentAccessor()
  • Method Details

    • getComponentSafely

      public static <T> Optional<T> getComponentSafely(Class<T> componentClass)
      Returns the core component which is stored in JIRA's Dependency Injection container under the key that is the given class, if and only if Pico is fully initialized and that component is present.

      This is equivalent to checking ComponentManager.getInstance().getState().isContainerInitialised() before retrieving the component and using Optional.empty() for all cases of being unable to resolve it.

      This paranoid usage is mainly of interest to very low-level code, such as custom Seraph authenticators or web filters, that might get accessed during system initialization or catastrophic error reporting (404.jsp, error500.jsp, or startup.jsp for example). Plugins generally should not have to worry about this because the Pico container is initialized before the plugin system is started.

      Parameters:
      componentClass - class to find a component instance by
      Returns:
      an Optional containing the requested component, or Optional.empty() if the component is not currently available
      Since:
      v7.0.0
    • safeSupplierOf

      @Nonnull public static <T> Supplier<Optional<T>> safeSupplierOf(Class<T> componentClass)
      Returns a "safe" supplier of the given component. Use this when you need to defer the lookup of that component until some later time.
      Type Parameters:
      T - the type of component
      Parameters:
      componentClass - the class of component
      Returns:
      a supplier that simply invokes getComponentSafely(Class)
      Since:
      7.4
    • getComponent

      public static <T> T getComponent(Class<T> componentClass)
      Returns the core component which is stored in JIRA's Dependency Injection container under the key that is the given class.

      In practise, this is the same as getComponentOfType(Class) except it will fail faster if the given Class is not a known component key (it also has a shorter and more meaningful name).

      Please note that this method only gets components from JIRA's core Pico Container. That is, it retrieves core components and components declared in Plugins1 plugins, but not components declared in Plugins2 plugins.

      Parameters:
      componentClass - class to find a component instance by
      Returns:
      the dependency injection component
      See Also:
    • supplierOf

      @Nonnull public static <T> Supplier<T> supplierOf(Class<T> componentClass)
      Returns a supplier of the given component. Use this when you need to defer the lookup of that component until some later time.
      Type Parameters:
      T - the type of component
      Parameters:
      componentClass - the class of component
      Returns:
      a supplier that simply invokes getComponent(Class)
      Since:
      7.4
    • getComponentReference

      @ExperimentalApi public static <T> ComponentReference<T> getComponentReference(@Nonnull Class<T> componentClass)
      Returns a thread-safe, Serializable lazy reference to the core component which is stored in JIRA's Dependency Injection container under the key that is the given class.

      WARNING: Component references obtained in this way must not be held past the lifetime of the Pico container, which is thrown away during a full system restore (import). Doing so causes the previous incarnation of the system to bleed across, leading to leaked memory, poor performance, and even inconsistent behaviour as components from the two separate Pico containers accidentally interact. This warning is generally not important to plugin developers, but should be respected by anyone working within jira-core, particularly when messing with filters, seraph authenticators, and other globally static objects.

      Parameters:
      componentClass - class to find a component instance by
      Returns:
      the dependency injection component reference
      Since:
      v6.3
      See Also:
    • getOsgiComponentReference

      @Deprecated @Internal public static <T> OsgiComponentReference<T> getOsgiComponentReference(@Nonnull Class<T> componentClass)
      Deprecated.
      Use getOSGiComponentInstanceOfType(Class) every time it is needed, instead. In the rare instances where this has unacceptable performance consequences, consider using a ServiceTracker or other similar enhanced access methods available through OSGi and through the plugin system in general. Since v7.0.0.
      Returns a thread-safe, Serializable lazy reference to the OSGi component under the key that is the given class.

      WARNING: This probably should not be used by any plugin developer. It effectively caches the result of calling getOSGiComponentInstanceOfType(Class), and as its documentation states, this is dangerous.

      Parameters:
      componentClass - class to find an OSGi component instance by
      Returns:
      the dependency injection component reference
      See Also:
    • getComponentOfType

      public static <T> T getComponentOfType(Class<T> componentClass)
      Returns the core component of the given Type (a Class or an Interface) which is stored in JIRA's Dependency Injection container.

      First it tries to find the component using the given Class as a key (like getComponent(Class)), however, if this fails then it will try to find a unique component that implements/extends the given Class. This seems unlikely to be useful, but is included for now, for completeness and backward compatibility.

      Please note that this method only gets components from JIRA's core Pico Container. That is, it retrieves core components and components declared in Plugins1 plugins, but not components declared in Plugins2 plugins.

      Parameters:
      componentClass - class to find a component instance by
      Returns:
      the dependency injection component
      See Also:
    • getOSGiComponentInstanceOfType

      public static <T> T getOSGiComponentInstanceOfType(Class<T> componentClass)
      Retrieves and returns a public component from OSGi land via its class name. This method can be used to retrieve a component provided via a plugins2 OSGi bundle. Please note that components returned via this method should NEVER be cached (for example, by saving it in a static field) as they may be refreshed at any time as a plugin is enabled/disabled or the componentManager is reinitialised (after an XML import).

      It is important to note that this only works for public components. That is components with public="true" declared in their XML configuration. This means that they are available for other plugins to import.

      A example use case for this method is the dashboards plugin. In several areas in JIRA we may want to render gadgets via the GadgetViewFactory. Whilst the interface for this component is available in JIRA core, the implementation is provided by the dashboards OSGi bundle. This method will allow us to access it.

      Note that if the osgiServiceTrackerCache is not available at the moment of calling inside ComponentManager, this method could throw an IllegalStateException.
      Parameters:
      componentClass - the class for which to find an OSGi component instance
      Returns:
      the found component or null if it does not exist
      See Also:
    • getOSGiComponentInstanceOfTypeSafely

      public static <T> Optional<T> getOSGiComponentInstanceOfTypeSafely(Class<T> componentClass)
      Retrieves and returns a public component from OSGi land via its class name in a safe manner. The difference compared to getOSGiComponentInstanceOfType(Class)} lies in using safe version of method from worker that handles exceptions and returns empty optional instead of null value.
      Parameters:
      componentClass - the class for which to find an OSGi component instance
      Returns:
      the found component or empty optional if it does not exist or if an exception was thrown inside worker
      See Also:
    • getProjectManager

      public static ProjectManager getProjectManager()
    • getApplicationProperties

      public static ApplicationProperties getApplicationProperties()
    • getJiraAuthenticationContext

      public static JiraAuthenticationContext getJiraAuthenticationContext()
    • getJiraDurationUtils

      public static JiraDurationUtils getJiraDurationUtils()
    • getConstantsManager

      public static ConstantsManager getConstantsManager()
    • getVelocityManager

      public static com.atlassian.velocity.VelocityManager getVelocityManager()
    • getVelocityParamFactory

      public static VelocityParamFactory getVelocityParamFactory()
    • getI18nHelperFactory

      public static I18nHelper.BeanFactory getI18nHelperFactory()
    • getFieldManager

      public static FieldManager getFieldManager()
    • getIssueManager

      public static IssueManager getIssueManager()
    • getAttachmentManager

      public static AttachmentManager getAttachmentManager()
    • getUserManager

      public static UserManager getUserManager()
    • getUserKeyService

      public static UserKeyService getUserKeyService()
    • getUserSearchService

      public static UserSearchService getUserSearchService()
    • getPermissionManager

      public static PermissionManager getPermissionManager()
    • getPermissionContextFactory

      public static PermissionContextFactory getPermissionContextFactory()
    • getCustomFieldManager

      public static CustomFieldManager getCustomFieldManager()
    • getFieldConfigSchemeManager

      public static FieldConfigSchemeManager getFieldConfigSchemeManager()
    • getUserUtil

      public static UserUtil getUserUtil()
    • getGroupManager

      public static GroupManager getGroupManager()
    • getEventTypeManager

      public static EventTypeManager getEventTypeManager()
    • getIssueEventManager

      public static IssueEventManager getIssueEventManager()
    • getWorkflowManager

      public static WorkflowManager getWorkflowManager()
    • getFieldScreenSchemeManager

      public static FieldScreenSchemeManager getFieldScreenSchemeManager()
    • getIssueFactory

      public static IssueFactory getIssueFactory()
    • getVersionManager

      public static VersionManager getVersionManager()
    • getCommentManager

      public static CommentManager getCommentManager()
    • getMailThreadManager

      public static MailThreadManager getMailThreadManager()
    • getWebResourceManager

      public static com.atlassian.webresource.api.WebResourceManager getWebResourceManager()
      Retrieves and returns the web resource manager instance
      Returns:
      web resource manager
    • getWebResourceUrlProvider

      public static com.atlassian.webresource.api.WebResourceUrlProvider getWebResourceUrlProvider()
      Retrieves and returns the web resource URL provider instance
      Returns:
      web resource URL provider
    • getBulkOperationManager

      public static BulkOperationManager getBulkOperationManager()
      Retrieves and return the bulk operation manager instance
      Returns:
      bulk operation manager
    • getMoveSubTaskOperationManager

      public static MoveSubTaskOperationManager getMoveSubTaskOperationManager()
      Retrieves and returns the move subtask operation manager instance
      Returns:
      move subtask operation manager
    • getWorklogManager

      public static WorklogManager getWorklogManager()
      Retrieves and returns the worklog manager instance
      Returns:
      worklog manager
    • getProjectFactory

      public static ProjectFactory getProjectFactory()
      Retrieves and returns the project factory instance
      Returns:
      project factory
    • getIssueTypeSchemeManager

      public static IssueTypeSchemeManager getIssueTypeSchemeManager()
      Retrieves and returns the issue type scheme manager instance
      Returns:
      issue type scheme manager
    • getIssueTypeScreenSchemeManager

      public static IssueTypeScreenSchemeManager getIssueTypeScreenSchemeManager()
      Retrieves and returns the issue type screen scheme manager instance
      Returns:
      issue type screen scheme manager
    • getSubTaskManager

      public static SubTaskManager getSubTaskManager()
      Retrieves and returns the subtask manager instance
      Returns:
      subtask manager
    • getIssueLinkManager

      public static IssueLinkManager getIssueLinkManager()
      Returns the IssueLinkManager component.
      Returns:
      the IssueLinkManager component.
    • getCrowdService

      public static com.atlassian.crowd.embedded.api.CrowdService getCrowdService()
    • getFieldLayoutManager

      public static FieldLayoutManager getFieldLayoutManager()
      Retrieves and returns the field layout manager
      Returns:
      field layout manager
    • getColumnLayoutManager

      public static ColumnLayoutManager getColumnLayoutManager()
      Retrieves and returns the column layout manager instance
      Returns:
      column layout manager
    • getVoteManager

      public static VoteManager getVoteManager()
      Retrieves and returns the vote manager instance
      Returns:
      vote manager
    • getPluginAccessor

      public static com.atlassian.plugin.PluginAccessor getPluginAccessor()
    • getPluginEventManager

      public static com.atlassian.plugin.event.PluginEventManager getPluginEventManager()
    • getComponentClassManager

      public static ComponentClassManager getComponentClassManager()
    • getPluginController

      public static com.atlassian.plugin.PluginController getPluginController()
    • getRendererManager

      public static RendererManager getRendererManager()
      Retrieves the RendererManager component.
      Returns:
      the RendererManager component.
    • getFieldScreenRendererFactory

      public static FieldScreenRendererFactory getFieldScreenRendererFactory()
      Retrieves and returns the field screen renderer factory instance
      Returns:
      field screen renderer factory
    • getWorkflowSchemeManager

      public static WorkflowSchemeManager getWorkflowSchemeManager()
      Retrieves and returns the workflow scheme manager instance
      Returns:
      workflow scheme manager
    • getIssueService

      public static IssueService getIssueService()
      Retrieves and returns the issue service instance
      Returns:
      issue service
    • getIndexPathManager

      public static IndexPathManager getIndexPathManager()
      Retrieves and returns the index path manager instance
      Returns:
      index path manager
    • getTranslationManager

      public static TranslationManager getTranslationManager()
      Retrieves and returns the translation manager instance
      Returns:
      translation manager
    • getWatcherManager

      public static WatcherManager getWatcherManager()
      Retrieves and returns the watcher manager instance
      Returns:
      watcher manager
    • getFieldScreenManager

      public static FieldScreenManager getFieldScreenManager()
      Retrieves and returns the field screen manager instance
      Returns:
      field screen manager
    • getMailServerManager

      public static com.atlassian.mail.server.MailServerManager getMailServerManager()
      Retrieves and returns the mail server manager instance
      Returns:
      mail server manager
    • getProjectComponentManager

      public static ProjectComponentManager getProjectComponentManager()
      Retrieves and returns the project component manager instance
      Returns:
      project component manager
    • getChangeHistoryManager

      public static ChangeHistoryManager getChangeHistoryManager()
      Retrieves and returns the ChangeHistoryManager manager instance
      Returns:
      ChangeHistoryManager
    • getUserPreferencesManager

      public static UserPreferencesManager getUserPreferencesManager()
      Retrieves and returns the user preferences manager instance
      Returns:
      user preferences manager
    • getUserPropertyManager

      public static UserPropertyManager getUserPropertyManager()
      Retrieves and returns the user preferences manager instance
      Returns:
      user preferences manager
    • getAvatarService

      public static AvatarService getAvatarService()
    • getAvatarManager

      public static AvatarManager getAvatarManager()
    • getListenerManager

      public static ListenerManager getListenerManager()
    • getMailQueue

      public static com.atlassian.mail.queue.MailQueue getMailQueue()
    • getNotificationSchemeManager

      public static NotificationSchemeManager getNotificationSchemeManager()
    • getPermissionSchemeManager

      public static PermissionSchemeManager getPermissionSchemeManager()
    • getIssueSecurityLevelManager

      public static IssueSecurityLevelManager getIssueSecurityLevelManager()
    • getServiceManager

      public static ServiceManager getServiceManager()
    • getSubscriptionManager

      public static SubscriptionManager getSubscriptionManager()
    • getGlobalPermissionManager

      public static GlobalPermissionManager getGlobalPermissionManager()
    • getLocaleManager

      public static LocaleManager getLocaleManager()
    • getOptionsManager

      public static OptionsManager getOptionsManager()
    • getOfBizDelegator

      public static OfBizDelegator getOfBizDelegator()
    • initialiseWorker

      @Internal public static ComponentAccessor.Worker initialiseWorker(ComponentAccessor.Worker componentAccessorWorker)
      This is called during system bootstrap to initialise this static helper class.

      Plugin developers should never call this in production code, although it is useful to put a mock Worker in here inside unit tests.

      Parameters:
      componentAccessorWorker - The worker that this static class delegates to in order to do actual work.
      Returns:
      the passed worker (a convenience for unit test method chaining)