use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class ResourceUtils method addIdentityRequirement.
public static void addIdentityRequirement(ResourceImpl resource, Resource required, boolean mandatory) {
for (Capability cap : required.getCapabilities(null)) {
if (cap.getNamespace().equals(IDENTITY_NAMESPACE)) {
Map<String, Object> attributes = cap.getAttributes();
Map<String, String> dirs = new HashMap<>();
dirs.put(REQUIREMENT_RESOLUTION_DIRECTIVE, mandatory ? RESOLUTION_MANDATORY : RESOLUTION_OPTIONAL);
Map<String, Object> attrs = new HashMap<>();
attrs.put(IDENTITY_NAMESPACE, attributes.get(IDENTITY_NAMESPACE));
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, attributes.get(CAPABILITY_TYPE_ATTRIBUTE));
Version version = (Version) attributes.get(CAPABILITY_VERSION_ATTRIBUTE);
if (version != null) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(version, true));
}
resource.addRequirement(new RequirementImpl(resource, IDENTITY_NAMESPACE, dirs, attrs));
}
}
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class SimpleFilter method convert.
/**
* Converts a attribute map to a filter. The filter is created by iterating
* over the map's entry set. If ordering of attributes is important (e.g.,
* for hitting attribute indices), then the map's entry set should iterate
* in the desired order. Equality testing is assumed for all attribute types
* other than version ranges, which are handled appropriated. If the attribute
* map is empty, then a filter that matches anything is returned.
*
* @param attrs Map of attributes to convert to a filter.
* @return A filter corresponding to the attributes.
*/
@SuppressWarnings("unchecked")
public static SimpleFilter convert(Map<String, Object> attrs) {
// Rather than building a filter string to be parsed into a SimpleFilter,
// we will just create the parsed SimpleFilter directly.
List<SimpleFilter> filters = new ArrayList<>(attrs.size());
for (Entry<String, Object> entry : attrs.entrySet()) {
if (entry.getValue() instanceof VersionRange) {
VersionRange vr = (VersionRange) entry.getValue();
if (!vr.isOpenFloor()) {
filters.add(new SimpleFilter(entry.getKey(), vr.getFloor().toString(), SimpleFilter.GTE));
} else {
SimpleFilter not = new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
((List<Object>) not.getValue()).add(new SimpleFilter(entry.getKey(), vr.getFloor().toString(), SimpleFilter.LTE));
filters.add(not);
}
if (vr.getCeiling() != null) {
if (!vr.isOpenCeiling()) {
filters.add(new SimpleFilter(entry.getKey(), vr.getCeiling().toString(), SimpleFilter.LTE));
} else if (!vr.getCeiling().equals(VersionRange.INFINITE_VERSION)) {
SimpleFilter not = new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
((List<Object>) not.getValue()).add(new SimpleFilter(entry.getKey(), vr.getCeiling().toString(), SimpleFilter.GTE));
filters.add(not);
}
}
} else {
List<String> values = SimpleFilter.parseSubstring(entry.getValue().toString());
if (values.size() > 1) {
filters.add(new SimpleFilter(entry.getKey(), values, SimpleFilter.SUBSTRING));
} else {
filters.add(new SimpleFilter(entry.getKey(), values.get(0), SimpleFilter.EQ));
}
}
}
SimpleFilter sf = null;
if (filters.size() == 1) {
sf = filters.get(0);
} else if (attrs.size() > 1) {
sf = new SimpleFilter(null, filters, SimpleFilter.AND);
} else if (filters.isEmpty()) {
sf = new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
}
return sf;
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class Subsystem method addRequirement.
protected void addRequirement(String requirement) throws BundleException {
for (Requirement req : ResourceBuilder.parseRequirement(this, requirement)) {
Object range = req.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
if (range instanceof String) {
req.getAttributes().put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange((String) range));
}
addRequirement(req);
}
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class Blacklist method isFeatureBlacklisted.
public static boolean isFeatureBlacklisted(List<String> blacklist, String name, String version) {
Clause[] clauses = Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
for (Clause clause : clauses) {
if (clause.getName().equals(name)) {
// Check feature version
VersionRange range = VersionRange.ANY_VERSION;
String vr = clause.getAttribute(BLACKLIST_RANGE);
if (vr != null) {
range = new VersionRange(vr, true);
}
if (range.contains(VersionTable.getVersion(version))) {
String type = clause.getAttribute(BLACKLIST_TYPE);
if (type == null || TYPE_FEATURE.equals(type)) {
return true;
}
}
}
}
return false;
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class Builder method addFeatures.
private void addFeatures(Set<Feature> allFeatures, String feature, Set<Feature> features, boolean mandatory) {
String name;
VersionRange range;
int idx = feature.indexOf('/');
if (idx > 0) {
name = feature.substring(0, idx);
String version = feature.substring(idx + 1);
version = version.trim();
if (version.equals(org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)) {
range = new VersionRange(Version.emptyVersion);
} else {
range = new VersionRange(version, true, true);
}
} else {
name = feature;
range = new VersionRange(Version.emptyVersion);
}
Set<Feature> set = allFeatures.stream().filter(f -> f.getName().equals(name) && range.contains(VersionTable.getVersion(f.getVersion()))).collect(Collectors.toSet());
if (mandatory && set.isEmpty()) {
throw new IllegalStateException("Could not find matching feature for " + feature);
}
for (Feature f : set) {
features.add(f);
for (Dependency dep : f.getFeature()) {
addFeatures(allFeatures, dep.toString(), features, !dep.isDependency() && !dep.isPrerequisite());
}
}
}
Aggregations