Hello,
I could not manage to register a module dynamically in Jira 10.
When trying to parse xml content (String) to create a dom4j.Element that I need for the method ComponentModuleDescriptor.init(com.atlassian.plugin.Plugin plugin, org.dom4j.Element element), I get the following error in Jira 10:
Caused by: java.lang.ClassCastException: class com.atlassian.core.xml.InterningDocumentFactory cannot be cast to class org.dom4j.DocumentFactory (com.atlassian.core.xml.InterningDocumentFactory is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @314b8f2d; org.dom4j.DocumentFactory is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @58cba9ac)
at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:92)
at org.dom4j.io.SAXReader.getDocumentFactory(SAXReader.java:667)
at org.dom4j.io.SAXReader.createContentHandler(SAXReader.java:948)
at org.dom4j.io.SAXReader.read(SAXReader.java:478)
Is there a new way to register a module dynamically in Jira 10?
Cheers,
Robin
2 Likes
ModuleDescriptor#init
signature has changed on platform 7, dom4j
is no longer used in Atlassian’s public API
Instead you must use the new com.atlassian.plugin.module.Element
class instead of org.dom4j.Element
To create an instance of com.atlassian.plugin.module.Element
from a plugin XML fragment you can use com.atlassian.plugin.osgi.factory.OsgiPluginXmlDescriptorParser
Here is some code we use in ScriptRunner that illustrates that (it’s Groovy, apologies…):
class PluginDescriptorParser {
List<Element> parse(String descriptor) {
def wrappedModuleDescriptor = "<atlassian-plugin>${descriptor}</atlassian-plugin>"
def descriptorParser = new OsgiPluginXmlDescriptorParser(IOUtils.toInputStream(wrappedModuleDescriptor, UTF_8), [] as Set)
descriptorParser.parseChildModulesFromSource()
}
}
Of course, this is a backwards incompatible change. If you want your app to work on older versions of Jira, you’ll need to dynamically call ModuleDescriptor#init
with the differing Element
types
If you don’t want to handle all this manually, Bitbucket is an option and lets you trivially register modules from a plugin XML fragment.
Hope that helps!
5 Likes
I’ve used the OsgiPluginXmlDescriptorParser object and the parse method. It works fine! Thank you for your help!
3 Likes