use of aQute.bnd.osgi.resource.FilterParser.Expression in project bnd by bndtools.
the class Utils method parseException.
public static List<ResolveTrace> parseException(String message) {
Matcher m = RESOLVE_MESSAGE_P.matcher(message);
List<ResolveTrace> result = new ArrayList<Utils.ResolveTrace>();
while (m.lookingAt()) {
ResolveTrace rt = new ResolveTrace();
rt.bsn = m.group("bsn");
rt.message = m.group("msg");
rt.version = m.group("version");
String namespace = m.group("ns");
String attrs = m.group("attrs");
String dirs = m.group("directives");
try {
Matcher filter = RESOLVE_DIRECTIVES_P.matcher(dirs);
if (filter.matches()) {
String f = filter.group("filter");
Expression parse = fp.parse(f);
rt.requirement = parse.toString();
} else
rt.requirement = "[" + namespace + "] {" + attrs + "} {" + dirs + "}";
} catch (Exception e) {
rt.requirement = "[" + namespace + "] {" + attrs + "} {" + dirs + "} " + e;
}
result.add(rt);
}
return result;
}
use of aQute.bnd.osgi.resource.FilterParser.Expression 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