Search in sources :

Example 1 with CapabilitySet

use of io.fabric8.agent.resolver.CapabilitySet in project fabric8 by jboss-fuse.

the class RequirementSort method collectDependencies.

@SuppressWarnings("unchecked")
private static <T extends Resource> Set<T> collectDependencies(T resource, CapabilitySet capSet) {
    Set<T> result = new LinkedHashSet<>();
    for (Requirement requirement : resource.getRequirements(null)) {
        String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
        SimpleFilter sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
        for (Capability cap : capSet.match(sf, true)) {
            result.add((T) cap.getResource());
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter)

Example 2 with CapabilitySet

use of io.fabric8.agent.resolver.CapabilitySet 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 3 with CapabilitySet

use of io.fabric8.agent.resolver.CapabilitySet 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 4 with CapabilitySet

use of io.fabric8.agent.resolver.CapabilitySet 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)4 CapabilitySet (io.fabric8.agent.resolver.CapabilitySet)3 SimpleFilter (io.fabric8.agent.resolver.SimpleFilter)2 LinkedHashSet (java.util.LinkedHashSet)2 Requirement (org.osgi.resource.Requirement)2 RequirementImpl (io.fabric8.agent.resolver.RequirementImpl)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Resource (org.osgi.resource.Resource)1