SAL Code Samples

Using PluginSettings

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

atlassian-plugin.xml
<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

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);
    }

    
}

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport