Search in sources :

Example 1 with BundleRequirement

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

the class HttpExtension method getAttributes.

private Map<String, Object> getAttributes() {
    BundleWiring bundleWiring = _bundle.adapt(BundleWiring.class);
    List<BundleWire> wires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
    Map<String, Object> cdiAttributes = Collections.emptyMap();
    for (BundleWire wire : wires) {
        BundleCapability capability = wire.getCapability();
        Map<String, Object> attributes = capability.getAttributes();
        String extender = (String) attributes.get(EXTENDER_NAMESPACE);
        if (extender.equals(CDI_CAPABILITY_NAME)) {
            BundleRequirement requirement = wire.getRequirement();
            cdiAttributes = requirement.getAttributes();
            break;
        }
    }
    return cdiAttributes;
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 2 with BundleRequirement

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

the class BundleServiceImpl method getDiag.

@Override
public String getDiag(Bundle bundle) {
    StringBuilder message = new StringBuilder();
    for (BundleStateService bundleStateService : stateServices) {
        String part = bundleStateService.getDiag(bundle);
        if (part != null) {
            message.append(bundleStateService.getName());
            message.append("\n");
            message.append(part);
        }
    }
    if (bundle.getState() == Bundle.INSTALLED) {
        System.out.println("Unsatisfied Requirements:");
        List<BundleRequirement> reqs = getUnsatisfiedRequirements(bundle, null);
        for (BundleRequirement req : reqs) {
            System.out.println(req);
        }
    }
    return message.toString();
}
Also used : BundleStateService(org.apache.karaf.bundle.core.BundleStateService) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 3 with BundleRequirement

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

the class Requirements method printMatchingRequirements.

private static boolean printMatchingRequirements(BundleWiring wiring, Pattern namespace) {
    List<BundleWire> wires = wiring.getRequiredWires(null);
    Map<BundleRequirement, List<BundleWire>> aggregateReqs = aggregateRequirements(namespace, wires);
    List<BundleRequirement> allReqs = wiring.getRequirements(null);
    boolean matches = false;
    for (BundleRequirement req : allReqs) {
        if (matchNamespace(namespace, req.getNamespace())) {
            matches = true;
            List<BundleWire> providers = aggregateReqs.get(req);
            if (providers != null) {
                System.out.println(req.getNamespace() + "; " + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " resolved by:");
                for (BundleWire wire : providers) {
                    String msg;
                    Object keyAttr = wire.getCapability().getAttributes().get(wire.getCapability().getNamespace());
                    if (keyAttr != null) {
                        msg = wire.getCapability().getNamespace() + "; " + keyAttr + " " + getVersionFromCapability(wire.getCapability());
                    } else {
                        msg = wire.getCapability().toString();
                    }
                    msg = "   " + msg + " from " + wire.getProviderWiring().getBundle();
                    System.out.println(msg);
                }
            } else {
                System.out.println(req.getNamespace() + "; " + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " " + UNRESOLVED_MESSAGE);
            }
        }
    }
    return matches;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 4 with BundleRequirement

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

use of org.osgi.framework.wiring.BundleRequirement in project felix by apache.

the class Inspect method printMatchingRequirements.

private static boolean printMatchingRequirements(BundleWiring wiring, List<String> namespace) {
    List<BundleWire> wires = wiring.getRequiredWires(null);
    Map<BundleRequirement, List<BundleWire>> aggregateReqs = aggregateRequirements(namespace, wires);
    List<BundleRequirement> allReqs = wiring.getRequirements(null);
    boolean matches = false;
    for (BundleRequirement req : allReqs) {
        if (matchNamespace(namespace, req.getNamespace())) {
            matches = true;
            List<BundleWire> providers = aggregateReqs.get(req);
            if (providers != null) {
                System.out.println(req.getNamespace() + "; " + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " resolved by:");
                for (BundleWire wire : providers) {
                    String msg;
                    Object keyAttr = wire.getCapability().getAttributes().get(wire.getCapability().getNamespace());
                    if (keyAttr != null) {
                        msg = wire.getCapability().getNamespace() + "; " + keyAttr + " " + getVersionFromCapability(wire.getCapability());
                    } else {
                        msg = wire.getCapability().toString();
                    }
                    msg = "   " + msg + " from " + wire.getProviderWiring().getBundle();
                    System.out.println(msg);
                }
            } else {
                System.out.println(req.getNamespace() + "; " + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " " + UNRESOLVED_MESSAGE);
            }
        }
    }
    return matches;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Aggregations

BundleRequirement (org.osgi.framework.wiring.BundleRequirement)51 BundleCapability (org.osgi.framework.wiring.BundleCapability)21 ArrayList (java.util.ArrayList)20 BundleRevision (org.osgi.framework.wiring.BundleRevision)17 BundleWire (org.osgi.framework.wiring.BundleWire)17 HashMap (java.util.HashMap)16 Bundle (org.osgi.framework.Bundle)14 Test (org.junit.Test)12 BundleException (org.osgi.framework.BundleException)11 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)10 BundleWiring (org.osgi.framework.wiring.BundleWiring)10 List (java.util.List)9 Collection (java.util.Collection)8 BundleRequirementImpl (org.apache.felix.framework.wiring.BundleRequirementImpl)8 ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)8 CompositeData (javax.management.openmbean.CompositeData)6 Module (org.eclipse.osgi.container.Module)6 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)6 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)6 SimpleFilter (org.apache.felix.framework.capabilityset.SimpleFilter)5