Search in sources :

Example 6 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class SubsystemResolverHook method filterResolvable.

public void filterResolvable(Collection<BundleRevision> candidates) {
    try {
        for (Iterator<BundleRevision> iterator = candidates.iterator(); iterator.hasNext(); ) {
            BundleRevision revision = iterator.next();
            if (revision.equals(ThreadLocalBundleRevision.get())) {
                // The candidate is a bundle whose INSTALLED event is
                // currently being processed on this thread.
                iterator.remove();
                continue;
            }
            if (revision.getSymbolicName().startsWith(Constants.RegionContextBundleSymbolicNamePrefix))
                // Don't want to filter out the region context bundle.
                continue;
            Collection<BasicSubsystem> subsystems = this.subsystems.getSubsystemsReferencing(revision);
            if (subsystems.isEmpty() && ThreadLocalSubsystem.get() != null) {
                // This is the revision of a bundle being installed as part of a subsystem installation
                // before it has been added as a reference or constituent.
                iterator.remove();
                continue;
            }
            for (BasicSubsystem subsystem : subsystems) {
                if (subsystem.isFeature()) {
                    // Feature subsystems require no isolation.
                    continue;
                }
                // But only when in the INSTALLING state.
                if (Subsystem.State.INSTALLING.equals(subsystem.getState())) {
                    iterator.remove();
                }
            }
        }
    } catch (RuntimeException e) {
        // This try/catch block is in place because exceptions occurring here are not showing up in the console during testing.
        LOGGER.debug("Unexpected exception while filtering resolution candidates: " + candidates, e);
    }
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 7 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class ResolveContext method installDependenciesOfRequirerIfNecessary.

private void installDependenciesOfRequirerIfNecessary(Requirement requirement) {
    if (requirement == null) {
        return;
    }
    Resource requirer = requirement.getResource();
    if (resource.equals(requirer)) {
        return;
    }
    Collection<BasicSubsystem> subsystems;
    if (requirer instanceof BasicSubsystem) {
        BasicSubsystem subsystem = (BasicSubsystem) requirer;
        subsystems = Collections.singletonList(subsystem);
    } else if (requirer instanceof BundleRevision) {
        BundleRevision revision = (BundleRevision) requirer;
        BundleConstituent constituent = new BundleConstituent(null, revision);
        subsystems = Activator.getInstance().getSubsystems().getSubsystemsByConstituent(constituent);
    } else {
        return;
    }
    for (BasicSubsystem subsystem : subsystems) {
        if (Utils.isProvisionDependenciesInstall(subsystem) || !State.INSTALLING.equals(subsystem.getState())) {
            continue;
        }
        AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.INSTALL_ONLY));
    }
}
Also used : BundleConstituent(org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent) Resource(org.osgi.resource.Resource) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 8 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision 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 9 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class ProviderBundleTrackerCustomizer method getHeaderFromBundleOrFragment.

private String getHeaderFromBundleOrFragment(Bundle bundle, String headerName, String matchString) {
    String val = bundle.getHeaders().get(headerName);
    if (matches(val, matchString))
        return val;
    BundleRevision rev = bundle.adapt(BundleRevision.class);
    if (rev != null) {
        BundleWiring wiring = rev.getWiring();
        if (wiring != null) {
            for (BundleWire wire : wiring.getProvidedWires("osgi.wiring.host")) {
                Bundle fragment = wire.getRequirement().getRevision().getBundle();
                val = fragment.getHeaders().get(headerName);
                if (matches(val, matchString)) {
                    return val;
                }
            }
        }
    }
    return null;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 10 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision 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) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleWire(org.osgi.framework.wiring.BundleWire)

Aggregations

BundleRevision (org.osgi.framework.wiring.BundleRevision)66 Bundle (org.osgi.framework.Bundle)38 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)14 Map (java.util.Map)11 Test (org.junit.Test)11 BundleCapability (org.osgi.framework.wiring.BundleCapability)11 BundleWiring (org.osgi.framework.wiring.BundleWiring)11 Resource (org.osgi.resource.Resource)11 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)9 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)9 HashSet (java.util.HashSet)8 BundleWire (org.osgi.framework.wiring.BundleWire)8 BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 Set (java.util.Set)6 TreeMap (java.util.TreeMap)6 TabularData (javax.management.openmbean.TabularData)6 IOException (java.io.IOException)5 Collection (java.util.Collection)5 List (java.util.List)5