use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class DistroCommandTest method testMultipleCapabilitiesPerNamespace.
public void testMultipleCapabilitiesPerNamespace() throws Exception {
bnd bnd = new bnd();
CommandLine cmdline = new CommandLine(null);
List<String> remoteArgs = new ArrayList<>();
RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
File distro = new File("generated/tmp/test.distro.jar");
List<String> distroArgs = new ArrayList<>();
distroArgs.add("-o");
distroArgs.add(distro.getPath());
distroArgs.add("test.distro");
distroArgs.add("1.0.0");
DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
assertTrue(distro.exists());
ResourceBuilder builder = new ResourceBuilder();
Domain manifest = Domain.domain(new Jar(distro).getManifest());
builder.addManifest(manifest);
Resource resource = builder.build();
List<Capability> capabilities = resource.getCapabilities(null);
assertNotNull(capabilities);
List<Capability> extenderCaps = resource.getCapabilities(ExtenderNamespace.EXTENDER_NAMESPACE);
int jspTaglibCapabilityCount = 0;
for (Capability capability : extenderCaps) {
Map<String, Object> attributes = capability.getAttributes();
if ("jsp.taglib".equals(attributes.get(ExtenderNamespace.EXTENDER_NAMESPACE))) {
jspTaglibCapabilityCount++;
}
}
assertEquals(2, jspTaglibCapabilityCount);
List<Capability> eeCaps = resource.getCapabilities(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
assertTrue(eeCaps.size() > 0);
Capability javaSECap = null;
for (Capability capability : eeCaps) {
Map<String, Object> attributes = capability.getAttributes();
if ("JavaSE".equals(attributes.get(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))) {
javaSECap = capability;
}
}
assertNotNull(javaSECap);
@SuppressWarnings("null") Map<String, Object> attributes = javaSECap.getAttributes();
assertTrue(attributes.containsKey("version"));
@SuppressWarnings("unchecked") List<Version> versions = (List<Version>) attributes.get("version");
assertTrue(versions.size() > 1);
assertTrue(versions.contains(new Version("1.7.0")));
assertTrue(versions.contains(new Version("1.6.0")));
assertTrue(versions.contains(new Version("1.5.0")));
assertTrue(versions.contains(new Version("1.4.0")));
assertTrue(versions.contains(new Version("1.3.0")));
}
use of aQute.bnd.osgi.resource.ResourceBuilder 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);
}
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);
}
Aggregations