Replacing deprecated AbstractEditHandlerDetailsWebAction in Atlassian JIRA plugin for 7.X

旧城冷巷雨未停 提交于 2019-12-25 16:48:21

问题


I'm following Atlassian's Tutorial - Custom message (mail) handler for JIRA

I've hit a brick wall with the second to last step:

3) Create a new file named EditDemoHandlerDetailsWebAction.java in src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo directory, and give it the following contents:

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());
    }
}

The class inherits from AbstractEditHandlerDetailsWebAction which allows us to concentrate on parameter validation. It takes care of the add, edit, and cancel handler lifecycle itself.

This tutorial is supposed to support JIRA 5.0+ including the newest version up to 7.2

I am using JIRA 7.1.8

My problem is that maven is unable to locate the dependency for

import com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction;

After a TON of digging, I have found that com.atlassian.jira.plugins.mail exists in the specs for up to JIRA 5.1.8

However, in the specs for 5.2-m03 onward, this folder is not present, which is why maven cant find it.

Moreover, I can't find any information stating that these classes were deprecated nor any suggestion as to what I should replace this code with for my version of JIRA.

So, what can I use in place of the seemingly deprecated com.atlassian.jira.plugins.mail.webwork.AbstractEditHandlerDetailsWebAction; in the above class?


回答1:


For whatever reason, the version numbers of the JIRA mail plugin became dissociated from the version numbers of JIRA itself. You will be able to build the project once you ensure that you are referencing the correct version of the mail plugin.

I was able to get it to build as follows:

Clone the repo from the tutorial

git clone https://bitbucket.org/atlassian_tutorial/jira-add-email-handler.git

Figure out which version of the JIRA mail plugin is in use

You can do this easily by looking in the JIRA install directory. In my JIRA 7.1 install, the mail plugin was 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

Adjust the POM to correspond to the correct version of the mail plugin

Here is the patch I applied against the 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>

Fix other type issues

There is one other reference in DemoHandler that you'll have to change from User to ApplicationUser.

After that, it builds for me.



来源:https://stackoverflow.com/questions/39670569/replacing-deprecated-abstractedithandlerdetailswebaction-in-atlassian-jira-plugi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!