我目前正在开发自定义JIRA插件,但在将插件集成到JIRA项目/问题管理系统时遇到了一些麻烦。我仅使用JIRA SDK已有约4个月的时间,所以我不是专家。
一些注意事项:
现在,我的代码当前正在发生的情况是createCustomField方法返回null。当我运行atlas-debug命令时,我可以看到(在cmd中)由于该方法而引发了空指针异常。因此未安装该插件。
这是我的代码:
public class PluginListener implements InitializingBean, DisposableBean {
private final IssueTypeManager issueTypeManager;
private final CustomFieldManager customFieldManager;
private final FieldScreenManager fieldScreenManager;
public PluginListener(IssueTypeManager issueTypeManager, CustomFieldManager customFieldManager, FieldScreenManager fieldScreenManager) {
this.issueTypeManager = issueTypeManager;
this.customFieldManager = customFieldManager;
this.fieldScreenManager = fieldScreenManager;
}
@Override
public void destroy() throws Exception {
// Handle plugin disabling or un-installation here
}
@Override
public void afterPropertiesSet() throws Exception {
// Handle plugin enabling or installation here
// Create issue type:
IssueType issueType = this.issueTypeManager.createIssueType("TheType", "TheDescription", "/images/icons/issuetypes/genericissue.png");
// Create custom field:
// Create a list of issue types for which the custom field needs to be available
List<GenericValue> issueTypes = new ArrayList<GenericValue>();
issueTypes.add(null);
// Create a list of project contexts for which the custom field needs to be available
List<JiraContextNode> contexts = new ArrayList<JiraContextNode>();
contexts.add(GlobalIssueContext.getInstance());
CustomFieldType fieldType = this.customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:textfield");
CustomFieldSearcher fieldSearcher = this.customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:textsearcher");
// Add custom field
final CustomField cField = this.customFieldManager.createCustomField("FOO", "BAR", fieldType, fieldSearcher, contexts, issueTypes);
// Add field to default Screen
FieldScreen defaultScreen = fieldScreenManager.getFieldScreen(FieldScreen.DEFAULT_SCREEN_ID);
if (!defaultScreen.containsField(cField.getId())) {
FieldScreenTab firstTab = defaultScreen.getTab(0);
firstTab.addFieldScreenLayoutItem(cField.getId());
}
}
}
运行atlas-debug
是从JIRA冷启动有效地安装插件。可能的问题是,在JIRA完全准备好操作和处理某些类型的请求之前,已安装JIRA插件(并激活了OSGi捆绑软件)。
要进行调试,请在您的atlas-debug运行失败后,尝试尝试手动导航至Toolgear-> Add-ons-> Manage add-ons,然后尝试重新上传插件.JAR(在target
目录中查找)。如果在那个时候能正常工作,则表明JIRA在初始系统启动时根本没有为插件做好准备,因此您需要将字段创建步骤移到其他地方。
您可以尝试onStart事件。如果这对您不起作用,则最可靠的方法可能是延迟初始化,只要您可以确保用户首次访问插件时就执行此步骤。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句