Search in sources :

Example 71 with Builder

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

the class ClazzTest method testJiniPlatformClasses.

/**
	 * <pre>
	 *  java.lang.ArrayIndexOutOfBoundsException: 43007 [bnd] at
	 * aQute.bnd.osgi.Clazz.classConstRef(Clazz.java:1880) [bnd] at
	 * aQute.bnd.osgi.Clazz.crawl(Clazz.java:1185)
	 * </pre>
	 * 
	 * This happened on the Jini platform
	 * 
	 * @throws Exception
	 */
public void testJiniPlatformClasses() throws Exception {
    try (Builder b = new Builder()) {
        b.addClasspath(IO.getFile("jar/jsk-platform.jar"));
        b.setExportPackage("*");
        Jar build = b.build();
        assertTrue(b.check());
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar)

Example 72 with Builder

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

the class BuilderTest method testMetaInfExport.

/**
	 * Check if we export META-INF when we export the complete classpath.
	 */
public static void testMetaInfExport() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.EXPORT_PACKAGE, "*");
    Builder analyzer = new Builder();
    try {
        analyzer.setClasspath(new File[] { IO.getFile("jar/asm.jar") });
        analyzer.setProperties(base);
        analyzer.build();
        assertTrue(analyzer.check());
        assertFalse(analyzer.getExports().getByFQN("META-INF") != null);
        assertTrue(analyzer.getExports().getByFQN("org.objectweb.asm") != null);
    } finally {
        analyzer.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Properties(java.util.Properties)

Example 73 with Builder

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

the class BuilderTest method test1017UsingPrivatePackagesVersion.

/**
	 * #1017 Wrong import version range being generated On one project I depend
	 * on bundle A and bundle B. Both only export packages in version 1.0. No
	 * package is exported by both of them. But B also embeds one package from A
	 * in version 2.0 (via
	 * http://njbartlett.name/2014/05/26/static-linking.html) but that one
	 * package is not exported from B. Now if the classpath first contains B
	 * then A the import-package statement being generated for that package
	 * (being embedded in B in version 2.0 and exported from A in 1.0) has a
	 * version range starting with 2.0 (which is wrong). Only if the classpath
	 * contains A first and then B, it takes the right import version range for
	 * that package (namely starting with 1.0) I use the maven-bundle-plugin
	 * 2.5.3 with bndlib 2.4.0.
	 */
public void test1017UsingPrivatePackagesVersion() throws Exception {
    Builder A = new Builder();
    A.addClasspath(new File("jar/osgi.jar"));
    A.setExportPackage("org.osgi.service.event");
    A.build();
    assertTrue(A.check());
    Builder B = new Builder();
    B.addClasspath(new File("jar/osgi.jar"));
    B.setExportPackage("org.osgi.service.wireadmin");
    B.setPrivatePackage("org.osgi.service.event");
    B.setIncludeResource("org/osgi/service/event/packageinfo;literal='version 2.0.0'");
    B.build();
    assertTrue(B.check());
    Builder B_A = new Builder();
    B_A.addClasspath(B.getJar());
    B_A.addClasspath(A.getJar());
    B_A.addClasspath(new File("bin"));
    B_A.setPrivatePackage("test.reference_to_eventadmin");
    B_A.build();
    assertTrue(B_A.check());
    assertEquals("[1.0,2)", B_A.getImports().getByFQN("org.osgi.service.event").getVersion());
    Builder A_B = new Builder();
    A_B.addClasspath(A.getJar());
    A_B.addClasspath(B.getJar());
    A_B.addClasspath(new File("bin"));
    A_B.setPrivatePackage("test.reference_to_eventadmin");
    A_B.build();
    assertTrue(A_B.check());
    assertEquals("[1.0,2)", A_B.getImports().getByFQN("org.osgi.service.event").getVersion());
}
Also used : Builder(aQute.bnd.osgi.Builder) File(java.io.File)

Example 74 with Builder

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

the class BuilderTest method testNoImportDirective.

public static void testNoImportDirective() throws Exception {
    Builder b = new Builder();
    try {
        b.setProperty("Export-Package", "org.osgi.util.measurement, org.osgi.service.http;-noimport:=true");
        b.setProperty("Private-Package", "org.osgi.framework, test.refer");
        b.addClasspath(IO.getFile("jar/osgi.jar"));
        b.addClasspath(new File("bin"));
        Jar jar = b.build();
        assertTrue(b.check());
        Manifest m = jar.getManifest();
        String imports = m.getMainAttributes().getValue("Import-Package");
        // referred
        assertTrue(imports.contains("org.osgi.util.measurement"));
        // to
        // but
        // no
        // private
        // references
        // (does
        // not
        // use
        // fw).
        // referred
        assertFalse(imports.contains("org.osgi.service.http"));
    // to
    // but no
    // private
    // references
    // (does not
    // use
    // fw).
    } finally {
        b.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 75 with Builder

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

the class BuilderTest method testBundleClasspath.

public static void testBundleClasspath() throws Exception {
    Builder bmaker = new Builder();
    try {
        Properties p = new Properties();
        p.put("Export-Package", "test.activator;-split-package:=merge-first");
        p.put("Bundle-Activator", "test.activator.Activator");
        p.put("Import-Package", "*");
        p.put("Bundle-ClassPath", ".");
        bmaker.setProperties(p);
        bmaker.setClasspath(new File[] { new File("bin"), new File("src") });
        Jar jar = bmaker.build();
        assertTrue(bmaker.check());
        report("testBundleClasspath", bmaker, jar);
        jar.exists("testresources/activator/Activator.class");
        assertEquals(bmaker.getErrors().size(), 0);
        assertEquals(bmaker.getWarnings().size(), 0);
    } finally {
        bmaker.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties) File(java.io.File)

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