Search in sources :

Example 61 with Builder

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

the class ContractTest method testOverlap.

/**
	 * Test if we can detect an overlap, and then if we can control the overlap
	 * 
	 * @throws Exception
	 */
public void testOverlap() throws Exception {
    Jar bjar = getContractExporter("test", "2.5", "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    // 1x
    a.addClasspath(bjar);
    // 2x
    a.addClasspath(bjar);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check("Contracts \\[Contract \\[name=test;version=2.5.0;from=biz.aQute.bndlib.tests\\], Contract \\[name=test;version=2.5.0"));
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar)

Example 62 with Builder

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

the class ContractTest method testSimple.

public void testSimple() throws Exception {
    Jar bjar = getContractExporter("test", "2.5", "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjar);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters rc = domain.getRequireCapability();
    rc.remove("osgi.ee");
    System.out.println(rc);
    assertEquals(1, rc.size());
    Packages ps = a.getImports();
    assertTrue(ps.containsFQN("org.osgi.service.cm"));
    Attrs attrs = ps.getByFQN("org.osgi.service.cm");
    assertNotNull(attrs);
    assertNull(attrs.getVersion());
}
Also used : Parameters(aQute.bnd.header.Parameters) Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 63 with Builder

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

the class ContractTest method testWarningVersion.

/**
	 * Test the warnings that we have no no version
	 * 
	 * @throws Exception
	 */
public void testWarningVersion() throws Exception {
    Jar bjara = getContractExporter("abc", (String[]) null, "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjara);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("test.packageinfo,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check("Contract \\[name=abc;version=0.0.0;from=biz.aQute.bndlib.tests] does not declare a version"));
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters p = domain.getRequireCapability();
    p.remove("osgi.ee");
    assertEquals(0, p.size());
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 64 with Builder

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

the class ContractTest method testMultiple.

public void testMultiple() throws Exception {
    Jar bjar = getContractExporter("abc", new String[] { "2.5", "2.6", "3.0", "3.1" }, "${exports}");
    Builder a = newBuilder();
    a.setTrace(true);
    a.addClasspath(bjar);
    a.setProperty(Constants.CONTRACT, "*");
    a.setImportPackage("org.osgi.service.cm,*");
    a.setProperty("Export-Package", "test.refer");
    Jar ajar = a.build();
    assertTrue(a.check());
    Domain domain = Domain.domain(ajar.getManifest());
    Parameters rc = domain.getRequireCapability();
    rc.remove("osgi.ee");
    System.out.println(rc);
    assertEquals(1, rc.size());
    assertNotNull(rc);
    assertEquals(1, rc.size());
    Attrs attrs = rc.get("osgi.contract");
    assertEquals("(&(osgi.contract=abc)(version=3.1.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 65 with Builder

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

the class BuilderTest method testIncludeResourceFromZipOneDirectory.

public static void testIncludeResourceFromZipOneDirectory() throws Exception {
    Builder bmaker = new Builder();
    try {
        Properties p = new Properties();
        p.put("Import-Package", "");
        p.put("Include-Resource", "@jar/easymock.jar!/org/easymock/**");
        bmaker.setProperties(p);
        Jar jar = bmaker.build();
        assertTrue(bmaker.check());
        assertEquals(59, jar.getResources().size());
        assertNotNull(jar.getResource("org/easymock/AbstractMatcher.class"));
    } finally {
        bmaker.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Aggregations

Builder (aQute.bnd.osgi.Builder)440 Jar (aQute.bnd.osgi.Jar)228 File (java.io.File)203 Properties (java.util.Properties)99 Manifest (java.util.jar.Manifest)99 Resource (aQute.bnd.osgi.Resource)83 Attributes (java.util.jar.Attributes)43 DocumentBuilder (javax.xml.parsers.DocumentBuilder)41 XmlTester (aQute.bnd.test.XmlTester)39 Parameters (aQute.bnd.header.Parameters)35 Document (org.w3c.dom.Document)27 Attrs (aQute.bnd.header.Attrs)21 JarResource (aQute.bnd.osgi.JarResource)20 LogService (org.osgi.service.log.LogService)17 ProjectBuilder (aQute.bnd.build.ProjectBuilder)16 Domain (aQute.bnd.osgi.Domain)16 ArrayList (java.util.ArrayList)14 DependencyGraphBuilder (org.apache.maven.shared.dependency.graph.DependencyGraphBuilder)13 HashMap (java.util.HashMap)12 Project (aQute.bnd.build.Project)10