Search in sources :

Example 1 with Filter

use of aQute.lib.filter.Filter in project bnd by bndtools.

the class Analyzer method doRequireBnd.

/**
	 * Ensure that we are running on the correct bnd.
	 */
protected void doRequireBnd() {
    Attrs require = OSGiHeader.parseProperties(getProperty(REQUIRE_BND));
    if (require == null || require.isEmpty())
        return;
    Hashtable<String, String> map = new Hashtable<String, String>();
    map.put(Constants.VERSION_FILTER, getBndVersion());
    for (String filter : require.keySet()) {
        try {
            Filter f = new Filter(filter);
            if (f.match(map))
                continue;
            error("%s fails for filter %s values=%s", REQUIRE_BND, require.get(filter), map);
        } catch (Exception t) {
            exception(t, "%s with value %s throws exception", REQUIRE_BND, require);
        }
    }
}
Also used : Filter(aQute.lib.filter.Filter) Hashtable(java.util.Hashtable) Attrs(aQute.bnd.header.Attrs) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with Filter

use of aQute.lib.filter.Filter in project bnd by bndtools.

the class ResourceBuilder method findCapabilities.

public List<Capability> findCapabilities(String ns, String filter) throws Exception {
    if (filter == null || capabilities.isEmpty())
        return Collections.emptyList();
    List<Capability> capabilities = new ArrayList<Capability>();
    Filter f = new Filter(filter);
    for (Capability c : getCapabilities()) {
        if (ns != null && !ns.equals(c.getNamespace()))
            continue;
        Map<String, Object> attributes = c.getAttributes();
        if (attributes != null) {
            if (f.matchMap(attributes))
                capabilities.add(c);
        }
    }
    return capabilities;
}
Also used : Capability(org.osgi.resource.Capability) Filter(aQute.lib.filter.Filter) ArrayList(java.util.ArrayList)

Example 3 with Filter

use of aQute.lib.filter.Filter in project bnd by bndtools.

the class bnd method _select.

@Description("Helps finding information in a set of JARs by filtering on manifest data and printing out selected information.")
public void _select(selectOptions opts) throws Exception {
    PrintStream out = this.out;
    Filter filter = null;
    if (opts.where() != null) {
        String w = opts.where();
        if (!w.startsWith("("))
            w = "(" + w + ")";
        filter = new Filter(w);
    }
    Instructions instructions = new Instructions(opts.header());
    for (String s : opts._arguments()) {
        Jar jar = getJar(s);
        if (jar == null) {
            err.println("no file " + s);
            continue;
        }
        Domain domain = Domain.domain(jar.getManifest());
        Hashtable<String, Object> ht = new Hashtable<String, Object>();
        Iterator<String> i = domain.iterator();
        Set<String> realNames = new HashSet<String>();
        while (i.hasNext()) {
            String key = i.next();
            String value = domain.get(key).trim();
            ht.put(key.trim().toLowerCase(), value);
            realNames.add(key);
        }
        ht.put("resources", jar.getResources().keySet());
        realNames.add("resources");
        if (filter != null) {
            if (!filter.match(ht))
                continue;
        }
        Set<Instruction> unused = new HashSet<Instruction>();
        Collection<String> select = instructions.select(realNames, unused, true);
        for (String h : select) {
            if (opts.path()) {
                out.print(jar.getSource().getAbsolutePath() + ":");
            }
            if (opts.name()) {
                out.print(jar.getSource().getName() + ":");
            }
            if (opts.key()) {
                out.print(h + ":");
            }
            out.println(ht.get(h.toLowerCase()));
        }
        for (Instruction ins : unused) {
            String literal = ins.getLiteral();
            if (literal.equals("name"))
                out.println(jar.getSource().getName());
            else if (literal.equals("path"))
                out.println(jar.getSource().getAbsolutePath());
            else if (literal.equals("size") || literal.equals("length"))
                out.println(jar.getSource().length());
            else if (literal.equals("modified"))
                out.println(new Date(jar.getSource().lastModified()));
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Hashtable(java.util.Hashtable) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) Date(java.util.Date) FilenameFilter(java.io.FilenameFilter) Filter(aQute.lib.filter.Filter) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) Description(aQute.lib.getopt.Description)

Example 4 with Filter

use of aQute.lib.filter.Filter in project bnd by bndtools.

the class Verifier method verifyRequirements.

private void verifyRequirements() throws IllegalArgumentException, Exception {
    Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.REQUIRE_CAPABILITY));
    for (String key : map.keySet()) {
        verifyNamespace(key, "Require");
        Attrs attrs = map.get(key);
        verify(attrs, "filter:", FILTERPATTERN, false, "Requirement %s filter not correct", key);
        String filter = attrs.get("filter:");
        if (filter != null) {
            String verify = new Filter(filter).verify();
            if (verify != null)
                error("Invalid filter syntax in requirement %s=%s. Reason %s", key, attrs, verify);
        }
        verify(attrs, "cardinality:", CARDINALITY_PATTERN, false, "Requirement %s cardinality not correct", key);
        verify(attrs, "resolution:", RESOLUTION_PATTERN, false, "Requirement %s resolution not correct", key);
        if (key.equals("osgi.extender")) {
        // No requirements on extender
        } else if (key.equals("osgi.serviceloader")) {
        } else if (key.equals("osgi.contract")) {
        } else if (key.equals("osgi.service")) {
        } else if (key.equals("osgi.ee")) {
        } else if (key.equals("osgi.native")) {
        } else if (key.equals("osgi.identity")) {
        } else if (key.startsWith("osgi.wiring.")) {
            error("%s namespace must not be specified with generic requirements", key);
        }
        verifyAttrs(key, attrs);
        if (attrs.containsKey("mandatory:"))
            error("%s directive is intended for Capabilities, not Requirement %s", "mandatory:", key);
        if (attrs.containsKey("uses:"))
            error("%s directive is intended for Capabilities, not Requirement %s", "uses:", key);
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Filter(aQute.lib.filter.Filter) Attrs(aQute.bnd.header.Attrs)

Aggregations

Filter (aQute.lib.filter.Filter)4 Attrs (aQute.bnd.header.Attrs)2 Hashtable (java.util.Hashtable)2 Parameters (aQute.bnd.header.Parameters)1 Domain (aQute.bnd.osgi.Domain)1 Instruction (aQute.bnd.osgi.Instruction)1 Instructions (aQute.bnd.osgi.Instructions)1 Jar (aQute.bnd.osgi.Jar)1 Description (aQute.lib.getopt.Description)1 FileNotFoundException (java.io.FileNotFoundException)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Capability (org.osgi.resource.Capability)1