The OSGi Enterprise Release 5 Specification introduces the osgi.extender
namespace. This namespace makes it possible for bundles that assume extenders such as Blueprint or Declarative Services are installed in the framework to model this dependency using the Require-Capability
header.
Chapter 135.2 osgi.extender Namespace tells us that the value of the capability for each specific extender should be specified in the corresponding specification. An example is given for Blueprint:
Provide-Capability: osgi.extender;
osgi.extender="osgi.blueprint";
uses:="org.osgi.service.blueprint.container,org.osgi.service.blueprint.reflect"
version:Version="1.0"
However, chapter 112 Declarative Services Specification does not specify the capability that an SCR implementation provides.
Peter Kriens gives an example in a blog post on Requirements and Capabilities that suggests the capability for SCR is osgi.component
. I assume that eventually this value will be properly defined in the specs. But until then I cannot use it.
Since the Require-Capability
and Provide-Capability
headers were introduced in OSGi Core Release 4.3 the mechanism is already available in framework implementations. So, I want my bundles to express a requirement on SCR so that an SCR implementation can be resolved from an OBR repository.
I can imagine one solution where I create an empty bundle that on one hand provides a custom capability and on the other hand require an implementation bundle. For example:
Provide-Capability: com.example.extender; extender=scr
Require-Bundle: org.apache.felix.scr; bundle-version=1.6.0
Any bundles that include declarative services can then express a requirement to this capability. For example:
Require-Capability: com.example.extender; filter:="(extender=scr)"
Is this a good way of making sure SCR is resolved when I deploy bundles that contain declarative services? Is there any other way?
A good solution to this problem would be a solution that can also be applied to other legacy bundles that don't provide capabilities.