@PublicApi public class ComponentAccessor extends Object
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:
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.
Modifier and Type | Class and Description |
---|---|
static interface |
ComponentAccessor.Worker |
Constructor and Description |
---|
ComponentAccessor() |
Modifier and Type | Method and Description |
---|---|
static ApplicationProperties |
getApplicationProperties() |
static AttachmentManager |
getAttachmentManager() |
static AttachmentPathManager |
getAttachmentPathManager()
Retrieves and returns the attachment path instance
|
static AvatarManager |
getAvatarManager() |
static AvatarService |
getAvatarService() |
static BulkOperationManager |
getBulkOperationManager()
Retrieves and return the bulk operation manager instance
|
static ChangeHistoryManager |
getChangeHistoryManager()
Retrieves and returns the
ChangeHistoryManager manager instance |
static ColumnLayoutManager |
getColumnLayoutManager()
Retrieves and returns the column layout manager instance
|
static CommentManager |
getCommentManager() |
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 |
getComponentClassManager() |
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 |
getConstantsManager() |
static com.atlassian.crowd.embedded.api.CrowdService |
getCrowdService() |
static CustomFieldManager |
getCustomFieldManager() |
static EventTypeManager |
getEventTypeManager() |
static FieldConfigSchemeManager |
getFieldConfigSchemeManager() |
static FieldLayoutManager |
getFieldLayoutManager()
Retrieves and returns the field layout manager
|
static FieldManager |
getFieldManager() |
static FieldScreenManager |
getFieldScreenManager()
Retrieves and returns the field screen manager instance
|
static FieldScreenRendererFactory |
getFieldScreenRendererFactory()
Retrieves and returns the field screen renderer factory instance
|
static GlobalPermissionManager |
getGlobalPermissionManager() |
static GroupManager |
getGroupManager() |
static I18nHelper.BeanFactory |
getI18nHelperFactory() |
static IndexPathManager |
getIndexPathManager()
Retrieves and returns the index path manager instance
|
static IssueEventManager |
getIssueEventManager() |
static IssueFactory |
getIssueFactory() |
static IssueLinkManager |
getIssueLinkManager()
Returns the IssueLinkManager component.
|
static IssueManager |
getIssueManager() |
static IssueSecurityLevelManager |
getIssueSecurityLevelManager() |
static IssueService |
getIssueService()
Retrieves and returns the issue service instance
|
static IssueTypeSchemeManager |
getIssueTypeSchemeManager()
Retrieves and returns the issue type scheme manager instance
|
static IssueTypeScreenSchemeManager |
getIssueTypeScreenSchemeManager()
Retrieves and returns the issue type screen scheme manager instance
|
static JiraAuthenticationContext |
getJiraAuthenticationContext() |
static JiraDurationUtils |
getJiraDurationUtils() |
static ListenerManager |
getListenerManager() |
static LocaleManager |
getLocaleManager() |
static com.atlassian.mail.queue.MailQueue |
getMailQueue() |
static com.atlassian.mail.server.MailServerManager |
getMailServerManager()
Retrieves and returns the mail server manager instance
|
static MailThreadManager |
getMailThreadManager() |
static MoveSubTaskOperationManager |
getMoveSubTaskOperationManager()
Retrieves and returns the move subtask operation manager instance
|
static NotificationSchemeManager |
getNotificationSchemeManager() |
static OfBizDelegator |
getOfBizDelegator() |
static OptionsManager |
getOptionsManager() |
static <T> T |
getOSGiComponentInstanceOfType(Class<T> componentClass)
Retrieves and returns a public component from OSGi land via its class name.
|
static <T> OsgiComponentReference<T> |
getOsgiComponentReference(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. |
static PermissionContextFactory |
getPermissionContextFactory() |
static PermissionManager |
getPermissionManager() |
static PermissionSchemeManager |
getPermissionSchemeManager() |
static com.atlassian.plugin.PluginAccessor |
getPluginAccessor() |
static com.atlassian.plugin.PluginController |
getPluginController() |
static com.atlassian.plugin.event.PluginEventManager |
getPluginEventManager() |
static ProjectComponentManager |
getProjectComponentManager()
Retrieves and returns the project component manager instance
|
static ProjectFactory |
getProjectFactory()
Retrieves and returns the project factory instance
|
static ProjectManager |
getProjectManager() |
static RendererManager |
getRendererManager()
Retrieves the RendererManager component.
|
static ServiceManager |
getServiceManager() |
static SubscriptionManager |
getSubscriptionManager() |
static SubTaskManager |
getSubTaskManager()
Retrieves and returns the subtask manager instance
|
static TranslationManager |
getTranslationManager()
Retrieves and returns the translation manager instance
|
static UserKeyService |
getUserKeyService() |
static UserManager |
getUserManager() |
static UserPreferencesManager |
getUserPreferencesManager()
Retrieves and returns the user preferences manager instance
|
static UserPropertyManager |
getUserPropertyManager()
Retrieves and returns the user preferences manager instance
|
static UserSearchService |
getUserSearchService() |
static UserUtil |
getUserUtil() |
static com.atlassian.velocity.VelocityManager |
getVelocityManager() |
static VelocityParamFactory |
getVelocityParamFactory() |
static VersionManager |
getVersionManager() |
static VoteManager |
getVoteManager()
Retrieves and returns the vote manager instance
|
static WatcherManager |
getWatcherManager()
Retrieves and returns the watcher manager instance
|
static com.atlassian.plugin.webresource.WebResourceManager |
getWebResourceManager()
Retrieves and returns the web resource manager instance
|
static com.atlassian.plugin.webresource.WebResourceUrlProvider |
getWebResourceUrlProvider()
Retrieves and returns the web resource URL provider instance
|
static WorkflowManager |
getWorkflowManager() |
static WorkflowSchemeManager |
getWorkflowSchemeManager()
Retrieves and returns the workflow scheme manager instance
|
static WorklogManager |
getWorklogManager()
Retrieves and returns the worklog manager instance
|
static ComponentAccessor.Worker |
initialiseWorker(ComponentAccessor.Worker componentAccessorWorker)
This is called during system bootstrap to initialise this static helper class.
|
static <T> java.util.function.Supplier<Optional<T>> |
safeSupplierOf(Class<T> componentClass)
Returns a "safe" supplier of the given component.
|
static <T> java.util.function.Supplier<T> |
supplierOf(Class<T> componentClass)
Returns a supplier of the given component.
|
public static <T> Optional<T> getComponentSafely(Class<T> componentClass)
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.
componentClass
- class to find a component instance byOptional
containing the requested component, or Optional.empty()
if the
component is not currently available@Nonnull public static <T> java.util.function.Supplier<Optional<T>> safeSupplierOf(Class<T> componentClass)
T
- the type of componentcomponentClass
- the class of componentgetComponentSafely(Class)
public static <T> T getComponent(Class<T> componentClass)
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.
componentClass
- class to find a component instance bygetComponentOfType(Class)
,
getComponentSafely(Class)
@Nonnull public static <T> java.util.function.Supplier<T> supplierOf(Class<T> componentClass)
T
- the type of componentcomponentClass
- the class of componentgetComponent(Class)
@ExperimentalApi public static <T> ComponentReference<T> getComponentReference(@Nonnull Class<T> componentClass)
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.
componentClass
- class to find a component instance byComponentReference
@Deprecated @Internal public static <T> OsgiComponentReference<T> getOsgiComponentReference(@Nonnull Class<T> componentClass)
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.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.
componentClass
- class to find an OSGi component instance byOsgiComponentReference
public static <T> T getComponentOfType(Class<T> componentClass)
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.
componentClass
- class to find a component instance bygetComponent(Class)
,
getComponentSafely(Class)
public static <T> T getOSGiComponentInstanceOfType(Class<T> componentClass)
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.
componentClass
- the class for which to find an OSGi component instancenull
if it does not existgetComponentOfType(Class)
public static ProjectManager getProjectManager()
public static ApplicationProperties getApplicationProperties()
public static JiraAuthenticationContext getJiraAuthenticationContext()
public static JiraDurationUtils getJiraDurationUtils()
public static ConstantsManager getConstantsManager()
public static com.atlassian.velocity.VelocityManager getVelocityManager()
public static VelocityParamFactory getVelocityParamFactory()
public static I18nHelper.BeanFactory getI18nHelperFactory()
public static FieldManager getFieldManager()
public static IssueManager getIssueManager()
public static AttachmentManager getAttachmentManager()
public static UserManager getUserManager()
public static UserKeyService getUserKeyService()
public static UserSearchService getUserSearchService()
public static PermissionManager getPermissionManager()
public static PermissionContextFactory getPermissionContextFactory()
public static CustomFieldManager getCustomFieldManager()
public static FieldConfigSchemeManager getFieldConfigSchemeManager()
public static UserUtil getUserUtil()
public static GroupManager getGroupManager()
public static EventTypeManager getEventTypeManager()
public static IssueEventManager getIssueEventManager()
public static WorkflowManager getWorkflowManager()
public static IssueFactory getIssueFactory()
public static VersionManager getVersionManager()
public static CommentManager getCommentManager()
public static MailThreadManager getMailThreadManager()
public static com.atlassian.plugin.webresource.WebResourceManager getWebResourceManager()
public static com.atlassian.plugin.webresource.WebResourceUrlProvider getWebResourceUrlProvider()
public static BulkOperationManager getBulkOperationManager()
public static MoveSubTaskOperationManager getMoveSubTaskOperationManager()
public static WorklogManager getWorklogManager()
public static ProjectFactory getProjectFactory()
public static IssueTypeSchemeManager getIssueTypeSchemeManager()
public static IssueTypeScreenSchemeManager getIssueTypeScreenSchemeManager()
public static SubTaskManager getSubTaskManager()
public static IssueLinkManager getIssueLinkManager()
public static com.atlassian.crowd.embedded.api.CrowdService getCrowdService()
public static FieldLayoutManager getFieldLayoutManager()
public static ColumnLayoutManager getColumnLayoutManager()
public static VoteManager getVoteManager()
public static com.atlassian.plugin.PluginAccessor getPluginAccessor()
public static com.atlassian.plugin.event.PluginEventManager getPluginEventManager()
public static ComponentClassManager getComponentClassManager()
public static com.atlassian.plugin.PluginController getPluginController()
public static RendererManager getRendererManager()
public static FieldScreenRendererFactory getFieldScreenRendererFactory()
public static WorkflowSchemeManager getWorkflowSchemeManager()
public static IssueService getIssueService()
public static IndexPathManager getIndexPathManager()
public static AttachmentPathManager getAttachmentPathManager()
public static TranslationManager getTranslationManager()
public static WatcherManager getWatcherManager()
public static FieldScreenManager getFieldScreenManager()
public static com.atlassian.mail.server.MailServerManager getMailServerManager()
public static ProjectComponentManager getProjectComponentManager()
public static ChangeHistoryManager getChangeHistoryManager()
ChangeHistoryManager
manager instancepublic static UserPreferencesManager getUserPreferencesManager()
public static UserPropertyManager getUserPropertyManager()
public static AvatarService getAvatarService()
public static AvatarManager getAvatarManager()
public static ListenerManager getListenerManager()
public static com.atlassian.mail.queue.MailQueue getMailQueue()
public static NotificationSchemeManager getNotificationSchemeManager()
public static PermissionSchemeManager getPermissionSchemeManager()
public static IssueSecurityLevelManager getIssueSecurityLevelManager()
public static ServiceManager getServiceManager()
public static SubscriptionManager getSubscriptionManager()
public static GlobalPermissionManager getGlobalPermissionManager()
public static LocaleManager getLocaleManager()
public static OptionsManager getOptionsManager()
public static OfBizDelegator getOfBizDelegator()
@Internal public static ComponentAccessor.Worker initialiseWorker(ComponentAccessor.Worker componentAccessorWorker)
Plugin developers should never call this in production code, although it is useful to put a mock Worker in here inside unit tests.
componentAccessorWorker
- The worker that this static class delegates to in order to do actual work.Copyright © 2002-2021 Atlassian. All Rights Reserved.