Search in sources :

Example 1 with CapabilitySet

use of org.apache.karaf.features.internal.resolver.CapabilitySet in project karaf by apache.

the class XmlRepository method hasResource.

private boolean hasResource(String type, String name, Version version) {
    CapabilitySet set = capSets.get(IDENTITY_NAMESPACE);
    if (set != null) {
        Map<String, Object> attrs = new HashMap<>();
        attrs.put(CAPABILITY_TYPE_ATTRIBUTE, type);
        attrs.put(IDENTITY_NAMESPACE, name);
        attrs.put(CAPABILITY_VERSION_ATTRIBUTE, version);
        SimpleFilter sf = SimpleFilter.convert(attrs);
        return !set.match(sf, true).isEmpty();
    } else {
        return false;
    }
}
Also used : HashMap(java.util.HashMap) SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter) CapabilitySet(org.apache.karaf.features.internal.resolver.CapabilitySet)

Example 2 with CapabilitySet

use of org.apache.karaf.features.internal.resolver.CapabilitySet 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 3 with CapabilitySet

use of org.apache.karaf.features.internal.resolver.CapabilitySet in project karaf by apache.

the class BaseRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<>();
    for (Requirement requirement : requirements) {
        CapabilitySet set = capSets.get(requirement.getNamespace());
        if (set != null) {
            SimpleFilter sf;
            if (requirement instanceof RequirementImpl) {
                sf = ((RequirementImpl) requirement).getFilter();
            } else {
                String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
                sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
            }
            result.put(requirement, set.match(sf, true));
        } else {
            result.put(requirement, Collections.emptyList());
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RequirementImpl(org.apache.karaf.features.internal.resolver.RequirementImpl) HashMap(java.util.HashMap) SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter) Collection(java.util.Collection) CapabilitySet(org.apache.karaf.features.internal.resolver.CapabilitySet)

Example 4 with CapabilitySet

use of org.apache.karaf.features.internal.resolver.CapabilitySet in project karaf by apache.

the class BaseRepository method addResource.

protected void addResource(Resource resource) {
    for (Capability cap : resource.getCapabilities(null)) {
        String ns = cap.getNamespace();
        capSets.computeIfAbsent(ns, n -> new CapabilitySet(Collections.singletonList(n))).addCapability(cap);
    }
    resources.add(resource);
}
Also used : Requirement(org.osgi.resource.Requirement) Logger(org.slf4j.Logger) Constants(org.osgi.framework.Constants) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CapabilitySet(org.apache.karaf.features.internal.resolver.CapabilitySet) RequirementImpl(org.apache.karaf.features.internal.resolver.RequirementImpl) ArrayList(java.util.ArrayList) Capability(org.osgi.resource.Capability) List(java.util.List) Map(java.util.Map) SimpleFilter(org.apache.karaf.features.internal.resolver.SimpleFilter) Repository(org.osgi.service.repository.Repository) Collections(java.util.Collections) Capability(org.osgi.resource.Capability) CapabilitySet(org.apache.karaf.features.internal.resolver.CapabilitySet)

Aggregations

CapabilitySet (org.apache.karaf.features.internal.resolver.CapabilitySet)4 HashMap (java.util.HashMap)3 SimpleFilter (org.apache.karaf.features.internal.resolver.SimpleFilter)3 Collection (java.util.Collection)2 RequirementImpl (org.apache.karaf.features.internal.resolver.RequirementImpl)2 Capability (org.osgi.resource.Capability)2 Requirement (org.osgi.resource.Requirement)2 Resource (org.osgi.resource.Resource)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Constants (org.osgi.framework.Constants)1 Repository (org.osgi.service.repository.Repository)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1