JIRA 4.3 : Customising JIRA code
This page last changed on Mar 03, 2011 by rosie@atlassian.com.
When customising JIRA, it is sometimes necessary to make code modifications. Most classes in JIRA conform to an interface (eg. the Webwork action classes, and *Manager classes), so it is possible to write your own implementation of JIRA interfaces and use yours instead of the default. This page describes the basics of how to plug modified classes into JIRA with minimal pain. PicocontainerJIRA uses Picocontainer as a central object factory. Picocontainer is responsible for instantiating objects and resolving their constructor dependencies. This greatly simplifies code, in that any Picocontainer-instantiated object (eg. a Webwork action) can obtain an instance of another (eg. a Manager class) simply by requesting one in its constructor. PicoContainer will ensure each object required in the constructor is passed in (aka dependency injection). Eg. the ViewIssue action: ViewIssue.java Non-managed classesClasses not managed by Picocontainer (eg. workflow conditions / functions, Services and Listeners, or JSP scriptlets) can still get pico-instantiated objects statically using static methods on ComponentManager. For example: Register new Picocontainer-managed classesPicocontainer-managed classes need to be registered with Picocontainer. This happens automatically for Webwork actions, but other classes need to be registered manually. This is done in ComponentRegistrar's registerComponents() method: ComponentManager.java Components can either by INTERNAL meaning that they will be available only to JIRA itself or PROVIDED in which case they will also be available to plugins2 plugins. Components are generally only registered in the ComponentRegistrar, if they are required in JIRA internally. Plugin writers who wish to write to write their own components that can be injected in their plugin's classes should use the component plugin module . If you wanted to register your overridden version of a pico-registered class, you could just register yours instead of the default in ComponentRegistrar above. Overriding components in JIRA with an extension pico-container
Sometimes it may be necessary for a plugin writer to override a component that JIRA ships with to provide some custom behaviour. You can do this by providing an extension pico container via a jira-application.properties property. In jira-application.properties, register an extension container provider: jira.extension.container.provider = com.mycompany.jira.MyContainerProvider In this class, you can register your own implementations of interfaces, which will be used in preference to the defaults in ComponentManager: MyContainerProvider.java package com.mycompany.jira; import org.picocontainer.PicoContainer; import org.picocontainer.defaults.DefaultPicoContainer; import com.atlassian.jira.config.component.ProfilingComponentAdapterFactory; import com.atlassian.jira.web.action.issue.BugAssociatorPrefs; import com.atlassian.jira.security.PermissionManager; import com.atlassian.jira.permission.PermissionSchemeManager; import com.mycompany.jira.MyBugAssociatorPrefs; import com.mycompany.jira.MyPermissionManager; import com.mycompany.jira.MyPermissionSchemeManager; public class MyContainerProvider implements ContainerProvider { private DefaultPicoContainer container; public PicoContainer getContainer(PicoContainer parent) { if (container == null) buildContainer(parent); return container; } private void buildContainer(PicoContainer parent) { this.container = new DefaultPicoContainer(new ProfilingComponentAdapterFactory(), parent); container.registerComponentImplementation(BugAssociatorPrefs.class, MyBugAssociatorPrefs.class); container.registerComponentImplementation(PermissionManager.class, MyPermissionManager.class); container.registerComponentImplementation(PermissionSchemeManager.class, MyPermissionSchemeManager.class); } } Here we have registered our own implementations of three classes, after delegating to the default (so ours will take precedence). You can now keep MyContainerProvider and your modified com.mycompany.jira.* classes in their own jar, which can be dropped into any JIRA instance to customize it to your needs. |
![]() |
Document generated by Confluence on Mar 27, 2011 18:54 |