Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Accessing params from plugin-info section in atlassian-plugin.xml

Charles Duffy
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 7, 2012

The plugin descriptor documentation specifies that parameters to a plugin can be created in the descriptor, as such:

<atlassian-plugin>
<plugin-info>
<param name="key">value</param>
<param name="key2">value2</param>
....
</plugin-info>
</atlassian-plugin>

However, I'm having trouble finding documentation on how to retrieve or access these parameters. I suspect that they might be the key/value pairs exposed through com.atlassian.plugin.PluginInformation.getParameters(), but the canonical mechanism for retrieving the PluginInformation object for the active plugin (without needing to have the plugin's key embedded in the source) is unclear.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Charles Duffy
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 7, 2012

This can in fact be done.

First, add a dependency on atlassian-plugins-osgi-bridge to your pom.xml:

&lt;dependency&gt;
  &lt;groupId&gt;com.atlassian.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;atlassian-plugins-osgi-bridge&lt;/artifactId&gt;
  &lt;version&gt;2.10.1&lt;/version&gt;
  &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

Add a component import to your pom.xml:

&lt;component-import
 key="plugin-retrieval-service"
 interface="com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService"/&gt;

Finally, retrieve a PluginRetrievalService instance through constructor dependency injection, and use it to access the parameter map:

import com.atlassian.plugin.Plugin;
import com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService;

public class YourComponent {
  public YourComponent(PluginRetrievalService prs) {
    Plugin plugin = prs.getPlugin();
    Map&lt;String,String&gt; params = plugin
      .getPluginInformation()
      .getParameters();
    String key  = params.get("key");
    String key2 = params.get("key2");
  }
}

Tyler Wright April 11, 2013

How can I get access to that package: com.atlassian.plugin.osgi.bridge.external.PluginRetrievalService? I can't find what jar its in.

2 votes
MB
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 9, 2013

I've managed to accomplish this using one-liner:

Map params = ComponentAccessor.getPluginAccessor().getPlugin("com.example.jira.plugin.test").getModuleDescriptor("myModule").getParams();
String s = params.get("param1").toString();
...

but I'm not sure if that's JIRA 6.x specific or it can work in JIRA 5.x too. My atlassian-plugin.xml looks like this:

&lt;atlassian-plugin key="com.example.jira.plugin.test" name="test plugin" plugins-version="2"&gt;
	&lt;plugin-info&gt;
		&lt;description&gt;${project.description}&lt;/description&gt;
		&lt;version&gt;${project.version}&lt;/version&gt;
		&lt;vendor name="${project.organization.name}" url="${project.organization.url}" /&gt;
	&lt;/plugin-info&gt;
	&lt;component key="myModule" class="com.example.jira.plugin.myModule"&gt;
		&lt;description&gt;Test Class.&lt;/description&gt;
		&lt;param name="param1" value="value1" /&gt;
		&lt;param name="param2" value="value2 blah" /&gt;
	&lt;/component&gt;
&lt;/atlassian-plugin&gt;
0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2012

Jira saves the values for you, then in the actual plugin, you can use code like

ParameterUtils.getStringParam(params, "key2")

Assuming key2 is a string of course.

Charles Duffy
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 7, 2012

Where does "params" come from in this example? To be clear -- I'm implementing a generic component, not a WebAction or similar interface where a parameter map is specified as part of the calling convention.

Charles Duffy
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 7, 2012

Err, "add handling for the parameters" isn't helpful until/unless I know how to get access to them through the plugin API -- can't handle something I don't know how to retrieve... hence this question being asked in the first place.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2012

Ahh, you'll need to add handling for the parameters yourself then - the code I've got simply reuses the parameters that are built into the report/field/workflow parameter screens already.

TAGS
AUG Leaders

Atlassian Community Events