0

I created an eclipse plugin that requires a certain capability in its manifest:

Require-Capability: osgi.service;filter:="(osgi.service=my.client.SessionService)"

My target platform contains another bundle that provides this capability. When I try to build this with Tycho I'm getting the following exception:

[ERROR] Internal error: java.lang.RuntimeException: org.osgi.framework.BundleException: Bundle my.client.rxp cannot be resolved
[ERROR] Resolution errors:
[ERROR] Bundle my.client.rxp - Missing Constraint: Require-Capability: osgi.service; filter="(osgi.service=my.client.SessionService)"

It seems that Tycho cannot handle OSGi Capabilities. Everything works fine as soon as I add the bundle that provides the capability as a required bundle to my eclipse plugin. But this makes no sense since the eclipse plugin shouldn't have any dependency to another implementation bundle. How can OSGi Capabilities be used in a Tycho build?

sebplorenz
  • 999
  • 2
  • 10
  • 17
  • You should probably also set a directive `effective:=active` on your requirement so that it does not prevent resolution of the bundle by the OSGi Framework itself. Service dependencies like this are really only intended as hints to a Resolver such as p2 (if it only supported them!) or the one in Bndtools (which does support them). – Neil Bartlett Mar 17 '14 at 19:46
  • Hi Neil, I tried with effective:=active already. If I add it to the manifest then p2 seems to ignore the whole statement. "The OSGi framework resolver only considers Capabilities without an effective directive or effective:=resolve. Capabilties with other values for the effective directive can be considered by an external agent." OSGi core 5.0.0 spec. p.33. This nice idea of Capabilities seems pretty useless in a maven-tycho-p2 environment :( – sebplorenz Mar 18 '14 at 07:28
  • I know that p2 does not handle it properly. Nevertheless, using effective:=active on this kind of requirement is correct. So I think what you mean to say is that the maven-tycho-p2 environment seems pretty useless ;-) – Neil Bartlett Mar 31 '14 at 04:22
  • Yes, and this is not the only problem driving me crazy when using maven-tycho-p2 ...but that's another story for another time. – sebplorenz Apr 03 '14 at 14:51

2 Answers2

0

This is most probably caused by a bug in p2:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=313553

which Tycho uses to resolve dependencies.

jsievers
  • 1,853
  • 10
  • 13
0

Thanks to jsievers, who provided the correct eclipse bug entry. Inside the bug entry there is a link to the Customizing p2 Metadata article. To cut a long story short, for p2 to handle capabilities correctly you have to provide capability advices by writing a p2 advice file (p2.inf).

I had to do the following to fix the capability resolution described in my question above. In the bundle that provides the capability there must be a META-INF/p2.inf file with the following contents:

provides.0.namespace = osgi.serviceloader
provides.0.name = my.client.SessionService

In the bundle that requires the capability there must be a META-INF/p2.inf file with the following contents:

requires.0.namespace = osgi.serviceloader
requires.0.name = my.client.SessionService

Much more capability advices options can be found in the article.

sebplorenz
  • 999
  • 2
  • 10
  • 17