Search in sources :

Example 46 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class BndrunResolveContext method postProcessProviders.

protected void postProcessProviders(Requirement requirement, Set<Capability> wired, List<Capability> candidates) {
    if (candidates.size() == 0)
        return;
    // Call resolver hooks
    for (ResolverHook resolverHook : registry.getPlugins(ResolverHook.class)) {
        resolverHook.filterMatches(requirement, candidates);
    }
    // Process the resolve preferences
    boolean prefsUsed = false;
    if (resolvePrefs != null && !resolvePrefs.isEmpty()) {
        List<Capability> insertions = new LinkedList<Capability>();
        for (Iterator<Capability> iterator = candidates.iterator(); iterator.hasNext(); ) {
            Capability cap = iterator.next();
            if (resolvePrefs.containsKey(getResourceIdentity(cap.getResource()))) {
                iterator.remove();
                insertions.add(cap);
            }
        }
        if (!insertions.isEmpty()) {
            candidates.addAll(0, insertions);
            prefsUsed = true;
        }
    }
    if (!prefsUsed) {
        for (ResolutionCallback callback : getCallbacks()) {
            callback.processCandidates(requirement, wired, candidates);
        }
    }
}
Also used : Capability(org.osgi.resource.Capability) ResolverHook(aQute.bnd.service.resolve.hook.ResolverHook) LinkedList(java.util.LinkedList)

Example 47 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class DebugReporter method doAllMembers.

private void doAllMembers() {
    header("RESOURCES");
    Requirement r = CapReqBuilder.createBundleRequirement("*", null).buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(r);
    Set<Resource> resources = ResourceUtils.getResources(providers);
    for (Resource resource : resources) {
        resource(resource);
    }
    resource(context.getSystemResource());
    nl();
}
Also used : Requirement(org.osgi.resource.Requirement) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource)

Example 48 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class AbstractResolveContext method insertHostedCapability.

@Override
public int insertHostedCapability(List<Capability> caps, HostedCapability hc) {
    init();
    Integer prioObj = resourcePriorities.get(hc.getResource());
    int priority = prioObj != null ? prioObj.intValue() : Integer.MAX_VALUE;
    for (int i = 0; i < caps.size(); i++) {
        Capability c = caps.get(i);
        Integer otherPrioObj = resourcePriorities.get(c.getResource());
        int otherPriority = otherPrioObj != null ? otherPrioObj.intValue() : 0;
        if (otherPriority > priority) {
            caps.add(i, hc);
            return i;
        }
    }
    int newIndex = caps.size();
    // the List passed by Felix does not support the
    // single-arg version of add()... it throws
    // UnsupportedOperationException
    caps.add(newIndex, hc);
    return newIndex;
}
Also used : HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability)

Example 49 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class AbstractResolveContext method findProvidersFromRepositories.

protected ArrayList<Capability> findProvidersFromRepositories(Requirement requirement, LinkedHashSet<Capability> existingWiredCapabilities) {
    // Second stage results: repository contents; may be reordered.
    ArrayList<Capability> secondStageResult = new ArrayList<Capability>();
    // Iterate over the repos
    int order = 0;
    ArrayList<Capability> repoCapabilities = new ArrayList<Capability>();
    for (Repository repo : repositories) {
        repoCapabilities.clear();
        Collection<Capability> capabilities = findProviders(repo, requirement);
        if (capabilities != null && !capabilities.isEmpty()) {
            repoCapabilities.ensureCapacity(capabilities.size());
            for (Capability capability : capabilities) {
                if (isPermitted(capability.getResource()) && isCorrectEffectiveness(requirement, capability)) {
                    repoCapabilities.add(capability);
                    setResourcePriority(order, capability.getResource());
                }
            }
            secondStageResult.addAll(repoCapabilities);
        }
        order++;
    }
    Collections.sort(secondStageResult, capabilityComparator);
    // Convert second-stage results to a list and post-process
    ArrayList<Capability> secondStageList = new ArrayList<Capability>(secondStageResult);
    // Post-processing second stage results
    postProcessProviders(requirement, existingWiredCapabilities, secondStageList);
    return secondStageList;
}
Also used : Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList)

Example 50 with Capability

use of org.osgi.resource.Capability in project bnd by bndtools.

the class AbstractResolveContext method getResources.

public List<Resource> getResources(List<Repository> repos, Requirement req) {
    Set<Resource> resources = new HashSet<Resource>();
    for (Repository repo : repos) {
        Collection<Capability> providers = findProviders(repo, req);
        resources.addAll(ResourceUtils.getResources(providers));
    }
    return new ArrayList<>(resources);
}
Also used : Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Capability (org.osgi.resource.Capability)197 Requirement (org.osgi.resource.Requirement)104 Resource (org.osgi.resource.Resource)61 ArrayList (java.util.ArrayList)40 HashMap (java.util.HashMap)39 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)37 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)35 Collection (java.util.Collection)32 MockRegistry (test.lib.MockRegistry)26 BndEditModel (aQute.bnd.build.model.BndEditModel)25 Version (org.osgi.framework.Version)20 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)17 Test (org.junit.Test)16 File (java.io.File)15 HostedCapability (org.osgi.service.resolver.HostedCapability)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 LinkedList (java.util.LinkedList)11 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)8