Class ComponentAccessor
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
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ApplicationProperties
static AttachmentManager
static AvatarManager
static AvatarService
static BulkOperationManager
Retrieves and return the bulk operation manager instancestatic ChangeHistoryManager
Retrieves and returns theChangeHistoryManager
manager instancestatic ColumnLayoutManager
Retrieves and returns the column layout manager instancestatic CommentManager
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.static ComponentClassManager
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.static <T> ComponentReference<T>
getComponentReference
(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.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.static ConstantsManager
static com.atlassian.crowd.embedded.api.CrowdService
static CustomFieldManager
static EventTypeManager
static FieldConfigSchemeManager
static FieldLayoutManager
Retrieves and returns the field layout managerstatic FieldManager
static FieldScreenManager
Retrieves and returns the field screen manager instancestatic FieldScreenRendererFactory
Retrieves and returns the field screen renderer factory instancestatic FieldScreenSchemeManager
static GlobalPermissionManager
static GroupManager
static I18nHelper.BeanFactory
static IndexPathManager
Retrieves and returns the index path manager instancestatic IssueEventManager
static IssueFactory
static IssueLinkManager
Returns the IssueLinkManager component.static IssueManager
static IssueSecurityLevelManager
static IssueService
Retrieves and returns the issue service instancestatic IssueTypeSchemeManager
Retrieves and returns the issue type scheme manager instancestatic IssueTypeScreenSchemeManager
Retrieves and returns the issue type screen scheme manager instancestatic JiraAuthenticationContext
static JiraDurationUtils
static ListenerManager
static LocaleManager
static com.atlassian.mail.queue.MailQueue
static com.atlassian.mail.server.MailServerManager
Retrieves and returns the mail server manager instancestatic MailThreadManager
static MoveSubTaskOperationManager
Retrieves and returns the move subtask operation manager instancestatic NotificationSchemeManager
static OfBizDelegator
static OptionsManager
static <T> T
getOSGiComponentInstanceOfType
(Class<T> componentClass) Retrieves and returns a public component from OSGi land via its class name.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.static <T> OsgiComponentReference<T>
getOsgiComponentReference
(Class<T> componentClass) Deprecated.static PermissionContextFactory
static PermissionManager
static PermissionSchemeManager
static com.atlassian.plugin.PluginAccessor
static com.atlassian.plugin.PluginController
static com.atlassian.plugin.event.PluginEventManager
static ProjectComponentManager
Retrieves and returns the project component manager instancestatic ProjectFactory
Retrieves and returns the project factory instancestatic ProjectManager
static RendererManager
Retrieves the RendererManager component.static ServiceManager
static SubscriptionManager
static SubTaskManager
Retrieves and returns the subtask manager instancestatic TranslationManager
Retrieves and returns the translation manager instancestatic UserKeyService
static UserManager
static UserPreferencesManager
Retrieves and returns the user preferences manager instancestatic UserPropertyManager
Retrieves and returns the user preferences manager instancestatic UserSearchService
static UserUtil
static com.atlassian.velocity.VelocityManager
static VelocityParamFactory
static VersionManager
static VoteManager
Retrieves and returns the vote manager instancestatic WatcherManager
Retrieves and returns the watcher manager instancestatic com.atlassian.webresource.api.WebResourceManager
Retrieves and returns the web resource manager instancestatic com.atlassian.webresource.api.WebResourceUrlProvider
Retrieves and returns the web resource URL provider instancestatic WorkflowManager
static WorkflowSchemeManager
Retrieves and returns the workflow scheme manager instancestatic WorklogManager
Retrieves and returns the worklog manager instancestatic ComponentAccessor.Worker
initialiseWorker
(ComponentAccessor.Worker componentAccessorWorker) This is called during system bootstrap to initialise this static helper class.safeSupplierOf
(Class<T> componentClass) Returns a "safe" supplier of the given component.static <T> Supplier<T>
supplierOf
(Class<T> componentClass) Returns a supplier of the given component.
-
Constructor Details
-
ComponentAccessor
public ComponentAccessor()
-
-
Method Details
-
getComponentSafely
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 usingOptional.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
, orstartup.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, orOptional.empty()
if the component is not currently available - Since:
- v7.0.0
-
safeSupplierOf
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
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
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.UsegetOSGiComponentInstanceOfType(Class)
every time it is needed, instead. In the rare instances where this has unacceptable performance consequences, consider using aServiceTracker
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
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
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
Note that if the osgiServiceTrackerCache is not available at the moment of calling insideGadgetViewFactory
. 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.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
Retrieves and returns a public component from OSGi land via its class name in a safe manner. The difference compared togetOSGiComponentInstanceOfType(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
-
getApplicationProperties
-
getJiraAuthenticationContext
-
getJiraDurationUtils
-
getConstantsManager
-
getVelocityManager
public static com.atlassian.velocity.VelocityManager getVelocityManager() -
getVelocityParamFactory
-
getI18nHelperFactory
-
getFieldManager
-
getIssueManager
-
getAttachmentManager
-
getUserManager
-
getUserKeyService
-
getUserSearchService
-
getPermissionManager
-
getPermissionContextFactory
-
getCustomFieldManager
-
getFieldConfigSchemeManager
-
getUserUtil
-
getGroupManager
-
getEventTypeManager
-
getIssueEventManager
-
getWorkflowManager
-
getFieldScreenSchemeManager
-
getIssueFactory
-
getVersionManager
-
getCommentManager
-
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
Retrieves and return the bulk operation manager instance- Returns:
- bulk operation manager
-
getMoveSubTaskOperationManager
Retrieves and returns the move subtask operation manager instance- Returns:
- move subtask operation manager
-
getWorklogManager
Retrieves and returns the worklog manager instance- Returns:
- worklog manager
-
getProjectFactory
Retrieves and returns the project factory instance- Returns:
- project factory
-
getIssueTypeSchemeManager
Retrieves and returns the issue type scheme manager instance- Returns:
- issue type scheme manager
-
getIssueTypeScreenSchemeManager
Retrieves and returns the issue type screen scheme manager instance- Returns:
- issue type screen scheme manager
-
getSubTaskManager
Retrieves and returns the subtask manager instance- Returns:
- subtask manager
-
getIssueLinkManager
Returns the IssueLinkManager component.- Returns:
- the IssueLinkManager component.
-
getCrowdService
public static com.atlassian.crowd.embedded.api.CrowdService getCrowdService() -
getFieldLayoutManager
Retrieves and returns the field layout manager- Returns:
- field layout manager
-
getColumnLayoutManager
Retrieves and returns the column layout manager instance- Returns:
- column layout manager
-
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
-
getPluginController
public static com.atlassian.plugin.PluginController getPluginController() -
getRendererManager
Retrieves the RendererManager component.- Returns:
- the RendererManager component.
-
getFieldScreenRendererFactory
Retrieves and returns the field screen renderer factory instance- Returns:
- field screen renderer factory
-
getWorkflowSchemeManager
Retrieves and returns the workflow scheme manager instance- Returns:
- workflow scheme manager
-
getIssueService
Retrieves and returns the issue service instance- Returns:
- issue service
-
getIndexPathManager
Retrieves and returns the index path manager instance- Returns:
- index path manager
-
getTranslationManager
Retrieves and returns the translation manager instance- Returns:
- translation manager
-
getWatcherManager
Retrieves and returns the watcher manager instance- Returns:
- watcher manager
-
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
Retrieves and returns the project component manager instance- Returns:
- project component manager
-
getChangeHistoryManager
Retrieves and returns theChangeHistoryManager
manager instance- Returns:
- ChangeHistoryManager
-
getUserPreferencesManager
Retrieves and returns the user preferences manager instance- Returns:
- user preferences manager
-
getUserPropertyManager
Retrieves and returns the user preferences manager instance- Returns:
- user preferences manager
-
getAvatarService
-
getAvatarManager
-
getListenerManager
-
getMailQueue
public static com.atlassian.mail.queue.MailQueue getMailQueue() -
getNotificationSchemeManager
-
getPermissionSchemeManager
-
getIssueSecurityLevelManager
-
getServiceManager
-
getSubscriptionManager
-
getGlobalPermissionManager
-
getLocaleManager
-
getOptionsManager
-
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)
-
getOSGiComponentInstanceOfType(Class)
every time it is needed, instead.