大家都知道,JIRA是一个优秀的问题跟踪系统。
但它不一定就能完全满足你的需要,比如导入Excel方式提交的BUG。
值得庆幸的是,JIRA提供了强大的插件开发功能,现说一说我的一点小经验。
准备: JIRA3.9, JIRA SDK, IDEA / Eclipse, 熟悉Java(废话), 熟悉WebWork
资料: http://confluence.atlassian.com/display/JIRA/JIRA+Development+Hub
官方资料可能无法全部找到你想要的,这时你可以下载一些其它第三方插件来分析其源码。
最重要的一点,那就是反编译JIRA代码,直接查看之。
比如,你想查看 /secure/IssueNavigator.jspa 的代码
打开 WEB-INF/classes/ actions.xml 查找 IssueNavigator ,如下:
<
action
name
="issue.IssueNavigator"
alias
="IssueNavigator"
>
< view name ="success" > /secure/views/navigator/navigator.jsp </ view >
< view name ="error" > /secure/views/navigator/navigator.jsp </ view >
</ action >
< view name ="success" > /secure/views/navigator/navigator.jsp </ view >
< view name ="error" > /secure/views/navigator/navigator.jsp </ view >
</ action >
表示其对应的类是 com.atlassian.jira.web.action.issue.IssueNavigator 反编译之即可。
以下说一说一些常用的方法:
JIRA提供各种 xxxManager 提口来实现各种操作
你可以通过 ComponentManager.getInstance().getXxx() 来得到其实例
也可以通过 ComponentManager.getComponentInstanceOfType(xxx.class) 来得到,非常方便。
比如:
JiraAuthenticationContext authenticationContext
=
ComponentManager.getInstance().getJiraAuthenticationContext();
ProjectComponentManager pcm = (ProjectComponentManager)ComponentManager.getComponentInstanceOfType(ProjectComponentManager. class );
ProjectComponentManager pcm = (ProjectComponentManager)ComponentManager.getComponentInstanceOfType(ProjectComponentManager. class );
例子:
public
static
User getCurrentUser()
{
JiraAuthenticationContext authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext();
return authenticationContext == null ? null : authenticationContext.getUser();
}
public static Project getProject( long pid) {
return ComponentManager.getInstance().getProjectManager().getProjectObj(pid);
}
public static MutableIssue getIssueById(Long id) {
try {
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
return issueManager.getIssueObject(id);
} catch (Exception e) {
return null;
}
}
JiraAuthenticationContext authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext();
return authenticationContext == null ? null : authenticationContext.getUser();
}
public static Project getProject( long pid) {
return ComponentManager.getInstance().getProjectManager().getProjectObj(pid);
}
public static MutableIssue getIssueById(Long id) {
try {
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
return issueManager.getIssueObject(id);
} catch (Exception e) {
return null;
}
}
把邮件加入JIRA队列:
Email mail
=
new
Email(toaddr);
MailQueueItem item = new SingleMailQueueItem(mail);
ManagerFactory.getMailQueue().addItem(item);
MailQueueItem item = new SingleMailQueueItem(mail);
ManagerFactory.getMailQueue().addItem(item);
另外你可以覆盖JIRA的Action,比如覆盖CreateSubTaskIssueDetails
让其在创建子任务时自动导入父任务的一些数据(如"所属模块")。
<
action
name
="jira.plugin.rstoolkit.webui.action.CreateSubTaskIssueDetails"
alias
="CreateSubTaskIssueDetails"
>
< view name ="error" > /secure/views/createsubtaskissue-details.jsp </ view >
< view name ="input" > /secure/views/createsubtaskissue-details.jsp </ view >
< view name ="init" > /rstoolkit/initsubtaskdetails.jsp </ view >
</ action >
< view name ="error" > /secure/views/createsubtaskissue-details.jsp </ view >
< view name ="input" > /secure/views/createsubtaskissue-details.jsp </ view >
< view name ="init" > /rstoolkit/initsubtaskdetails.jsp </ view >
</ action >
实在不想打字,其它的一些就不一一列举了。