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

Setting JIRA plugin configuration parameters

Jannik Luyten
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.
April 4, 2013

Hi everyone

I am developing a plugin that uses a few configuration parameters (database connection stuff) which I want set through either a configuration file (database.properties kind of thing), or maybe the plugin administration section (if this is at all possible?), or even the atlassian-plugin.xml file.

How would I go about doing this? Any help is appreciated!

Kind regards

Jannik

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Jannik Luyten
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 6, 2013

I ended up implementing a simple property loader that loaded the properties from a file, which I then used everywhere I needed to load the plugin properties:

public class PropertyLoader {
	
	private Logger logger = Logger.getLogger(PropertyLoader.class);
	public PropertyLoader(){}
	
	public String loadProperty(String key) {
        try {
            Properties properties = new Properties();
            InputStream stream = getClass().getClassLoader().getResourceAsStream("/somePropertiesFile.properties");
            properties.load(stream);
            stream.close();
            
            String property = properties.getProperty(key);
			if(property == null) {
            	String message = "No property for key '" + key + "' found.";
    			logger.error(message);
				throw new IllegalArgumentException(message);
            }
            
            return property;
        } catch (Throwable t) {
            String message = "Error while loading property";
			logger.error(message, t);
            throw new RuntimeException(message, t);
        }
	}
}

3 votes
Gert-Jan van de Streek
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.
May 31, 2013

Check https://developer.atlassian.com/display/DOCS/Storing+plugin+settings. This is a general way for storing configuration properties for plugins, even across the atlassian products. Combine it with a configuration link for your plugin:

<plugin-info>
  ..
  <param name="configure.url">/secure/admin/configsla.jspa</param>
</plugin-info>

Implement that configuration link with a webwork action. See https://developer.atlassian.com/display/JIRADEV/Webwork+plugin+module for details.

Jannik Luyten
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 6, 2013

Would this allow you to change the plugin settings through configuration? Or would you have to crack open the plug-in and change the atlassian-plugin.xml file?

Gert-Jan van de Streek May 14, 2014

You will always have to write custom code for this. See the jspa in the above example. That is the implementation of a settings screen.

The correct link to the atlassian developer documentation is now: https://developer.atlassian.com/display/DOCS/Storing+plugin+settings

1 vote
Jobin Kuruvilla [Adaptavist]
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.
April 6, 2013
0 votes
Thomas Heyne
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.
April 4, 2013
import com.atlassian.sal.api.ApplicationProperties;

public class MyPluginComponentImpl implements MyPluginComponent {
    protected final ApplicationProperties applicationProperties;

    public MyPluginComponentImpl(ApplicationProperties applicationProperties) {
        this.applicationProperties = applicationProperties;
    }

    public String getName() {
        if (null != applicationProperties) {
            return "myComponent:" + applicationProperties.getDisplayName();
        }

        return "myComponent";
    }
}

Jannik Luyten
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.
April 4, 2013

Does this file match JIRA's General Configuration parameters? (https://confluence.atlassian.com/display/JIRA042/Advanced+JIRA+configuration+with+jira-application.properties)

If so, these are for _all_ plugins within JIRA, no? I would need some form of configuration visible to my plugin only, not to all plugins.

Thomas Heyne
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.
April 4, 2013

no, the file(s) I speak about will be automatically created if you are using the atlassian maven plug-in to set-up your plug-in either in Eclipse or in IDEA (I did)

as far as I remmeber correctly you will be asked on the console option to set them up or not if you create the plug-in module

you get two java classes generated (the interface and the implementation class *Impl) plus a properties file

via the variable applicationProperties you have access to the properties you need
you should be able to read from atlassian-plugin.xml as well

Jannik Luyten
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.
April 4, 2013

This does not seem the way to go. The application properties file contains general information about the application in question, e.g. JIRA. There is a getPropertyValue(key) method on it, but as of SAL 2.7.0, this is deprecated (http://docs.atlassian.com/sal-api/2.7.0/sal-api/apidocs/com/atlassian/sal/api/ApplicationProperties.html#getPropertyValue(java.lang.String) )

I need a way to provide my own configuration parameters, specific to my plugin, which I can specify in a file or through JIRA administration, and then read in my code.

Thomas Heyne
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.
April 14, 2013

how about this:

private static final String PROPERTYNAME = "<yourpath>/<yourfilename>.properties";
    private List properties;

    ...

    private List getProperites() {
        if (this.properties == null) {
            try {
                InputStream resourceInputStream = getClass().getClassLoader().getResourceAsStream(PROPERTYNAME);

                if (resourceInputStream != null) {
                    DataInputStream inputStream = new DataInputStream(resourceInputStream);

                    this.properties = new ArrayList();
                    String line;
                    while ((line = inputStream.readLine()) != null) {
                        line = line.trim();
                        // your logic here
                    }

                    inputStream.close();
                }
                else {
                    this.properties = Collections.EMPTY_LIST;
                }
            }
            catch (IOException e) {
                this.properties = Collections.EMPTY_LIST;
                e.printStackTrace();
            }
        }

        return this.properties;
    }

0 votes
Timothy
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.
April 4, 2013

If you want it on the fly, store the data in the database and pull it from your code.

If not, you can pull it from a .properties file.

Jannik Luyten
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.
April 4, 2013

And how would I go about creating such a file?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events