Search code examples
javaruntimeosgibundles

Modifying a Bundle Manifest at run time


Is it possible (and if so, safe) to modify the MANIFEST of a bundle anytime during it's lifecycle (i.e. presumably only between INSTALLED and RESOLVED).

I guess another way to ask the question would be,

After INSTALLED, but before RESOLVED, is the MANIFEST already fully evaluated (i.e. further changes would be ignored) making it too late to change?

If all of the above seems absurd.. then my next question would be, does anyone think that it's possible (without nasty framework hacks) to wrap the MANIFEST resolution (i.e. the classloader step to get the META-INF/MANIFEST.MF from a bundle) with a custom impl.

Background: Consider an existing modularity framework, not based on OSGi, that I'd like to simplify the migration for, toward OSGi, by offering the ability to deploy the tone of existing "plugins" without modification, and at runtime, perform an analysis (the "plugins" are well defined so the mapping should not be hard) which converts them to true OSGi bundles, using BND runtime operations to generate a MANIFEST which would be used in place of the potentially none-existent or non-osgi-bundle MANIFEST.

Hopefully that makes sense (@njbartlett!)


Solution

  • Why not define a URL scheme that mutates the manifest as part of the install/update process? When the framework accesses the bundle via your URLConnection, you can return a mutated bundle with the mutated manifest. This is basically what the web bundle support does and it should work for you too.