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

Can't import PluginSettingsFactory in BitBucket plugin

Matt November 11, 2015

Hello,

I'm trying to develop a rest plugin for Bitbucket v4.0 and I need to use the PluginSettingsFactory yet I can't import it, lots of errors. I've tried following the guide,

https://developer.atlassian.com/docs/atlassian-platform-common-components/shared-access-layer/sal-code-samples

but that doesn't work. If I add the component-import-key it doesn't do any good, my plugin crashes because it can't find the Factory classes.

So I tried adding the import to atlassian-plugins-component-imports.xml

   <osgi:reference id="pluginSettingsFactory" interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory"/>

but that was a whole other world of hurt,

Error creating bean with name 'pluginSettingsFactory': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class[]' for property 'interfaces'; nested exception is java.lang.IllegalArgumentException: Cannot find class [com.atlassian.sal.api.pluginsettings.PluginSettingsFactory


Any help is greatly appreciated.

 

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Ben Humphreys
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 12, 2015

Hi Matt,

If you are able to compile without error, but see those errors at run time I suspect the OSGi imports are the problem. You should have a section in your POM that looks like this:

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;com.atlassian.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;bitbucket-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;${amps.version}&lt;/version&gt;
            &lt;extensions&gt;true&lt;/extensions&gt;
            &lt;configuration&gt;
                &lt;products&gt;
                    &lt;product&gt;
                        &lt;id&gt;bitbucket&lt;/id&gt;
                        &lt;instanceId&gt;bitbucket&lt;/instanceId&gt;
                        &lt;version&gt;${bitbucket.version}&lt;/version&gt;
                        &lt;dataVersion&gt;${bitbucket.data.version}&lt;/dataVersion&gt;
                    &lt;/product&gt;
                &lt;/products&gt;
                &lt;instructions&gt;
                    &lt;Atlassian-Plugin-Key&gt;${atlassian.plugin.key}&lt;/Atlassian-Plugin-Key&gt;
                    &lt;!-- Add package to export here --&gt;
                    &lt;Export-Package&gt;
                        com.example.api,
                    &lt;/Export-Package&gt;
                    &lt;!-- Add package import here --&gt;
                    &lt;Import-Package&gt;
                        com.example.api,
                        *
                    &lt;/Import-Package&gt;
                &lt;/instructions&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

See the <Import-Package> section; probably the simplest thing to do here is to just list your own exported package (in this case com.example.api) followed by an asterisk. Note the comma at the end of the first line, this is very important and the POM will be parsed without error if you do omit it, but will not result in the asterisk import actually working like you expect.

If that does not help, please have a look at this example I just put together: https://bitbucket.org/ben_humphreys/example-sal-usage/overview

0 votes
Matt November 16, 2015

Thank you, your example provide all of the answers and help I was looking for. Is there documentation for the way you setup your plugin to use SAL?

0 votes
Matt November 12, 2015

Thank you for the response. I am including the dependency in the pom.xml.

 

If I try the <component-import... method I end up with the following error,

ThrowableExceptionMapper Uncaught exception thrown by REST service: com/atlassian/sal/api/pluginsettings/PluginSettingsFactory

[INFO] [talledLocalContainer] java.lang.NoClassDefFoundError: com/atlassian/sal/api/pluginsettings/PluginSettingsFactory

and if I try the <osgi:reference id... method I end up with the error in my original email. 

thank you

0 votes
Ben Humphreys
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 11, 2015

When you say you "can't import it", do you mean compilation fails? Have you added the sal-api dependency to your Maven POM?

&lt;dependency&gt;
    &lt;groupId&gt;com.atlassian.sal&lt;/groupId&gt;
    &lt;artifactId&gt;sal-api&lt;/artifactId&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

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