How to get JarPluginArtifact from JIRA Plugin object?

Vladimir Vasic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2013

When running JIRA plugin in debug mode, I can see originalPluginArtifact (JarPluginArtifact) from Plugin object in expressions window, but I can't get that property programmatically in code.
I need that in order to get jar file name (name of installed plugin jar file) based on given plugin key.
Eg:

plugin key -> tac.jira.languages.it_IT plugin jar file name -> plugin_3538044376309176990_jira-language-pack-it_IT-5.1.7-v2r22090-2012-10-15.jar

debug screen

2 answers

1 accepted

0 votes
Answer accepted
Vladimir Vasic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2013

I found out workaround. I got plugin directory path: ComponentAccessor.getComponent(JiraHome.class).getPluginsDirectory()

so I made a method which check every file name within that directory, if it contains specific substring which is predefined.

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

One solution I can think of (a little hacky in my opinion) is to try casting the Plugin to com.atlassian.plugin.impl.DefaultDynamicPlugin - something like that:

if(p instanceof DefaultDynamicPlugin) {
	File f = ((DefaultDynamicPlugin)p).getPluginArtifact().toFile();
	f.getName()
	....
}

Just out of curiosity - why do you need the plugin jar file ?

Vladimir Vasic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

Thanks for reply.

I need it cause I want to add some inputs in properties file which is located in jar archive (plugin). So in order to re-pack plugin I have to know its real filename on run time cause it is altered by jira sdk by adding something like plugin_353804437..._name_of_the_plugin.jar when you install plugin.

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2013

Not sure if this is your case but if you need some runtime data for the plugin maybe it's better to use Active Objects - https://developer.atlassian.com/display/DOCS/Active+Objects

Suggest an answer

Log in or Sign up to answer