Search in sources :

Example 21 with Wiring

use of org.osgi.resource.Wiring in project felix by apache.

the class ResolverTest method testScenario12.

/**
 * Test dynamic resolution with an unresolvable host
 */
@Test(expected = ResolutionException.class)
public void testScenario12() throws Exception {
    ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
    Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
    Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
    ResourceImpl a1 = new ResourceImpl("A");
    Capability a1_hostCap = addCap(a1, HostNamespace.HOST_NAMESPACE, "A");
    ResourceImpl b1 = new ResourceImpl("B");
    Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
    ResourceImpl c1 = new ResourceImpl("C");
    Capability c_hostCap = addCap(c1, HostNamespace.HOST_NAMESPACE, "A");
    Capability c_pkgCap = addCap(c1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
    Requirement c_pkgReq1 = addReq(c1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.b");
    candMap.put(b_pkgReq1, Collections.singletonList(c_pkgCap));
    candMap.put(c_pkgReq1, Collections.<Capability>emptyList());
    Map<Resource, List<Wire>> wires = new HashMap<Resource, List<Wire>>();
    wires.put(a1, new ArrayList<Wire>());
    wires.put(b1, new ArrayList<Wire>());
    Map<Resource, List<Wire>> invertedWires = new HashMap<Resource, List<Wire>>();
    invertedWires.put(a1, new ArrayList<Wire>());
    invertedWires.put(b1, new ArrayList<Wire>());
    wirings.put(a1, new SimpleWiring(a1, Collections.<Capability>emptyList(), wires, invertedWires));
    wirings.put(b1, new SimpleWiring(b1, Collections.<Capability>emptyList(), wires, invertedWires));
    ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Collections.<Resource>emptyList(), Collections.<Resource>emptyList());
    List<Capability> caps = new ArrayList<Capability>();
    caps.add(c_pkgCap);
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci, b1, b_pkgReq1, caps);
    assertEquals(0, wireMap.size());
}
Also used : GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) Capability(org.osgi.resource.Capability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Logger(org.apache.felix.resolver.Logger) Wire(org.osgi.resource.Wire) Wiring(org.osgi.resource.Wiring) Requirement(org.osgi.resource.Requirement) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) ArrayList(java.util.ArrayList) List(java.util.List) ResolveContextImpl(org.apache.felix.resolver.test.util.ResolveContextImpl) Test(org.junit.Test)

Example 22 with Wiring

use of org.osgi.resource.Wiring in project aries by apache.

the class ResolveContext method processAsSubstitutableExport.

private void processAsSubstitutableExport(boolean isFragment, Requirement requirement, List<Capability> capabilities) {
    String namespace = requirement.getNamespace();
    if (!PackageNamespace.PACKAGE_NAMESPACE.equals(namespace)) {
        return;
    }
    Resource resource = requirement.getResource();
    Wiring wiring = wirings.get(resource);
    if (isFragment) {
        List<Wire> fragmentWires = wiring.getRequiredResourceWires(HostNamespace.HOST_NAMESPACE);
        for (Wire fragmentWire : fragmentWires) {
            Resource host = fragmentWire.getProvider();
            processResourceCapabilities(wirings.get(host).getResourceCapabilities(namespace), requirement, capabilities);
        }
    } else {
        List<Capability> resourceCapabilities = wiring.getResourceCapabilities(namespace);
        processResourceCapabilities(resourceCapabilities, requirement, capabilities);
    }
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) Wiring(org.osgi.resource.Wiring) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) MissingCapability(org.apache.aries.subsystem.core.internal.DependencyCalculator.MissingCapability) Resource(org.osgi.resource.Resource) Wire(org.osgi.resource.Wire)

Example 23 with Wiring

use of org.osgi.resource.Wiring in project aries by apache.

the class ResolveContext method processAsFragment.

private void processAsFragment(Requirement requirement, List<Capability> capabilities) {
    String namespace = requirement.getNamespace();
    Resource fragment = requirement.getResource();
    Wiring fragmentWiring = wirings.get(fragment);
    List<Wire> fragmentWires = fragmentWiring.getRequiredResourceWires(HostNamespace.HOST_NAMESPACE);
    for (Wire fragmentWire : fragmentWires) {
        Resource host = fragmentWire.getProvider();
        Wiring hostWiring = wirings.get(host);
        List<Wire> hostWires = hostWiring.getRequiredResourceWires(namespace);
        processWires(hostWires, requirement, capabilities);
    }
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) Wiring(org.osgi.resource.Wiring) Resource(org.osgi.resource.Resource) Wire(org.osgi.resource.Wire)

Aggregations

Resource (org.osgi.resource.Resource)23 Wiring (org.osgi.resource.Wiring)23 Capability (org.osgi.resource.Capability)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 List (java.util.List)19 Requirement (org.osgi.resource.Requirement)19 Wire (org.osgi.resource.Wire)18 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)17 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)17 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)16 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)16 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)16 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)16 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)16 Logger (org.apache.felix.resolver.Logger)15 ResolverImpl (org.apache.felix.resolver.ResolverImpl)15 Test (org.junit.Test)14 Resolver (org.osgi.service.resolver.Resolver)10 ResourceImpl (org.apache.felix.resolver.test.util.ResourceImpl)7