Search in sources :

Example 6 with Capability

use of io.fabric8.agent.model.Capability in project fabric8 by jboss-fuse.

the class BaseRepository method addResource.

protected void addResource(Resource resource) {
    for (Capability cap : resource.getCapabilities(null)) {
        String ns = cap.getNamespace();
        CapabilitySet set = capSets.get(ns);
        if (set == null) {
            if ("service-reference".equals(ns) || "osgi.service".equals(ns)) {
                set = new CapabilitySet(Collections.singletonList("objectClass"));
            } else {
                set = new CapabilitySet(Collections.singletonList(ns));
            }
            capSets.put(ns, set);
        }
        set.addCapability(cap);
    }
    resources.add(resource);
}
Also used : Capability(org.osgi.resource.Capability) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Example 7 with Capability

use of io.fabric8.agent.model.Capability in project fabric8 by jboss-fuse.

the class BaseRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    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.<Capability>emptyList());
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RequirementImpl(io.fabric8.agent.resolver.RequirementImpl) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Collection(java.util.Collection) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Example 8 with Capability

use of io.fabric8.agent.model.Capability in project fabric8 by jboss-fuse.

the class RequirementSort method sort.

/**
 * Sorts {@link org.osgi.resource.Resource} based on their {@link org.osgi.resource.Requirement}s and {@link org.osgi.resource.Capability}s.
 */
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(io.fabric8.agent.resolver.CapabilitySet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Capability (org.osgi.resource.Capability)7 Resource (org.osgi.resource.Resource)5 CapabilitySet (io.fabric8.agent.resolver.CapabilitySet)4 HashMap (java.util.HashMap)4 Requirement (org.osgi.resource.Requirement)4 SimpleFilter (io.fabric8.agent.resolver.SimpleFilter)3 ResourceUtils.addIdentityRequirement (io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement)2 Collection (java.util.Collection)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 DictionaryAsMap (org.apache.felix.utils.collections.DictionaryAsMap)2 BundleRevision (org.osgi.framework.wiring.BundleRevision)2 BundleInfo (io.fabric8.agent.model.BundleInfo)1 Capability (io.fabric8.agent.model.Capability)1 Dependency (io.fabric8.agent.model.Dependency)1 Requirement (io.fabric8.agent.model.Requirement)1 CapabilityImpl (io.fabric8.agent.resolver.CapabilityImpl)1 RequirementImpl (io.fabric8.agent.resolver.RequirementImpl)1 ResourceImpl (io.fabric8.agent.resolver.ResourceImpl)1 ArrayList (java.util.ArrayList)1