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);
}
}
}
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;
}
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()));
}
}
}
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);
}
}
Aggregations