1

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!)

Ray
  • 1,324
  • 10
  • 18

2 Answers2

4

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.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
  • Thanks BJ & njb! This is kind of what I had in mind, and after I had reviewed a little of what virgo was doing I suspected it might be the way to go, but I wanted to hear it from the pros. I hate getting so far into an impl and later hearing "wth did you do that when you could have done this...". Can you point to the cleanest impl of this idea so that I might learn some best practices? – Ray Sep 12 '11 at 12:27
  • Have a look at the Pax url wrap, it's used to transform non OSGi maven jars into bundles (ie with manifest.mf) at runtime. https://github.com/ops4j/org.ops4j.pax.url/commits/master/pax-url-wrap – earcam Sep 12 '11 at 14:37
1

No you can't do this. The whole JAR file (and therefore the MANIFEST.MF) is read during the install operation. In order to change anything in that JAR you would have to either update the bundle or uninstall and install again.

Regarding what you actually want to do, why can't you just perform the analysis and transformation through bnd before installing the JAR as a bundle?

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • The flexibility of having been able to implement this inside of the OSGi framework as a (Framework|Bundle)Listener was appealing. I'm aware that we can do it before. And so that will have to be the way! – Ray Sep 11 '11 at 17:30
  • Actually, It's not that I'm trying to change the jar... it's that I'm trying wrap certain parts of the jar to make then look differently. – Ray Sep 11 '11 at 17:32
  • Although to be honest, gemini-web/virgo does something like this when wrapping web bundles. – Ray Sep 11 '11 at 17:37
  • Ray, take a look at BJ's answer. I forgot about this possibility and it sounds quite elegant to me. – Neil Bartlett Sep 11 '11 at 20:43