Using the OSGi API, how do I know if a given package is a fragment?

In the OSGi API, a call to BundleContext.getBundles () returns all packets, regardless of whether they are fragments or not. For a given Bundle object , what is the best way to determine if it is a fragment or not?

+5
source share
3 answers

The best way:

(bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0

+8
source

One possible way: use Bundle.getHeaders () to search for the Fragment-Host . If present, this is a fragment.

+4
source

OSGi Core Specification Release 4, 4.2, PackageAdmin, , . , .

import org.osgi.framework.Bundle;
import org.osgi.service.packageadmin.PackageAdmin;

PackageAdmin packageAdmin = ...; // I assume you know this

Bundle hostBundle = ...;         // I assume you know this
Bundle fragmentBundle = ...;     // I assume you know this

assertFalse(PackageAdmin.BUNDLE_TYPE_FRAGMENT, packageAdmin.getBundleType(hostBundle);
assertEquals(PackageAdmin.BUNDLE_TYPE_FRAGMENT, packageAdmin.getBundleType(fragmentBundle);

-, OSGi 4.3 PackageAdmin org.osgi.framework.wiring.

+1
source

All Articles