use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class CapReqBuilder method createRequirementFromCapability.
public static RequirementBuilder createRequirementFromCapability(Capability cap) {
RequirementBuilder req = new RequirementBuilder(cap.getNamespace());
StringBuilder sb = new StringBuilder("(&");
for (Entry<String, Object> e : cap.getAttributes().entrySet()) {
Object v = e.getValue();
if (v instanceof Version || e.getKey().equals("version")) {
VersionRange r = new VersionRange(v.toString());
String filter = r.toFilter();
sb.append(filter);
} else
sb.append("(").append(e.getKey()).append("=").append(escapeFilterValue((String) v)).append(")");
}
sb.append(")");
req.and(sb.toString());
return req;
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class Filters method fromVersionRange.
/**
* Generate an LDAP-style version filter from a version range, using a
* specific attribute name for the version; for example can be used to
* generate a range using the {@code bundle-version} attribute such as
* {@code (&(bundle-version>=1.0)(!(bundle-version>=2.0))}.
*
* @param range
* @param versionAttr
* @return The generated filter
* @throws IllegalArgumentException If the supplied range is invalid.
*/
public static String fromVersionRange(String range, String versionAttr) throws IllegalArgumentException {
if (range == null)
return null;
VersionRange parsedRange = new VersionRange(range);
Filter left;
if (parsedRange.includeLow())
left = new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, parsedRange.getLow().toString());
else
left = new NotFilter(new SimpleFilter(versionAttr, Operator.LessThanOrEqual, parsedRange.getLow().toString()));
Filter right;
if (!parsedRange.isRange())
right = null;
else if (parsedRange.includeHigh())
right = new SimpleFilter(versionAttr, Operator.LessThanOrEqual, parsedRange.getHigh().toString());
else
right = new NotFilter(new SimpleFilter(versionAttr, Operator.GreaterThanOrEqual, parsedRange.getHigh().toString()));
Filter result;
if (right != null)
result = new AndFilter().addChild(left).addChild(right);
else
result = left;
return result.toString();
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class ResourceBuilder method addFragmentHost.
public void addFragmentHost(String bsn, Attrs attrs) throws Exception {
CapReqBuilder rbb = new CapReqBuilder(resource, HostNamespace.HOST_NAMESPACE);
rbb.addDirectives(attrs);
StringBuilder filter = new StringBuilder();
filter.append("(").append(HostNamespace.HOST_NAMESPACE).append("=").append(bsn).append(")");
String v = attrs.get(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
if (v != null && VersionRange.isOSGiVersionRange(v)) {
VersionRange range = VersionRange.parseOSGiVersionRange(v);
filter.insert(0, "(&");
filter.append(range.toFilter(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
filter.append(")");
}
rbb.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
addRequirement(rbb.buildRequirement());
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class Analyzer method cleanupVersion.
public static String cleanupVersion(String version) {
if (version == null)
return "0";
Matcher m = Verifier.VERSIONRANGE.matcher(version);
if (m.matches()) {
try {
VersionRange vr = new VersionRange(version);
return version;
} catch (Exception e) {
// ignore
}
}
m = fuzzyVersionRange.matcher(version);
if (m.matches()) {
String prefix = m.group(1);
String first = m.group(2);
String last = m.group(3);
String suffix = m.group(4);
return prefix + cleanupVersion(first) + "," + cleanupVersion(last) + suffix;
}
m = fuzzyVersion.matcher(version);
if (m.matches()) {
StringBuilder result = new StringBuilder();
String major = removeLeadingZeroes(m.group(1));
String minor = removeLeadingZeroes(m.group(3));
String micro = removeLeadingZeroes(m.group(5));
String qualifier = m.group(7);
if (qualifier == null) {
if (!isInteger(minor)) {
qualifier = minor;
minor = "0";
} else if (!isInteger(micro)) {
qualifier = micro;
micro = "0";
}
}
if (major != null) {
result.append(major);
if (minor != null) {
result.append(".");
result.append(minor);
if (micro != null) {
result.append(".");
result.append(micro);
if (qualifier != null) {
result.append(".");
cleanupModifier(result, qualifier);
}
} else if (qualifier != null) {
result.append(".0.");
cleanupModifier(result, qualifier);
}
} else if (qualifier != null) {
result.append(".0.0.");
cleanupModifier(result, qualifier);
}
return result.toString();
}
}
return version;
}
use of aQute.bnd.version.VersionRange in project bnd by bndtools.
the class LocalIndexedRepo method getHandle.
private ResourceHandle getHandle(Object... target) throws Exception {
String bsn = (String) target[0];
Version v = (Version) target[1];
VersionRange r = new VersionRange("[" + v.getWithoutQualifier() + "," + v.getWithoutQualifier() + "]");
ResourceHandle[] handles = getHandles(bsn, r.toString());
if (handles == null || handles.length == 0) {
return null;
}
ResourceHandle h = handles[0];
return h;
}
Aggregations