Search in sources :

Example 26 with Resource

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

the class RepositoryTest method testLoadRepoWithCapabilitiesAndRequirement.

public void testLoadRepoWithCapabilitiesAndRequirement() throws Exception {
    RepositoryImpl r = new RepositoryImpl(getClass().getResource("repo3.xml").toURI());
    // Check features
    Feature[] features = r.getFeatures();
    assertNotNull(features);
    assertEquals(1, features.length);
    assertNotNull(features[0]);
    assertEquals("f1", features[0].getName());
    assertEquals(1, features[0].getCapabilities().size());
    assertEquals("cap", features[0].getCapabilities().get(0).getValue().trim());
    assertEquals(1, features[0].getRequirements().size());
    assertEquals("req", features[0].getRequirements().get(0).getValue().trim());
    Resource res = FeatureResource.build(features[0], null, null);
    assertEquals(1, res.getCapabilities("cap").size());
    assertEquals(1, res.getRequirements("req").size());
}
Also used : RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) Resource(org.osgi.resource.Resource) FeatureResource(org.apache.karaf.features.internal.resolver.FeatureResource)

Example 27 with Resource

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

the class FeaturesDependenciesTest 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 28 with Resource

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

the class FeaturesDependenciesTest method dumpBundles.

private void dumpBundles(SubsystemResolver resolver) {
    System.out.println("Bundle mapping");
    Map<String, Set<Resource>> bundles = resolver.getBundlesPerRegions();
    for (Map.Entry<String, Set<Resource>> entry : bundles.entrySet()) {
        System.out.println("    " + entry.getKey());
        for (Resource b : entry.getValue()) {
            System.out.println("        " + b);
        }
    }
}
Also used : Set(java.util.Set) MapUtils.addToMapSet(org.apache.karaf.features.internal.util.MapUtils.addToMapSet) Resource(org.osgi.resource.Resource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with Resource

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

the class RequirementSort method sort.

/**
     * Sort {@link Resource} based on their {@link Requirement}s and {@link Capability}s.
     *
     * @param resources the resource to sort.
     * @param <T> the resources type.
     * @return sorted collection of resources.
     */
public static <T extends Resource> Collection<T> sort(Collection<T> resources) {
    Set<String> namespaces = new HashSet<>();
    for (Resource r : resources) {
        for (Capability cap : r.getCapabilities(null)) {
            namespaces.add(cap.getNamespace());
        }
    }
    CapabilitySet capSet = new CapabilitySet(new ArrayList<>(namespaces));
    for (Resource r : resources) {
        for (Capability cap : r.getCapabilities(null)) {
            capSet.addCapability(cap);
        }
    }
    Set<T> sorted = new LinkedHashSet<>();
    Set<T> visited = new LinkedHashSet<>();
    for (T r : resources) {
        visit(r, visited, sorted, capSet);
    }
    return sorted;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) CapabilitySet(org.apache.karaf.features.internal.resolver.CapabilitySet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 30 with Resource

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

the class Builder method resolve.

private Map<String, Integer> resolve(DownloadManager manager, Resolver resolver, Collection<Features> repositories, Collection<String> features, Collection<String> bundles, Collection<String> overrides, Collection<String> optionals) throws Exception {
    BundleRevision systemBundle = getSystemBundle();
    AssemblyDeployCallback callback = new AssemblyDeployCallback(manager, this, systemBundle, repositories);
    Deployer deployer = new Deployer(manager, resolver, callback, callback);
    // Install framework
    Deployer.DeploymentRequest request = createDeploymentRequest();
    // Add overrides
    request.overrides.addAll(overrides);
    // Add optional resources
    final List<Resource> resources = new ArrayList<>();
    Downloader downloader = manager.createDownloader();
    for (String optional : optionals) {
        downloader.download(optional, provider -> {
            Resource resource = ResourceBuilder.build(provider.getUrl(), getHeaders(provider));
            synchronized (resources) {
                resources.add(resource);
            }
        });
    }
    downloader.await();
    request.globalRepository = new BaseRepository(resources);
    // Install features
    for (String feature : features) {
        MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, feature);
    }
    for (String bundle : bundles) {
        MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, "bundle:" + bundle);
    }
    Set<String> prereqs = new HashSet<>();
    while (true) {
        try {
            deployer.deploy(callback.getDeploymentState(), request);
            break;
        } catch (Deployer.PartialDeploymentException e) {
            if (!prereqs.containsAll(e.getMissing())) {
                prereqs.addAll(e.getMissing());
            } else {
                throw new Exception("Deployment aborted due to loop in missing prerequisites: " + e.getMissing());
            }
        }
    }
    return callback.getStartupBundles();
}
Also used : ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) BaseRepository(org.apache.karaf.features.internal.repository.BaseRepository) Downloader(org.apache.karaf.features.internal.download.Downloader) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BundleRevision(org.osgi.framework.wiring.BundleRevision) Deployer(org.apache.karaf.features.internal.service.Deployer) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Resource (org.osgi.resource.Resource)201 Capability (org.osgi.resource.Capability)62 Requirement (org.osgi.resource.Requirement)62 ArrayList (java.util.ArrayList)57 List (java.util.List)39 HashMap (java.util.HashMap)32 File (java.io.File)27 Collection (java.util.Collection)24 Wire (org.osgi.resource.Wire)24 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)23 Map (java.util.Map)22 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)18 URI (java.net.URI)18 HashSet (java.util.HashSet)18 BndEditModel (aQute.bnd.build.model.BndEditModel)15 MockRegistry (test.lib.MockRegistry)15 Version (org.osgi.framework.Version)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)14 Repository (org.osgi.service.repository.Repository)14 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)13