Search in sources :

Example 56 with Builder

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

the class BuilderTest method testSplitWhenPrivateOverlapsExport.

/**
	 * Got a split package warning during verify when private overlaps with
	 * export
	 */
public static void testSplitWhenPrivateOverlapsExport() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(IO.getFile("jar/osgi.jar"));
        b.setProperty("Private-Package", "org.osgi.service.*");
        b.setProperty("Export-Package", "org.osgi.service.event");
        b.build();
        assertTrue(b.check());
    } finally {
        b.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder)

Example 57 with Builder

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

the class BuilderTest method testConditional2.

/**
	 * It looks like Conditional-Package can add the same package multiple
	 * times. So lets test this.
	 */
public static void testConditional2() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.EXPORT_PACKAGE, "org.osgi.service.log");
    base.put(Analyzer.CONDITIONAL_PACKAGE, "org.osgi.*");
    Builder analyzer = new Builder();
    try {
        analyzer.setProperties(base);
        analyzer.setClasspath(new File[] { IO.getFile("jar/osgi.jar") });
        analyzer.build();
        assertTrue(analyzer.check("private references"));
        Jar jar = analyzer.getJar();
        assertTrue(analyzer.check());
        assertNotNull(analyzer.getExports().getByFQN("org.osgi.service.log"));
        assertNotNull(jar.getDirectories().get("org/osgi/framework"));
    } finally {
        analyzer.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Example 58 with Builder

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

the class CalltreeTest method testCalltree.

@SuppressWarnings("restriction")
public static void testCalltree() throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Private-Package", "test");
    b.build();
    Collection<Clazz> clazzes = b.getClassspace().values();
    assertTrue(clazzes.size() > 10);
    CalltreeResource.writeCalltree(pw, clazzes);
    pw.close();
    System.err.println(sw.toString());
}
Also used : StringWriter(java.io.StringWriter) Builder(aQute.bnd.osgi.Builder) Clazz(aQute.bnd.osgi.Clazz) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 59 with Builder

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

the class ContainerTest method testBundleClasspath.

public void testBundleClasspath() throws Exception {
    try (Builder b = new Builder()) {
        b.addClasspath(new File("bin"));
        b.setBundleClasspath(".,osgi.jar");
        b.setIncludeResource("jar/osgi.jar");
        b.setExportPackage("test.annotation");
        b.setProperty("Hello", "World");
        b.build();
        assertTrue(b.check());
        File testjar = IO.getFile(tmp, "test.jar");
        b.getJar().write(testjar);
        Attrs attrs = new Attrs();
        attrs.put("expand-bcp", "true");
        Container c = new Container(testjar, null, attrs);
        List<File> files = new ArrayList<>();
        c.contributeFiles(files, b);
        assertEquals(2, files.size());
        assertEquals(files.get(0).getCanonicalFile(), testjar.getCanonicalFile());
    }
}
Also used : Container(aQute.bnd.build.Container) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) File(java.io.File)

Example 60 with Builder

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

the class ContractTest method testUnused.

/**
	 * Make sure we do not add a contract if not used
	 * 
	 * @throws Exception
	 */
public void testUnused() throws Exception {
    Jar bjara = getContractExporter("atest", "2.5", "${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());
    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)

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