Search in sources :

Example 56 with Wire

use of org.osgi.resource.Wire 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)

Example 57 with Wire

use of org.osgi.resource.Wire in project karaf by apache.

the class SubsystemTest method dumpWiring.

private void dumpWiring(SubsystemResolver resolver) {
    System.out.println("Wiring");
    Map<Resource, List<Wire>> wiring = resolver.getWiring();
    List<Resource> resources = new ArrayList<>(wiring.keySet());
    resources.sort(Comparator.comparing(this::getName));
    for (Resource resource : resources) {
        System.out.println("    " + getName(resource));
        for (Wire wire : wiring.get(resource)) {
            System.out.println("        " + wire);
        }
    }
}
Also used : Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Wire(org.osgi.resource.Wire)

Example 58 with Wire

use of org.osgi.resource.Wire in project karaf by apache.

the class SubsystemResolver method resolve.

@Override
public Map<Resource, List<Wire>> resolve(String featureResolutionRange, FeaturesService.ServiceRequirementsBehavior serviceRequirements, final Repository globalRepository, String outputFile) throws Exception {
    if (root == null) {
        return Collections.emptyMap();
    }
    // Download bundles
    root.downloadBundles(manager, featureResolutionRange, serviceRequirements, new RepositoryManager(), callback);
    // Populate digraph and resolve
    digraph = new StandardRegionDigraph(null, null);
    populateDigraph(digraph, root);
    Downloader downloader = manager.createDownloader();
    SubsystemResolveContext context = new SubsystemResolveContext(root, digraph, globalRepository, downloader, serviceRequirements);
    if (outputFile != null) {
        Map<String, Object> json = new HashMap<>();
        if (globalRepository != null) {
            json.put("globalRepository", toJson(globalRepository));
        }
        json.put("repository", toJson(context.getRepository()));
        try {
            // this is where the magic happens...
            wiring = resolver.resolve(context);
            json.put("success", "true");
            json.put("wiring", toJson(wiring));
        } catch (Exception e) {
            json.put("success", "false");
            json.put("exception", e.toString());
            throw e;
        } finally {
            try (Writer writer = Files.newBufferedWriter(Paths.get(outputFile), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
                JsonWriter.write(writer, json, true);
            }
        }
    } else {
        // this is where the magic happens...
        wiring = resolver.resolve(context);
    }
    downloader.await();
    // Remove wiring to the fake environment resource
    if (environmentResource != null) {
        for (List<Wire> wires : wiring.values()) {
            wires.removeIf(wire -> wire.getProvider() == environmentResource);
        }
    }
    // Fragments are always wired to their host only, so create fake wiring to
    // the subsystem the host is wired to
    associateFragments();
    return wiring;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Downloader(org.apache.karaf.features.internal.download.Downloader) Wire(org.osgi.resource.Wire) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Writer(java.io.Writer) JsonWriter(org.apache.karaf.util.json.JsonWriter) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Aggregations

Wire (org.osgi.resource.Wire)58 Resource (org.osgi.resource.Resource)49 ArrayList (java.util.ArrayList)38 List (java.util.List)36 HashMap (java.util.HashMap)35 Requirement (org.osgi.resource.Requirement)31 Capability (org.osgi.resource.Capability)29 Wiring (org.osgi.resource.Wiring)18 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)15 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)15 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)15 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)15 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)15 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)15 ResolverImpl (org.apache.felix.resolver.ResolverImpl)14 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)14 Logger (org.apache.felix.resolver.Logger)13 Test (org.junit.Test)13 Resolver (org.osgi.service.resolver.Resolver)12 Map (java.util.Map)11