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

Is there a chance to get components from other plugins (non-system plugins) via OSGi

Thorsten Kamann January 31, 2012

Do I am trying something special? I have a plugin which should access components from other plugins via ComponentManager.
For the OSGi stuff I think a simple call to

ComponentManager.getOSGiComponentInstanceOfType(MultipleGitRepositoryManager.class);

should do the job. But I get a ClassCastException at

public static <T> T getOSGiComponentInstanceOfType(final Class<T> clazz){
   ....
   return clazz.cast(serviceTracker.getService());
....
}

It seems that my MultipleGitRepositoryManager is another than the one Felix have.
In my POM all dependencies have the scope provided.

Is there a way out of this?

After some experiments it seams that Felix hold one reference of a service. If I try to retrieve this service he is running in massive classloader problems.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Don Brown [Atlassian]
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.
January 31, 2012

If you need to consume a public component, you should do it via the <component-import> tag. Trying to retrieve the service directly via that java code you posted will bypass a lot of protective code that you'll want. You shouldn't have to do anything with package imports, unless there are two instances of that service exposed and you only want a specific instance.

Thorsten Kamann February 2, 2012

Yes with the component-imports it works. thanks.

Charles Henri Van Nuvel June 29, 2014

with component-import in plugin.xml and the component in the pom.xml it makes an error. I remove it from pom.xml and it works :)

1 vote
Colin Goudie
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.
January 31, 2012

You need to declare your component as public in atlassian-plugin.xml

See https://developer.atlassian.com/display/PLUGINFRAMEWORK/Component+Plugin+Module

Specifically the public attribute

Thorsten Kamann January 31, 2012

it were nice if it were so simple...the component I want to consume is already public.

JamieA
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.
January 31, 2012

You might need to import it in your bundle-imports section in your plugin.xml... Can you try that?

Thorsten Kamann January 31, 2012

you mean this?

<component-import key="gitManager" interface="com.xiplink.jira.git.MultipleGitRepositoryManager"/>

Colin Goudie
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.
January 31, 2012

Ah sorry, read your question in a rush. Thought you were after exposing your component.

JamieA
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.
January 31, 2012

No I mean like this:

<bundle-instructions>
    <Import-Package>com.atlassian.jira.jql.builder,*;resolution:=optional</Import-Package>
</bundle-instructions>

in the plugin-info section. Check the atlassian docs...

Thorsten Kamann January 31, 2012

seems to working.

But now I get an LinkageError. This I can solve if I restart the RevisionIndexService of the foreign Plugin. Are there known issues if more than one client consume an osgi component?

Don Brown [Atlassian]
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.
January 31, 2012

You shouldn't need to mess with import package statements, as the component-import tag should do the trick. You should only get linkage errors if you are bound to a different classloader that provides that interface than the one used by the service. Therefore, I'd recommend ditch the import package stuff and just use component-import. If that doesn't work, ensure that only one copy of that class is being exposed and once service impl. Also, there are no known issues with multiple plugins consuming a single public component.

Thorsten Kamann February 2, 2012

Yes...with the component-import it works now. thanks all for the help.

TAGS
AUG Leaders

Atlassian Community Events