Search in sources :

Example 1 with Expression

use of aQute.bnd.osgi.resource.FilterParser.Expression in project bnd by bndtools.

the class ResolveCommand method _query.

public void _query(QueryOptions options) throws Exception {
    List<String> args = options._arguments();
    String bsn = args.remove(0);
    String version = null;
    if (!args.isEmpty())
        version = args.remove(0);
    ProjectResolver pr = new ProjectResolver(bnd.getProject(options.project()));
    addClose(pr);
    IdentityCapability resource = pr.getResource(bsn, version);
    bnd.out.printf("%-30s %-20s %s\n", resource.osgi_identity(), resource.version(), resource.description(""));
    Resource r = resource.getResource();
    FilterParser p = new FilterParser();
    if (r != null) {
        List<Requirement> requirements = resource.getResource().getRequirements(null);
        if (!requirements.isEmpty()) {
            bnd.out.println("Requirements:");
            for (Requirement req : requirements) {
                Expression parse = p.parse(req);
                bnd.out.printf("  %-20s %s\n", req.getNamespace(), parse);
            }
        }
        List<Capability> capabilities = resource.getResource().getCapabilities(null);
        if (!capabilities.isEmpty()) {
            bnd.out.println("Capabilities:");
            for (Capability cap : capabilities) {
                Map<String, Object> attrs = new HashMap<String, Object>(cap.getAttributes());
                Object id = attrs.remove(cap.getNamespace());
                Object vv = attrs.remove("version");
                if (vv == null)
                    vv = attrs.remove("bundle-version");
                bnd.out.printf("  %-20s %-40s %-20s attrs=%s dirs=%s\n", cap.getNamespace(), id, vv, attrs, cap.getDirectives());
            }
        }
    }
}
Also used : Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) HashMap(java.util.HashMap) ProjectResolver(biz.aQute.resolve.ProjectResolver) Resource(org.osgi.resource.Resource) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Requirement(org.osgi.resource.Requirement) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 2 with Expression

use of aQute.bnd.osgi.resource.FilterParser.Expression in project bndtools by bndtools.

the class RequirementLabelProvider method requirementToUrl.

/**
     * This method return a query string (on jpm) based on a filter. This is not exact, but should in general give a
     * list to work from
     *
     * @param req
     *            The requirement searched
     * @return a query string where p: is for package and bsn: is for bundle symbolic name.
     */
public static String requirementToUrl(Requirement req) throws IOException {
    FilterParser fp = new FilterParser();
    Expression expression = fp.parse(req);
    String s = expression.query();
    return "http://jpm4j.org/#!/search?q=" + URLEncoder.encode(s, "UTF-8");
}
Also used : Expression(aQute.bnd.osgi.resource.FilterParser.Expression) StyledString(org.eclipse.jface.viewers.StyledString) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 3 with Expression

use of aQute.bnd.osgi.resource.FilterParser.Expression in project bnd by bndtools.

the class PermissionGenerator method getReferencedServices.

public static Set<String> getReferencedServices(Builder builder) {
    Set<String> referencedServices = new TreeSet<>();
    for (Entry<String, Attrs> entry : builder.getRequireCapability().entrySet()) {
        if (Processor.removeDuplicateMarker(entry.getKey()).equals("osgi.service")) {
            Attrs attrs = entry.getValue();
            String filter = attrs.get("filter:");
            if (filter != null && !filter.isEmpty()) {
                FilterParser filterParser = new FilterParser();
                Expression expr = filterParser.parse(filter);
                referencedServices.addAll(expr.visit(new FindReferencedServices()));
            }
        }
    }
    if (referencedServices.contains(MATCH_ALL)) {
        return Collections.singleton(MATCH_ALL);
    } else {
        return referencedServices;
    }
}
Also used : Expression(aQute.bnd.osgi.resource.FilterParser.Expression) PatternExpression(aQute.bnd.osgi.resource.FilterParser.PatternExpression) SimpleExpression(aQute.bnd.osgi.resource.FilterParser.SimpleExpression) TreeSet(java.util.TreeSet) Attrs(aQute.bnd.header.Attrs) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 4 with Expression

use of aQute.bnd.osgi.resource.FilterParser.Expression 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());
}
Also used : Expression(aQute.bnd.osgi.resource.FilterParser.Expression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression)

Example 5 with Expression

use of aQute.bnd.osgi.resource.FilterParser.Expression in project bnd by bndtools.

the class FilterParserTest method testReduce.

public void testReduce() throws IOException {
    Expression exp = fp.parse("(&(osgi.wiring.package=package)(!(version>=2.0.0))(version>=1.0.0))");
    System.out.println(exp);
}
Also used : Expression(aQute.bnd.osgi.resource.FilterParser.Expression) WithRangeExpression(aQute.bnd.osgi.resource.FilterParser.WithRangeExpression)

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