Last updatedDec 8, 2017

SAL code samples

Using PluginSettings

Add this to your atlassian-plugin.xml. It will only work with a version 2 plugin.

atlassian-plugin.xml

1
2
3
4
5
6
7
<atlassian-plugin key="your-plugin-key" name="Your plugin name" plugins-version="2">

    <!-- Makes PluginSettingsFactory available to your plugin. -->
    <component-import key="pluginSettingsFactory" interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory" />
    <!-- other stuff here -->

</atlassian-plugin>

Example class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Example {

    final PluginSettingsFactory pluginSettingsFactory;

    public Example(PluginSettingsFactory pluginSettingsFactory) {
        this.pluginSettingsFactory = pluginSettingsFactory;
    }

    public void storeSomeInfo(String key, String value) {
        // createGlobalSettings is nice and fast, so there's no need to cache it (it's memoised when necessary).
        pluginSettingsFactory.createGlobalSettings().put("my-plugin-namespace" + key, value);
    }

    public Object getSomeInfo(String key) {
        return pluginSettingsFactory.createGlobalSettings().get("my-plugin-namespace" + key);
    }

    public void storeSomeInfo(String projectKey, String key, String value) {
        // createSettingsForKey is nice and fast, so there's no need to cache it (it's memoised when necessary).
        pluginSettingsFactory.createSettingsForKey(projectKey).put("my-plugin-namespace" + key, value);
    }

    public Object getSomeInfo(String projectKey, String key) {
        return pluginSettingsFactory.createSettingsForKey(projectKey).get("my-plugin-namespace" + key);
    }
    
}