Search in sources :

Example 56 with BundleWiring

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();
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWiringData(org.apache.aries.jmx.codec.BundleWiringData) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 57 with BundleWiring

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;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) ArrayList(java.util.ArrayList) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 58 with BundleWiring

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);
        }
    }
}
Also used : BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 59 with BundleWiring

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) SubsystemException(org.osgi.service.subsystem.SubsystemException) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) SubsystemException(org.osgi.service.subsystem.SubsystemException) DynamicImportPackageHeader(org.apache.aries.subsystem.core.archive.DynamicImportPackageHeader) BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) DynamicImportPackageRequirement(org.apache.aries.subsystem.core.archive.DynamicImportPackageRequirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) Region(org.eclipse.equinox.region.Region) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 60 with BundleWiring

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);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Aggregations

BundleWiring (org.osgi.framework.wiring.BundleWiring)110 Bundle (org.osgi.framework.Bundle)61 BundleWire (org.osgi.framework.wiring.BundleWire)39 ArrayList (java.util.ArrayList)23 BundleRevision (org.osgi.framework.wiring.BundleRevision)23 BundleCapability (org.osgi.framework.wiring.BundleCapability)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)13 Hashtable (java.util.Hashtable)12 List (java.util.List)12 BundleContext (org.osgi.framework.BundleContext)12 URL (java.net.URL)10 Dictionary (java.util.Dictionary)10 HashSet (java.util.HashSet)9 LinkedHashMap (java.util.LinkedHashMap)8 Version (org.osgi.framework.Version)7 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)7 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)6 IAnswer (org.easymock.IAnswer)6 ServiceReference (org.osgi.framework.ServiceReference)6