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;
}
}
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;
}
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;
}
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);
}
Aggregations