Search in sources :

Example 26 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class BuilderTest method testEEMacro2.

public static void testEEMacro2() throws Exception {
    String[] packages = { "eclipse_1_1", "eclipse_1_2", "eclipse_1_3", "eclipse_1_4", "eclipse_1_5", "eclipse_1_6", "eclipse_1_7", "eclipse_jsr14", "sun_1_8" };
    String[] ees = { "JRE-1.1", "J2SE-1.2", "J2SE-1.3", "J2SE-1.4", "J2SE-1.5", "JavaSE-1.6", "JavaSE-1.7", "J2SE-1.4", "JavaSE-1.8" };
    String[] versions = { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.4", "1.8" };
    Pattern p = Pattern.compile("\\(&\\(osgi.ee=JavaSE\\)\\(version=(" + Version.VERSION_STRING + ")\\)\\)");
    for (int i = 0; i < packages.length; i++) {
        Builder b = new Builder();
        try {
            b.addClasspath(IO.getFile("compilerversions/compilerversions.jar"));
            b.setPrivatePackage(packages[i]);
            b.setBundleRequiredExecutionEnvironment("${ee}");
            Jar jar = b.build();
            assertTrue(b.check());
            Domain domain = Domain.domain(jar.getManifest());
            Parameters ee = domain.getBundleRequiredExecutionEnvironment();
            System.err.println(ee);
            assertEquals(ees[i], ee.toString());
            //
            // Check the requirements
            //
            Parameters een = domain.getRequireCapability();
            assertFalse(een.isEmpty());
            Attrs attrs = een.get("osgi.ee");
            String filter = attrs.get("filter:");
            Matcher m = p.matcher(filter);
            assertTrue(m.matches());
            assertEquals(versions[i], m.group(1));
        } finally {
            b.close();
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 27 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class ContractTest method testSelect.

/**
	 * Test if we can select
	 * 
	 * @throws Exception
	 */
public void testSelect() throws Exception {
    Jar bjara = getContractExporter("atest", "2.5", "${exports}");
    Jar bjarb = getContractExporter("btest", "2.5", "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    // 1x
    a.addClasspath(bjara);
    // 2x
    a.addClasspath(bjarb);
    a.setProperty(Constants.CONTRACT, "atest;alpha=1");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    ajar.getManifest().write(System.out);
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters p = domain.getRequireCapability();
    p.remove("osgi.ee");
    assertNotNull(p);
    assertEquals(1, p.size());
    Attrs attrs = p.get("osgi.contract");
    String alpha = attrs.get("alpha");
    assertEquals("1", alpha);
    assertEquals("(&(osgi.contract=atest)(version=2.5.0))", attrs.get("filter:"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 28 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class ResourceTest method testImportExportServiceFromManifest.

public void testImportExportServiceFromManifest() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    File f = IO.getFile("testresources/manifest/configadmin-1.8.8.mf");
    Manifest m = new Manifest(new FileInputStream(f));
    Domain d = Domain.domain(m);
    rb.addManifest(d);
    assertConfigAdminServices(rb.build());
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 29 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class AnnotationHeadersTest method testDefaultAttrs.

/**
	 * Default values of annotation attributes not included for customized
	 * webresource annotations #976
	 * <p>
	 * When I add a customized webresource annotation to a type definition, the
	 * default attributes are not included in the Require-Capability header. For
	 * example with the Jsonrpc webresource annotation this leads to the
	 * following Require-Capability in the manifest:
	 * osgi.enroute.webresource;filter:=
	 * "(&(osgi.enroute.webresource=/osgi/enroute/jsonrpc)(&(version>=1.1.1)(!(version>=2.0.0))))".
	 * Only when I explicitly add resource={"jsonrpc.js"} this is reflected in
	 * the manifest: osgi.enroute.webresource;resource:List
	 * <String>="jsonrpc.js";filter:=
	 * "(&(osgi.enroute.webresource=/osgi/enroute/jsonrpc)(&(version>=1.1.1)(!(version>=2.0.0))))",
	 * although jsonrpc.js is set as default for the resource attribute.
	 */
public void testDefaultAttrs() throws Exception {
    try (Builder b = new Builder()) {
        b.addClasspath(IO.getFile("bin"));
        b.setPrivatePackage("test.annotationheaders.attrs.defaults");
        b.build();
        assertTrue(b.check());
        b.getJar().getManifest().write(System.out);
        Domain d = Domain.domain(b.getJar().getManifest());
        Parameters rc = d.getRequireCapability();
        assertNotNull(rc);
        assertEquals(2, rc.size());
        Attrs attrs = rc.get("default-attrs");
        assertEquals("42", attrs.get("foo"));
        Parameters pc = d.getProvideCapability();
        assertNotNull(pc);
        assertEquals(1, pc.size());
        attrs = pc.get("default-attrs");
        assertEquals("42", attrs.get("foo"));
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Domain(aQute.bnd.osgi.Domain)

Example 30 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class VersionPolicyTest method testProviderType.

/**
	 * Tests if the implementation of the EventAdmin (which is marked as a
	 * ProviderType) causes the import of the api package to use the provider
	 * version policy.
	 */
public static void testProviderType() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setPrivatePackage("test.versionpolicy.implemented");
    a.setExportPackage("test.versionpolicy.api");
    // what changed so this is
    a.setImportPackage("test.versionpolicy.api");
    // not automatically
    // added?
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);
    Parameters parameters = d.getImportPackage();
    Attrs attrs = parameters.get("test.versionpolicy.api");
    assertNotNull(attrs);
    assertEquals("[1.2,1.3)", attrs.get("version"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Aggregations

Domain (aQute.bnd.osgi.Domain)36 Parameters (aQute.bnd.header.Parameters)24 Jar (aQute.bnd.osgi.Jar)24 Attrs (aQute.bnd.header.Attrs)18 File (java.io.File)18 Builder (aQute.bnd.osgi.Builder)16 Manifest (java.util.jar.Manifest)15 ArrayList (java.util.ArrayList)8 Resource (aQute.bnd.osgi.Resource)6 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)5 FileResource (aQute.bnd.osgi.FileResource)4 Container (aQute.bnd.build.Container)3 PomFromManifest (aQute.bnd.maven.PomFromManifest)3 Analyzer (aQute.bnd.osgi.Analyzer)3 Version (aQute.bnd.version.Version)3 List (java.util.List)3 DistroOptions (aQute.bnd.main.RemoteCommand.DistroOptions)2 RemoteOptions (aQute.bnd.main.RemoteCommand.RemoteOptions)2 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)2