Search in sources :

Example 16 with BundleWire

use of org.osgi.framework.wiring.BundleWire in project karaf by apache.

the class BundleInfoImpl method getFragments.

private void getFragments(BundleRevision revision) {
    List<BundleWire> wires = revision.getWiring().getProvidedWires(BundleRevision.HOST_NAMESPACE);
    if (wires != null) {
        for (BundleWire w : wires) {
            Bundle b = w.getRequirerWiring().getBundle();
            this.fragments.add(b);
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 17 with BundleWire

use of org.osgi.framework.wiring.BundleWire in project karaf by apache.

the class BundleWiresTest method packageWire.

private BundleWire packageWire(String packageFilter, BundleCapability bundleRef) {
    BundleWire wire = c.createMock(BundleWire.class);
    BundleRequirement req = packageRequirement(packageFilter);
    expect(wire.getRequirement()).andReturn(req);
    expect(wire.getCapability()).andReturn(bundleRef);
    return wire;
}
Also used : BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 18 with BundleWire

use of org.osgi.framework.wiring.BundleWire in project karaf by apache.

the class Deployer method computeBundlesToRefresh.

private static void computeBundlesToRefresh(Map<Bundle, String> toRefresh, Collection<Bundle> bundles, Map<Resource, Bundle> resources, Map<Resource, List<Wire>> resolution) {
    // Compute the new list of fragments
    Map<Bundle, Set<Resource>> newFragments = new HashMap<>();
    for (Bundle bundle : bundles) {
        newFragments.put(bundle, new HashSet<>());
    }
    if (resolution != null) {
        for (Resource res : resolution.keySet()) {
            for (Wire wire : resolution.get(res)) {
                if (HOST_NAMESPACE.equals(wire.getCapability().getNamespace())) {
                    Bundle bundle;
                    if (wire.getProvider() instanceof BundleRevision) {
                        bundle = ((BundleRevision) wire.getProvider()).getBundle();
                    } else {
                        bundle = resources.get(wire.getProvider());
                    }
                    if (bundle != null) {
                        Bundle b = resources.get(wire.getRequirer());
                        Resource r = b != null ? b.adapt(BundleRevision.class) : wire.getRequirer();
                        newFragments.get(bundle).add(r);
                    }
                }
            }
        }
    }
    // Main loop
    int size;
    Map<Bundle, Resource> bndToRes = new HashMap<>();
    for (Map.Entry<Resource, Bundle> entry : resources.entrySet()) {
        bndToRes.put(entry.getValue(), entry.getKey());
    }
    do {
        size = toRefresh.size();
        main: for (Bundle bundle : bundles) {
            Resource resource = bndToRes.get(bundle);
            // This bundle is not managed
            if (resource == null) {
                resource = bundle.adapt(BundleRevision.class);
            }
            // Continue if we already know about this bundle
            if (toRefresh.containsKey(bundle)) {
                continue;
            }
            // Ignore non resolved bundle
            BundleWiring wiring = bundle.adapt(BundleWiring.class);
            if (wiring == null) {
                continue;
            }
            // Ignore bundles that won't be wired
            List<Wire> newWires = resolution != null ? resolution.get(resource) : null;
            if (newWires == null) {
                continue;
            }
            // Check if this bundle is a host and its fragments changed
            Set<Resource> oldFragments = new HashSet<>();
            for (BundleWire wire : wiring.getProvidedWires(null)) {
                if (HOST_NAMESPACE.equals(wire.getCapability().getNamespace())) {
                    oldFragments.add(wire.getRequirer());
                }
            }
            if (!oldFragments.containsAll(newFragments.get(bundle))) {
                toRefresh.put(bundle, "Attached fragments changed: " + new ArrayList<>(newFragments.get(bundle)));
                break;
            }
            // Compare the old and new resolutions
            Set<Resource> wiredBundles = new HashSet<>();
            for (BundleWire wire : wiring.getRequiredWires(null)) {
                BundleRevision rev = wire.getProvider();
                Bundle provider = rev.getBundle();
                if (toRefresh.containsKey(provider)) {
                    // The bundle is wired to a bundle being refreshed,
                    // so we need to refresh it too
                    toRefresh.put(bundle, "Wired to " + provider.getSymbolicName() + "/" + provider.getVersion() + " which is being refreshed");
                    continue main;
                }
                Resource res = bndToRes.get(provider);
                wiredBundles.add(res != null ? res : rev);
            }
            Map<Resource, Requirement> wiredResources = new HashMap<>();
            for (Wire wire : newWires) {
                // Handle only packages, hosts, and required bundles
                String namespace = wire.getRequirement().getNamespace();
                if (!namespace.equals(BundleNamespace.BUNDLE_NAMESPACE) && !namespace.equals(PackageNamespace.PACKAGE_NAMESPACE) && !namespace.equals(HostNamespace.HOST_NAMESPACE)) {
                    continue;
                }
                // Ignore non-resolution time requirements
                String effective = wire.getRequirement().getDirectives().get(Namespace.CAPABILITY_EFFECTIVE_DIRECTIVE);
                if (effective != null && !Namespace.EFFECTIVE_RESOLVE.equals(effective)) {
                    continue;
                }
                // Ignore non bundle resources
                if (!isBundle(wire.getProvider())) {
                    continue;
                }
                if (!wiredResources.containsKey(wire.getProvider())) {
                    wiredResources.put(wire.getProvider(), wire.getRequirement());
                }
            }
            if (!wiredBundles.containsAll(wiredResources.keySet())) {
                Map<Resource, Requirement> newResources = new HashMap<>(wiredResources);
                newResources.keySet().removeAll(wiredBundles);
                StringBuilder sb = new StringBuilder();
                sb.append("Should be wired to: ");
                boolean first = true;
                for (Map.Entry<Resource, Requirement> entry : newResources.entrySet()) {
                    if (!first) {
                        sb.append(", ");
                    } else {
                        first = false;
                    }
                    Resource res = entry.getKey();
                    Requirement req = entry.getValue();
                    sb.append(getSymbolicName(res)).append("/").append(getVersion(res));
                    sb.append(" (through ");
                    sb.append(req);
                    sb.append(")");
                }
                toRefresh.put(bundle, sb.toString());
            }
        }
    } while (toRefresh.size() > size);
}
Also used : MapUtils.removeFromMapSet(org.apache.karaf.features.internal.util.MapUtils.removeFromMapSet) EnumSet(java.util.EnumSet) Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) FeatureResource(org.apache.karaf.features.internal.resolver.FeatureResource) Resource(org.osgi.resource.Resource) Wire(org.osgi.resource.Wire) BundleWire(org.osgi.framework.wiring.BundleWire) BundleWire(org.osgi.framework.wiring.BundleWire) Requirement(org.osgi.resource.Requirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 19 with BundleWire

use of org.osgi.framework.wiring.BundleWire in project camel by apache.

the class Activator method extenderCapabilityWired.

private boolean extenderCapabilityWired(Bundle bundle) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    if (wiring == null) {
        return true;
    }
    List<BundleWire> requiredWires = wiring.getRequiredWires(EXTENDER_NAMESPACE);
    for (BundleWire requiredWire : requiredWires) {
        if (CAMEL_EXTENDER.equals(requiredWire.getCapability().getAttributes().get(EXTENDER_NAMESPACE))) {
            if (this.bundleId == requiredWire.getProviderWiring().getBundle().getBundleId()) {
                LOG.debug("Camel extender requirement of bundle {} correctly wired to this implementation", bundle.getBundleId());
                return true;
            } else {
                LOG.info("Not processing bundle {} as it requires a camel extender but is not wired to the this implementation", bundle.getBundleId());
                return false;
            }
        }
    }
    return true;
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 20 with BundleWire

use of org.osgi.framework.wiring.BundleWire in project gfm_viewer by satyagraha.

the class BundleInformation method showSWTBotDependencies.

public static void showSWTBotDependencies() {
    log("commencing showSWTBotDependencies");
    Bundle bundle = FrameworkUtil.getBundle(SWTBot.class);
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    List<BundleWire> requiredWires = wiring.getRequiredWires(null);
    for (BundleWire requiredWire : requiredWires) {
        log("requiredWire: " + requiredWire);
    }
    log("completed showSWTBotDependencies");
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Aggregations

BundleWire (org.osgi.framework.wiring.BundleWire)30 BundleWiring (org.osgi.framework.wiring.BundleWiring)22 Bundle (org.osgi.framework.Bundle)19 ArrayList (java.util.ArrayList)9 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)8 Test (org.junit.Test)7 BundleCapability (org.osgi.framework.wiring.BundleCapability)7 BundleRevision (org.osgi.framework.wiring.BundleRevision)7 List (java.util.List)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 CompositeData (javax.management.openmbean.CompositeData)4 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)4 Version (org.osgi.framework.Version)4 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 JarOutputStream (java.util.jar.JarOutputStream)3 Manifest (java.util.jar.Manifest)3