use of aQute.bnd.osgi.resource.FilterParser.WithRangeExpression in project bnd by bndtools.
the class FilterParserTest method testBundleRange.
public void testBundleRange() throws Exception {
Expression expression = fp.parse("(&(osgi.wiring.bundle=B)(bundle-version>=1.0.0)(!(bundle-version>=2.0.0)))");
assertTrue(expression instanceof WithRangeExpression);
assertEquals("[1.0.0,2.0.0)", ((WithRangeExpression) expression).getRangeExpression().getRangeString());
}
use of aQute.bnd.osgi.resource.FilterParser.WithRangeExpression in project bnd by bndtools.
the class FilterParserTest method testPackageRange.
public void testPackageRange() throws Exception {
Expression expression = fp.parse("(&(osgi.wiring.package=A)(version>=1.0.0)(!(version>=2.0.0)))");
assertTrue(expression instanceof WithRangeExpression);
assertEquals("[1.0.0,2.0.0)", ((WithRangeExpression) expression).getRangeExpression().getRangeString());
}
use of aQute.bnd.osgi.resource.FilterParser.WithRangeExpression in project bndtools by bndtools.
the class R5LabelFormatter method appendRequirementLabel.
public static void appendRequirementLabel(StyledString label, Requirement requirement, boolean shorten) {
String namespace = requirement.getNamespace();
String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
boolean optional = Namespace.RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
FilterParser fp = new FilterParser();
if (filter == null) {
if (namespace.contains("$")) {
Pattern pattern = Pattern.compile("\\{(.*?)\\}");
Matcher matcher = pattern.matcher(namespace);
label.append(namespace);
while (matcher.find()) {
int begin = matcher.start(1);
int end = matcher.end(1);
label.setStyle(begin, end - begin, BoldStyler.INSTANCE_DEFAULT);
}
} else {
label.append(namespace + ": <no filter>", ItalicStyler.INSTANCE_ERROR);
}
} else {
try {
Expression exp = fp.parse(filter);
if (exp instanceof WithRangeExpression) {
appendNamespaceWithValue(label, namespace, ((WithRangeExpression) exp).printExcludingRange(), shorten);
RangeExpression range = ((WithRangeExpression) exp).getRangeExpression();
if (range != null)
label.append(" ").append(formatRangeString(range), StyledString.COUNTER_STYLER);
} else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(namespace)) {
Matcher matcher = EE_PATTERN.matcher(filter);
if (matcher.find()) {
String eename = matcher.group(1);
String version = matcher.group(2);
appendNamespaceWithValue(label, namespace, eename, true);
label.append(" ").append(version, StyledString.COUNTER_STYLER);
} else {
appendNamespaceWithValue(label, namespace, filter, true);
}
} else {
appendNamespaceWithValue(label, namespace, filter, true);
}
} catch (Exception e) {
label.append(namespace + ": ", StyledString.QUALIFIER_STYLER);
label.append("<parse error>", ItalicStyler.INSTANCE_ERROR);
}
}
boolean first = true;
for (Entry<String, String> directive : requirement.getDirectives().entrySet()) {
if (Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE.equals(directive.getKey()) || Namespace.REQUIREMENT_FILTER_DIRECTIVE.equals(directive.getKey()))
// deal with the filter: and resolution: directives separately
continue;
StringBuilder buf = new StringBuilder();
buf.append(first ? " " : ", ");
buf.append(directive.getKey()).append(":=").append(directive.getValue());
label.append(buf.toString(), StyledString.QUALIFIER_STYLER);
first = false;
}
if (optional) {
label.setStyle(0, label.length(), StyledString.QUALIFIER_STYLER);
label.append(" <optional>", ItalicStyler.INSTANCE_DEFAULT);
}
}
Aggregations