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