Search in sources :

Example 36 with Requirement

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

the class AugmentRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> fromRepos = repository.findProviders(requirements);
    for (Requirement requirement : requirements) {
        List<Capability> provided = new ArrayList<>();
        boolean replaced = false;
        for (Capability originalCapability : fromRepos.get(requirement)) {
            if (isValid(originalCapability)) {
                Capability wrappedCapability = wrapped.get(originalCapability);
                if (wrappedCapability != null) {
                    provided.add(wrappedCapability);
                    replaced = true;
                } else
                    provided.add(originalCapability);
            }
        }
        Collection<Capability> additional = ResourceUtils.findProviders(requirement, augmentedCapabilities);
        replaced |= provided.addAll(additional);
        if (replaced)
            fromRepos.put(requirement, provided);
    }
    return fromRepos;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 37 with Requirement

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

the class BaseRepository method dispatch.

private void dispatch(RequirementExpression expression, Set<Resource> providers) {
    if (expression instanceof IdentityExpression) {
        Map<Requirement, Collection<Capability>> capabilities = findProviders(Collections.singleton(((IdentityExpression) expression).getRequirement()));
        for (Collection<Capability> caps : capabilities.values()) {
            for (Capability c : caps) providers.add(c.getResource());
        }
    } else if (expression instanceof OrExpression) {
        for (RequirementExpression re : ((OrExpression) expression).getRequirementExpressions()) dispatch(re, providers);
    } else if (expression instanceof AndExpression) {
        List<RequirementExpression> requirementExpressions = ((AndExpression) expression).getRequirementExpressions();
        if (requirementExpressions.isEmpty())
            return;
        if (requirementExpressions.size() == 1) {
            dispatch(requirementExpressions.get(0), providers);
            return;
        }
        Set<Resource> subset = new HashSet<>();
        dispatch(requirementExpressions.get(0), subset);
        for (int i = 1; i < requirementExpressions.size(); i++) {
            for (Iterator<Resource> it = subset.iterator(); it.hasNext(); ) {
                Resource resource = it.next();
                RequirementExpression re = requirementExpressions.get(i);
                if (!matches(re, resource)) {
                    it.remove();
                    if (subset.isEmpty())
                        return;
                }
            }
        }
        providers.addAll(subset);
    } else if (expression instanceof NotExpression) {
        Set<Resource> allSet = new HashSet<>();
        dispatch(all, allSet);
        RequirementExpression re = ((NotExpression) expression).getRequirementExpression();
        for (Iterator<Resource> it = allSet.iterator(); it.hasNext(); ) {
            Resource resource = it.next();
            if (matches(re, resource)) {
                it.remove();
                if (allSet.isEmpty())
                    return;
            }
        }
        providers.addAll(allSet);
    } else
        throw new UnsupportedOperationException("Unknown expression type " + expression.getClass());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) NotExpression(org.osgi.service.repository.NotExpression) OrExpression(org.osgi.service.repository.OrExpression) Requirement(org.osgi.resource.Requirement) AndExpression(org.osgi.service.repository.AndExpression) RequirementExpression(org.osgi.service.repository.RequirementExpression) Iterator(java.util.Iterator) Collection(java.util.Collection) IdentityExpression(org.osgi.service.repository.IdentityExpression) HashSet(java.util.HashSet)

Example 38 with Requirement

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

the class BridgeRepository method index.

private void index() throws Exception {
    Map<Requirement, Collection<Capability>> all = repository.findProviders(Collections.singleton(allRq));
    for (Capability capability : all.get(allRq)) {
        Resource r = capability.getResource();
        index(r);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability) Resource(org.osgi.resource.Resource) Collection(java.util.Collection)

Example 39 with Requirement

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

the class ResourcesRepository method findProviders.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    MultiMap<Requirement, Capability> result = new MultiMap<>();
    for (Requirement requirement : requirements) {
        List<Capability> capabilities = findProvider(requirement);
        result.put(requirement, capabilities);
    }
    return (Map) result;
}
Also used : MultiMap(aQute.lib.collections.MultiMap) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map)

Example 40 with Requirement

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

the class XMLResourceGenerator method repository.

public XMLResourceGenerator repository(Repository repository) throws Exception {
    Requirement wildcard = ResourceUtils.createWildcardRequirement();
    Map<Requirement, Collection<Capability>> findProviders = repository.findProviders(Collections.singleton(wildcard));
    for (Capability capability : findProviders.get(wildcard)) {
        resource(capability.getResource());
    }
    return this;
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) Collection(java.util.Collection)

Aggregations

Requirement (org.osgi.resource.Requirement)201 Capability (org.osgi.resource.Capability)103 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)51 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 HashMap (java.util.HashMap)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)16 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9