3

Is this legal?

MANIFEST.MF for org.fragment1 (org.host is a normal bundle, not a fragment):

Bundle-SymbolicName: org.fragment1
Fragment-Host: org.host

MANIFEST.MF for org.fragment2:

Bundle-SymbolicName: org.fragment2
Fragment-Host: org.fragment1

Or should org.fragment2 instead have

Fragment-Host: org.host

?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

2 Answers2

6

Fragment bundles can't have a other fragment bundles as host. Only normal bundles can act as an fragment-host. So your third example is correct:

Or should org.fragment2 instead have

Fragment-Host: org.host

You find this restriction in the OSGi Service Platform Release 4 Version 4.3 Core Specification on page 70. It says:

A Fragment bundle can not be required by another bundle with the Require-Bundle header.

Tim
  • 2,831
  • 1
  • 25
  • 37
  • Thanks! Do you have a cite confirming this? I've run into the first example in a project and want to report this as a bug. OSGi specification paragraph 3.14 doesn't seem to say anything about it... – Alexey Romanov Aug 11 '11 at 09:39
  • But there is no `Require-Bundle` header here, only `Fragment-Host`. – Alexey Romanov Aug 11 '11 at 10:14
  • 1
    I think we _can_ say "All classes and resources within the fragment bundle must be loaded using the class loader of the host bundle" and "Fragments ... must not have their own class loader" together imply fragments can't be hosts, but it seems a slight stretch. – Alexey Romanov Aug 11 '11 at 10:19
3

Fragments attach to hosts. They cannot attach to other fragments. You can construct capabilities and requirements (new in Core 4.3) to prevent a fragment from attaching to a host unless another fragment is also attached. For example, fragment 1 could provide a capability which fragment 2 requires. This may provide the level of control you seek.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27