26.3. FragmentsSometimes it is not possible to package a plug-in as one unit. There are two common scenarios where this occurs:
Eclipse supports these use cases using fragments. Fragments are just like regular plug-ins except their content is seamlessly merged at runtime with a host plug-in rather than being standalone. A fragment's classpath elements are appended to its host's classpath and its registry contributions are made under the host's id. You cannot express dependencies on fragments, just their hosts. Figure 26-3 shows examples of both platform- and locale-specific fragments. Both fragments have a manifest file that identifies the fragment, its version, and its host id and version range. The following is an example of the markup found in the Runtime's National Language (NL) fragment: org.eclipse.core.runtime.nl1/MANIFEST.MF Bundle-SymbolicName: org.eclipse.core.runtime.nl1 Bundle-Version: 3.1.0 Fragment-Host: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)" Bundle-ClassPath: . Figure 26-3. Plug-in fragments
The next snippet is from the Windows SWT fragment's manifest file. Notice the highlighted platform filter line. This is an Eclipse-specific header that identifies the set of environmental conditions that must be met for this bundle to be resolved. In this case, the osgi.os, osgi.ws, and osgi.arch system properties must match the given values. The syntax of the filter is that of standard Lightweight Directory Access Protocol (LDAP) filters and is detailed in the OSGi specification. org.eclipse.swt.win32.win32.x86/MANIFEST.MF Bundle-SymbolicName: org.eclipse.swt.win32.win32.x86; singleton:=true Bundle-Version: 3.1.0 Fragment-Host: org.eclipse.swt; bundle-version="[3.0.0,4.0.0)" Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=x86)) In both cases, the fragments directly contain code or resources to be appended to the host's classpath. Adding a fragment's classpath entries, or the fragment itself, to the host is a vital characteristic of fragments. Fragments generally contain implementation detail for the host. Whether it is code or messages, the contents need to be accessed as though they were part of the host. The only way to do this is to put the fragment on the host's classloader. This gives bidirectional access to the classes and resources as well as enables Java package-level visibility. At runtime, the host and fragment behave as if they were a single plug-in. Fragments are a powerful mechanism, but they are not for every use case. There are several characteristics to consider when you are looking at using fragments:
Figure 26-4 shows the OSGi console of a running Eclipse application after typing the short status ("ss") command. Notice that org.eclipse.resources.win32 fragment (#12) is shown as installed (and resolved) and bound to the Resources host plug-in (#13). Notice also that the report for the Resources plug-in also lists plug-in #88 as an attached fragment. It is not shown here, but it is actually the Core Tools Resource Spy fragment. This illustrates that you can have multiple fragments attached to the same host. Figure 26-4. Fragment resolution status
|