我正在关注Atlassian's Tutorial - Custom message (mail) handler for JIRA
我用倒数第二步击中了一堵砖墙:
3)在src / main / java / com / example / plugins / tutorial / jira / mailhandlerdemo目录中创建一个名为EditDemoHandlerDetailsWebAction.java的新文件,并为其提供以下内容:
package com.example.plugins.tutorial.jira.mailhandlerdemo;
import com.atlassian.configurable.ObjectConfigurationException;
import com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction;
import com.atlassian.jira.service.JiraServiceContainer;
import com.atlassian.jira.service.services.file.AbstractMessageHandlingService;
import com.atlassian.jira.service.util.ServiceUtils;
import com.atlassian.jira.util.collect.MapBuilder;
import com.atlassian.plugin.PluginAccessor;
import java.util.Map;
public class EditDemoHandlerDetailsWebAction extends AbstractEditHandlerDetailsWebAction {
private final IssueKeyValidator issueKeyValidator;
public EditDemoHandlerDetailsWebAction(PluginAccessor pluginAccessor, IssueKeyValidator issueKeyValidator) {
super(pluginAccessor);
this.issueKeyValidator = issueKeyValidator;
}
private String issueKey;
public String getIssueKey() {
return issueKey;
}
public void setIssueKey(String issueKey) {
this.issueKey = issueKey;
}
// this method is called to let us populate our variables (or action state)
// with current handler settings managed by associated service (file or mail).
@Override
protected void copyServiceSettings(JiraServiceContainer jiraServiceContainer) throws ObjectConfigurationException {
final String params = jiraServiceContainer.getProperty(AbstractMessageHandlingService.KEY_HANDLER_PARAMS);
final Map<String, String> parameterMap = ServiceUtils.getParameterMap(params);
issueKey = parameterMap.get(DemoHandler.KEY_ISSUE_KEY);
}
@Override
protected Map<String, String> getHandlerParams() {
return MapBuilder.build(DemoHandler.KEY_ISSUE_KEY, issueKey);
}
@Override
protected void doValidation() {
if (configuration == null) {
return; // short-circuit in case we lost session, goes directly to doExecute which redirects user
}
super.doValidation();
issueKeyValidator.validateIssue(issueKey, new WebWorkErrorCollector());
}
}
该类继承自AbstractEditHandlerDetailsWebAction,它允许我们专注于参数验证。它负责添加,编辑和取消处理程序生命周期本身。
本教程应支持JIRA 5.0+,包括最新版本7.2
我正在使用JIRA 7.1.8
我的问题是maven无法找到依赖项
import com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction;
经过一次挖掘,我发现了com.atlassian.jira.plugins.mail
exists in the specs for up to JIRA 5.1.8
然而,in the specs for 5.2-m03向前,这个文件夹不存在,这就是为什么maven找不到它。
此外,我找不到任何信息表明这些类已被弃用,也没有任何关于我应该用我的JIRA版本替换此代码的建议。
那么,我可以用什么来代替上面这个看似被弃用的com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction;
呢?
无论出于何种原因,JIRA邮件插件的版本号与JIRA本身的版本号分离。一旦确保引用正确版本的邮件插件,就可以构建项目。
我能够按如下方式构建它:
git clone https://bitbucket.org/atlassian_tutorial/jira-add-email-handler.git
您可以通过查看JIRA安装目录轻松完成此操作。在我的JIRA 7.1安装中,邮件插件是v9.0.3:
$ find <PATH_TO_JIRA_INSTALL>/atlassian-jira -name '*jira-mail-plugin*.jar'
<your path here>/atlassian-jira/WEB-INF/atlassian-bundled-plugins/jira-mail-plugin-9.0.3.jar
这是我对pom.xml应用的补丁:
diff --git a/pom.xml b/pom.xml
index f493ef2..a3bbb8f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,7 @@
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-mail-plugin</artifactId>
- <version>${jira.version}</version>
+ <version>${jira.mail.plugin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -104,8 +104,9 @@
</build>
<properties>
- <jira.version>6.0.4</jira.version>
- <amps.version>4.2.0</amps.version>
+ <jira.version>7.1.8</jira.version>
+ <jira.mail.plugin.version>9.0.3</jira.mail.plugin.version> <!-- the version of the mail plugin shipped with your version of JIRA -->
+ <amps.version>5.0.4</amps.version> <!-- Adjust this to the specific version of the plugin SDK you have installed -->
<plugin.testrunner.version>1.1.1</plugin.testrunner.version>
<!-- TestKit version 5.x for JIRA 5.x, 6.x for JIRA 6.x -->
<testkit.version>5.2.26</testkit.version>
在DemoHandler中还有另一个参考,你必须从User
更改为ApplicationUser
。
在那之后,它为我建立。