use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ProcessorTest method assertNative.
private void assertNative(String in, String filter, String... fixup) throws Exception {
List<String> split = in == null ? new ArrayList<String>() : Strings.split("\\s*;\\s*", in);
split.add(0, "native_capability");
try (Processor p = new Processor()) {
String s = p._native_capability(split.toArray(new String[0]));
assertNotNull(s);
System.out.println(s);
ResourceBuilder rb = new ResourceBuilder();
List<Capability> capabilities = rb.addProvideCapabilities(s);
RequirementBuilder qb = new RequirementBuilder("osgi.native");
qb.addDirective("filter", filter);
List<Capability> found = ResourceUtils.findProviders(qb.synthetic(), capabilities);
assertTrue(!found.isEmpty());
assertTrue(p.check(fixup));
}
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testOSGiWiringHostFragment.
public void testOSGiWiringHostFragment() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
Resource resource = rb.build();
assertEquals(0, resource.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE).size());
assertEquals(0, resource.getCapabilities(HostNamespace.HOST_NAMESPACE).size());
List<Requirement> requirements = resource.getRequirements(HostNamespace.HOST_NAMESPACE);
assertEquals(1, requirements.size());
Map<String, String> directives = requirements.get(0).getDirectives();
assertTrue(directives.containsKey(HostNamespace.REQUIREMENT_FILTER_DIRECTIVE));
String filter = directives.get(HostNamespace.REQUIREMENT_FILTER_DIRECTIVE);
assertEquals("(&(osgi.wiring.host=demo)(&(bundle-version>=1.0.0)(!(bundle-version>=1.0.1))))", filter);
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testImportPackage.
public void testImportPackage() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
Requirement importPackage = rb.addImportPackage("com.foo", Attrs.create("version", "1.2.3").with("mandatory:", "a,b").with("a", "1").with("b", "2"));
String filter = importPackage.getDirectives().get("filter");
assertEquals("(&(osgi.wiring.package=com.foo)(version>=1.2.3)(a=1)(b=2))", filter);
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testOSGiWiringHostBundle.
public void testOSGiWiringHostBundle() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo/generated/demo.jar")));
Resource resource = rb.build();
List<Capability> capabilities = resource.getCapabilities(HostNamespace.HOST_NAMESPACE);
assertEquals(1, capabilities.size());
Map<String, Object> attributes = capabilities.get(0).getAttributes();
assertTrue(attributes.containsKey(HostNamespace.HOST_NAMESPACE));
assertTrue(attributes.containsKey(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
assertEquals("demo", attributes.get(HostNamespace.HOST_NAMESPACE));
assertNotNull(attributes.get(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
assertEquals(0, resource.getRequirements(HostNamespace.HOST_NAMESPACE).size());
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testResourceToVersionedClause.
public void testResourceToVersionedClause() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
Resource resource = rb.build();
VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
StringBuilder sb = new StringBuilder();
versionClause.formatTo(sb);
assertEquals("demo-fragment;version='[1.0.0,1.0.1)'", sb.toString());
}
Aggregations