Search code examples
osgiapache-felix

Find the OSGI bundle that exports a package?


How do I find the bundle that exports a package?

I am using felix and I have a string like "com.test", how do I know which bundle exports that package?

I don't want to use PackageAdmin as it has been deprecated, and I don't really want to get the Export-Package header for each bundle and parse it.

Any ideas?


Solution

  • It sounds like you want to do this programmatically, not at the Gogo shell ... at least I'll assume that from wording of your question.

    There is no real way to say "which bundle" exports a given package since there can be many bundles exporting any given package and that package can be in use from many bundles by many bundles. If you have a specific bundle and you want to know which bundle provides package com.test to it, you can get the importing bundle's wiring Bundle.adapt(BundleWiring.class) and then use BundleWiring.getRequiredWires() to get the providers of all of the bundle's dependencies.

    From there you just need to find the wire of osgi.wiring.package namespace for the package you want, then the provider of that wire will be a BundleCapability of a BundleRevision of the bundle you are interested in.