Search in sources :

Example 11 with Expression

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;
}
Also used : Matcher(java.util.regex.Matcher) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) ArrayList(java.util.ArrayList)

Example 12 with Expression

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) RangeExpression(aQute.bnd.osgi.resource.FilterParser.RangeExpression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) SimpleExpression(aQute.bnd.osgi.resource.FilterParser.SimpleExpression) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) RangeExpression(aQute.bnd.osgi.resource.FilterParser.RangeExpression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) StyledString(org.eclipse.jface.viewers.StyledString) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Aggregations

Expression (aQute.bnd.osgi.resource.FilterParser.Expression)12 WithRangeExpression (aQute.bnd.osgi.resource.FilterParser.WithRangeExpression)7 FilterParser (aQute.bnd.osgi.resource.FilterParser)5 SimpleExpression (aQute.bnd.osgi.resource.FilterParser.SimpleExpression)2 Matcher (java.util.regex.Matcher)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Requirement (org.osgi.resource.Requirement)2 Attrs (aQute.bnd.header.Attrs)1 PatternExpression (aQute.bnd.osgi.resource.FilterParser.PatternExpression)1 RangeExpression (aQute.bnd.osgi.resource.FilterParser.RangeExpression)1 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)1 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)1 ProjectResolver (biz.aQute.resolve.ProjectResolver)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 Pattern (java.util.regex.Pattern)1 Capability (org.osgi.resource.Capability)1 Resource (org.osgi.resource.Resource)1