Search in sources :

Example 1 with FilterParser

use of aQute.bnd.osgi.resource.FilterParser 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 FilterParser

use of aQute.bnd.osgi.resource.FilterParser 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 FilterParser

use of aQute.bnd.osgi.resource.FilterParser 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 FilterParser

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

the class FilterParserTest method testSpaces.

public void testSpaces() throws Exception {
    FilterParser p = new FilterParser();
    p.parse("(| (a=b) (b=c) )");
    p.parse("(| (&(osgi.ee=JavaSE)(version=1.6)) (&(osgi.ee=JavaSE/compact1)(version=1.8)) )");
    p.parse("(  &  (   org.osgi.framework.windowing.system   =   xyz    )     )");
    p.parse("( | ( org.osgi.framework.windowing.system=xyz))");
}
Also used : FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 5 with FilterParser

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

the class NativeCodeHeaderTest method testNative.

public void testNative() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    Requirement nativeCode = //
    rb.getNativeCode(//
    "f1;" + //
    "  osname=Windows95;" + //
    "  processor=x86;" + //
    "  selection-filter='(com.acme.windowing=win32)';" + //
    "  language=en;" + //
    "  osname=Windows98;" + //
    "  language=se, " + //
    "lib/solaris/libhttp.so;" + //
    "  osname=Solaris;" + //
    "  osname = SunOS ;" + //
    "  processor = sparc, " + //
    "lib/linux/libhttp.so ; " + //
    "  osname = Linux ; " + //
    "  processor = mips; " + //
    "  selection-filter = '(com.acme.windowing=gtk)'," + "*").synthetic();
    assertEquals(NativeNamespace.NATIVE_NAMESPACE, nativeCode.getNamespace());
    assertEquals("optional", nativeCode.getDirectives().get("resolution"));
    String filter = nativeCode.getDirectives().get("filter");
    assertEquals(null, Verifier.validateFilter(filter));
    FilterParser p = new FilterParser();
    Expression parse = p.parse(filter);
    assertEquals("(|(&(|(osgi.native.osname=Windows95)(osgi.native.osname=Windows98))(osgi.native.processor=x86)(|(osgi.native.language=en)(osgi.native.language=se))(com.acme.windowing=win32))(&(|(osgi.native.osname=Solaris)(osgi.native.osname=SunOS))(osgi.native.processor=sparc))(&(osgi.native.osname=Linux)(osgi.native.processor=mips)(com.acme.windowing=gtk)))", filter);
    System.out.println(nativeCode);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Aggregations

FilterParser (aQute.bnd.osgi.resource.FilterParser)7 Expression (aQute.bnd.osgi.resource.FilterParser.Expression)5 SimpleExpression (aQute.bnd.osgi.resource.FilterParser.SimpleExpression)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 WithRangeExpression (aQute.bnd.osgi.resource.FilterParser.WithRangeExpression)1 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)1 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)1 ProjectResolver (biz.aQute.resolve.ProjectResolver)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Capability (org.osgi.resource.Capability)1 Resource (org.osgi.resource.Resource)1