use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class BundleWiringState method getRevisionWiring.
private CompositeData getRevisionWiring(BundleRevision revision, int revisionID, String namespace, Map<BundleRevision, Integer> revisionIDMap) {
BundleWiring wiring = revision.getWiring();
List<BundleCapability> capabilities = wiring.getCapabilities(namespace);
List<BundleRequirement> requirements = wiring.getRequirements(namespace);
List<BundleWire> providedWires = wiring.getProvidedWires(namespace);
List<BundleWire> requiredWires = wiring.getRequiredWires(namespace);
BundleWiringData data = new BundleWiringData(wiring.getBundle().getBundleId(), revisionID, capabilities, requirements, providedWires, requiredWires, revisionIDMap);
return data.toCompositeData();
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class BaseActivator method getAllHeaders.
private List<String> getAllHeaders(String headerName, Bundle bundle) {
List<Bundle> bundlesFragments = new ArrayList<Bundle>();
bundlesFragments.add(bundle);
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
BundleWiring wiring = rev.getWiring();
if (wiring != null) {
for (BundleWire wire : wiring.getProvidedWires("osgi.wiring.host")) {
bundlesFragments.add(wire.getRequirement().getRevision().getBundle());
}
}
}
List<String> l = new ArrayList<String>();
for (Bundle bf : bundlesFragments) {
String header = bf.getHeaders().get(headerName);
if (header != null) {
l.add(header);
}
}
return l;
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class ResolveContext method addWiring.
private void addWiring(Resource resource, Map<Resource, Wiring> wirings) {
if (resource instanceof BundleConstituent) {
BundleConstituent bc = (BundleConstituent) resource;
BundleWiring wiring = bc.getWiring();
if (wiring != null) {
wirings.put(bc.getBundle().adapt(BundleRevision.class), wiring);
}
} else if (resource instanceof BundleRevision) {
BundleRevision br = (BundleRevision) resource;
BundleWiring wiring = br.getWiring();
if (wiring != null) {
wirings.put(br, wiring);
}
}
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class WovenClassListener method modified.
@Override
public void modified(WovenClass wovenClass) {
if (wovenClass.getState() != WovenClass.TRANSFORMED) {
// the defined state is reached.
return;
}
List<String> dynamicImports = wovenClass.getDynamicImports();
if (dynamicImports.isEmpty()) {
// Nothing to do if there are no dynamic imports.
return;
}
BundleWiring wiring = wovenClass.getBundleWiring();
Bundle bundle = wiring.getBundle();
BundleRevision revision = bundle.adapt(BundleRevision.class);
BundleConstituent constituent = new BundleConstituent(null, revision);
Collection<BasicSubsystem> basicSubsystems = subsystems.getSubsystemsByConstituent(constituent);
BasicSubsystem subsystem = basicSubsystems.iterator().next();
// Find the scoped subsystem in the region.
subsystem = scopedSubsystem(subsystem);
if (subsystem.getSubsystemId() == 0) {
// The root subsystem needs no sharing policy.
return;
}
if (EnumSet.of(Subsystem.State.INSTALLING, Subsystem.State.INSTALLED).contains(subsystem.getState())) {
// The scoped subsystem must be resolved before adding dynamic
// package imports to the sharing policy in order to minimize
// unpredictable wirings. Resolving the scoped subsystem will also
// resolve all of the unscoped subsystems in the region.
AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.RESOLVE_ONLY));
}
Bundle systemBundle = context.getBundle(org.osgi.framework.Constants.SYSTEM_BUNDLE_LOCATION);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
// The following map tracks all of the necessary updates as each dynamic
// import is processed. The key is the tail region of the connection
// whose filter needs updating.
Map<Region, RegionUpdaterInfo> updates = new HashMap<Region, RegionUpdaterInfo>();
for (String dynamicImport : dynamicImports) {
// For each dynamic import, collect the necessary update information.
DynamicImportPackageHeader header = new DynamicImportPackageHeader(dynamicImport);
List<DynamicImportPackageRequirement> requirements = header.toRequirements(revision);
for (DynamicImportPackageRequirement requirement : requirements) {
Collection<BundleCapability> providers = frameworkWiring.findProviders(requirement);
if (providers.isEmpty()) {
// import, no updates are made.
continue;
}
addSharingPolicyUpdates(requirement, subsystem, providers, updates);
}
}
// Now update each sharing policy only once.
for (RegionUpdaterInfo update : updates.values()) {
RegionUpdater updater = new RegionUpdater(update.tail(), update.head());
try {
updater.addRequirements(update.requirements());
} catch (IllegalStateException e) {
// Something outside of the subsystems implementation has
// deleted the edge between the parent and child subsystems.
// Assume the dynamic import sharing policy is being handled
// elsewhere. See ARIES-1429.
} catch (Exception e) {
throw new SubsystemException(e);
}
}
}
use of org.osgi.framework.wiring.BundleWiring in project aries by apache.
the class SubsystemDependencyTestBase method verifyRequireBundleWiring.
/**
* Verify that the Require-Bundle of wiredBundleName in subsystem s is met by a wire
* to expectedProvidingBundleName
* @param s
* @param wiredBundleName
* @param expectedProvidingBundleName
*/
protected void verifyRequireBundleWiring(Subsystem s, String wiredBundleName, String expectedProvidingBundleName) {
Bundle wiredBundle = context(s).getBundleByName(BUNDLE_D);
assertNotNull("Target bundle " + wiredBundleName + " not found", wiredBundle);
BundleWiring wiring = (BundleWiring) wiredBundle.adapt(BundleWiring.class);
List<BundleWire> wiredBundles = wiring.getRequiredWires(BUNDLE_NAMESPACE);
assertEquals("Only one bundle expected", 1, wiredBundles.size());
String requiredBundleName = (String) wiredBundles.get(0).getCapability().getAttributes().get(BUNDLE_NAMESPACE);
assertEquals("Wrong bundle requirement", BUNDLE_A, requiredBundleName);
String providingBundle = wiredBundles.get(0).getProvider().getSymbolicName();
assertEquals("Wrong bundle provider", expectedProvidingBundleName, providingBundle);
}
Aggregations