Hi,
I have a mission to verify that the OSGi meta-data in the bundle manifest accurately describes the bundle's contents. In particular, that every package listed in Export-Package is available somewhere along the bundle's Bundle-ClassPath. This is important because Bnd's Resolve task does not detect this kind of error in the meta-data unless another bundle wants to use classes from the exported package.
The BundleWiring seems to contain the information that I need:
val exportPackages = bundle.headers[EXPORT_PACKAGE]?.run(::extractPackageNames) ?: emptySet()
val wiring = bundle.adapt(BundleWiring::class.java)
for (exportPackage in exportPackages) {
val paths = wiring.listResources(exportPackage.replace('.', '/'), null, 0) ?: emptyList()
// assert that paths contains something other than just directories.
}
However, this check needs to run inside an OSGi framework and so is less than ideal.
It then occurred to me that Bnd might support this kind of validation already, and I duly discovered the aQute.bnd.osgi.Verifier class. This class looks like it performs a lot of other useful validation steps, and it wouldn't be difficult to wrap a Gradle task around it. However, it doesn't perform the specific check that I'm looking for, and I think that's
unlikely to be an oversight.
And so I have two questions please:
- Is the Export-Package validation that I seek so complicated that it needs to examine the BundleWiring? (E.g.searching bundles on the Bundle-ClassPath, which may have a Bundle-Classpath of their own, to the nth degree?)
- Is it worth using the Verifier anyway on a bundle which Bnd has just created? Or has Bnd already verified the bundle like this for me and so I'd just be duplicating the effort?
Thanks for any advice here,
Cheers,
Chris