Recipes‎ > ‎Programming‎ > ‎

Jira Plugins

I'm using Eclipse 3.5 Galileo, following instructions per http://confluence.atlassian.com/display/DEVNET/Configuring+Eclipse+to+use+the+SDK

(0) Downloaded the Jira SDK and installed under ~/Jira/atlassian-plugin-sdk-3.0.5

(1) Installed m2eclipse plugin.  This required a considerable amount of searching for software install sources for a number of different projects.  I used these software sources to install the necessary packages from within the Eclipse software installer.

http://m2eclipse.sonatype.org/sites/m2e
http://download.eclipse.org/tools/gef/updates/
http://download.eclipse.org/modeling/emf/updates/
http://download.eclipse.org/webtools/updates/
http://download.eclipse.org/tools/ve/updates/1.4

(2) Set the Maven installation directory, as apparently you need to use the one supplied with the Jira SDK

(3) Now following instructions per http://confluence.atlassian.com/display/DEVNET/Developing+your+Plugin+using+the+Atlassian+Plugin+SDK

Added to ~/.bashrc:
export PATH=$PATH:~/Jira/atlassian-plugin-sdk-3.0.5/bin

$ mkdir ~/Jira/helloworld
$ cd !$
$ atlas-create-jira-plugin

groupId: com.[...].jira.plugins
artifactId: helloworld
version: 1.0-SNAPSHOT
package: com.[...].jira.plugins

$ atlas-run

Hurray!  The plugin appears in the plugins list.  A good moment, 4+ hours of work to get here.  (The default p/w appears to be admin/admin.)

(4) Actual plugin development!

... 4 hours later ...

ah har har har har only joking har har

atlassian-plugin.xml:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.artifactId}" plugins-version="2" class="com.insuremytrip.jira.plugins.TTPriorityField">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <resource type="velocity" name="column-view" location="templates/plugins/fields/view/view-ttpriority.vm"/>
        <resource type="velocity" name="xml" location="templates/plugins/fields/view/xml-ttpriority.vm"/>
    </plugin-info>
</atlassian-plugin>

TTPriorityField.java (copied from comments on the tutorial page):

package com.[...].jira.plugins;

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.comments.Comment;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.customfields.impl.CalculatedCFType;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.opensymphony.user.EntityNotFoundException;
import com.opensymphony.user.User;
import com.opensymphony.user.UserManager;
import java.util.List;

@SuppressWarnings("unchecked")
public  class TTPriorityField extends CalculatedCFType 
{
 
private JiraAuthenticationContext authenticationContext = null;
private CommentManager commentManager = null;
private UserManager userManager = null;
 
/**
* Picocontainer should populate this
* @see "http://confluence.atlassian.com/display/JIRA/PicoContainer+and+JIRA" />
* @param authenticationContext authentication Context
* @param commentManager comment Manager
* @param userManager user manager
*/
public TTPriorityField(JiraAuthenticationContext authenticationContext, CommentManager commentManager, UserManager userManager) {
this.authenticationContext = authenticationContext;
this.commentManager = commentManager;
this.userManager = userManager;
}
 
public Object getValueFromIssue(CustomField field, Issue issue) {
User lastUser = null;
List comments = commentManager.getCommentsForUser(issue, authenticationContext.getUser());
if(comments != null && !comments.isEmpty()) {
Comment lastComment = (Comment)comments.get(comments.size() - 1);
try {
lastUser = userManager.getUser(lastComment.getAuthor());
}
catch(EntityNotFoundException e) {
e.printStackTrace();
}
}
return lastUser;
}
 
/** not sure what this does...doesn't ever seem to get called...but must exist */
public String getStringFromSingularObject(Object customFieldObject) 
{
return customFieldObject.toString();
}
 
/** not sure what this does...doesn't ever seem to get called...but must exist */
public Object getSingularObjectFromString(String customFieldObject) 
{
return customFieldObject;
}
}

$ rm -rv target
$ atlas-compile
$ atlas-run

Comments