Search in sources :

Example 21 with ResourceBuilder

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")));
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) Version(org.osgi.framework.Version) Jar(aQute.bnd.osgi.Jar) ArrayList(java.util.ArrayList) List(java.util.List) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 22 with ResourceBuilder

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);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) FilterParser(aQute.bnd.osgi.resource.FilterParser)

Example 23 with ResourceBuilder

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));
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 24 with ResourceBuilder

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);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource)

Example 25 with ResourceBuilder

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);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder)

Aggregations

ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)41 Resource (org.osgi.resource.Resource)22 File (java.io.File)13 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)8 Capability (org.osgi.resource.Capability)8 Requirement (org.osgi.resource.Requirement)8 Parameters (aQute.bnd.header.Parameters)6 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)6 Version (org.osgi.framework.Version)6 Domain (aQute.bnd.osgi.Domain)5 Resolution (biz.aQute.resolve.ResolverValidator.Resolution)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Processor (aQute.bnd.osgi.Processor)3 HashMap (java.util.HashMap)3 List (java.util.List)3 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 Referral (aQute.bnd.deployer.repository.api.Referral)2