Add this to your atlassian-plugin.xml. It will only work with a version 2 plugin.
atlassian-plugin.xml
1 2<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 2public 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); } }
Rate this page: