BundleManifestScanner

BundleManifestScanner

When?

You should use the BundleManifestScanner if you wish to implement an extender that is triggered by existence of specific entries in bundle manifest (META-INF/MANIFEST.MF).

How?

Usually in you extender BundleActivator you will create and start an instance of BundleWatcher by passing in a BundleManifestScanner and your extender specific BundleObserver.

new BundleWatcher< ManifestEntry >( bundleContext, // bundle manifest scanner new BundleManifestScanner(...), // customizer for scanned entries new BundleObserver< ManifestEntry >() public void addingEntries( Bundle bundle, List< ManifestEntry > entries ) { // your specific code, doing something with the manifest entries } public void removingEntries( Bundle bundle, List< ManifestEntry > entries ) { // revert actions (if required) } } );
BundleManifestScanner

This scanner takes the starting bundle manifest entries and makes use of provided ManifestFilter to find out if the current bundle manifest contains expected entries. If there are any entries matched by the manifest filter it will create for each one a ManifestEntry which is a simple pair between manifest header name and value.
Bellow is an example of creating a BundleManifestScanner that uses a regular expression based manifest filter:

new BundleManifestScanner( new RegexKeyManifestFilter( "Bundle-.*" ) );
ManifestFilter

Manifest filters scope is to filter the manifest entries to the set required by your extender. You can implement your own filter and/or make use of the built-in ones:

  • RegexKeyManifestFilter — matches manifest headers name against a regular expression

  • ... more to come

Examples

Pax Swissbox includes a set of examples to demonstrate its usage.

OSGi headers lister

This example uses the BundleWatcher to scan bundles that contains manifest headers that start with "Bundle", basically any bundle. As soon as bundle gets started (or is already started) it will log at INFO level all "Bundle*" headers. If a bundle gets stopped it will list again all "Bundle*" headers.

You can simply start the example by using Pax Runner (available only after release 0.2.0 of Pax Swissbox):

pax-run mvn:org.ops4j.pax.swissbox.samples.extender/manifest-extender --profiles=log