Search in sources :

Example 46 with Builder

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

the class BuilderTest method testExportVersionSource.

/**
	 * Test where the version comes from: Manifest or packageinfo
	 * 
	 * @throws Exception
	 */
public static void testExportVersionSource() throws Exception {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().putValue("Export-Package", "org.osgi.service.event;version=100");
    // Remove packageinfo
    Jar manifestOnly = new Jar(IO.getFile("jar/osgi.jar"));
    try {
        manifestOnly.remove("org/osgi/service/event/packageinfo");
        manifestOnly.setManifest(manifest);
        // Remove manifest
        Jar packageInfoOnly = new Jar(IO.getFile("jar/osgi.jar"));
        packageInfoOnly.setManifest(new Manifest());
        Jar both = new Jar(IO.getFile("jar/osgi.jar"));
        both.setManifest(manifest);
        // Only version in manifest
        Builder bms = new Builder();
        try {
            bms.addClasspath(manifestOnly);
            bms.setProperty("Export-Package", "org.osgi.service.event");
            bms.build();
            assertTrue(bms.check());
            String s = bms.getExports().getByFQN("org.osgi.service.event").get("version");
            assertEquals("100", s);
            // Only version in packageinfo
            Builder bpinfos = new Builder();
            bpinfos.addClasspath(packageInfoOnly);
            bpinfos.setProperty("Export-Package", "org.osgi.service.event");
            bpinfos.build();
            assertTrue(bpinfos.check());
            s = bpinfos.getExports().getByFQN("org.osgi.service.event").get("version");
            assertEquals("1.0.1", s);
        } finally {
            bms.close();
        }
    } finally {
        manifestOnly.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest)

Example 47 with Builder

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

the class BuilderTest method testRemoveClassFromPackage.

/**
	 * https://github.com/bndtools/bnd/issues/359 Starts with a bundle that has
	 * one package 'a' containing classes A and B. First removes B from 'a', and
	 * checks that the last modified date of the resulting bundle changed. Then
	 * removes A from 'a', and checks again that the last modified data changed.
	 */
public static void testRemoveClassFromPackage() throws Exception {
    try {
        Builder b = new Builder();
        try {
            IO.getFile("bin/a1/a").mkdirs();
            IO.copy(IO.getFile("bin/a/A.class"), IO.getFile("bin/a1/a/A.class"));
            IO.copy(IO.getFile("bin/a/B.class"), IO.getFile("bin/a1/a/B.class"));
            Jar classpath = new Jar(IO.getFile("bin/a1"));
            b.addClasspath(classpath);
            b.setPrivatePackage("a");
            Jar result = b.build();
            Resource ra = result.getResource("a/A.class");
            Resource rb = result.getResource("a/B.class");
            long lm1 = result.lastModified();
            assertTrue("Last modified date of bundle > 0", lm1 > 0);
            // windows has a very low resolution sometimes
            Thread.sleep(isWindows() ? 1000 : 100);
            IO.getFile("bin/a1/a/B.class").delete();
            classpath.remove("a/B.class");
            classpath.updateModified(System.currentTimeMillis(), "Removed file B");
            result = b.build();
            long lm2 = result.lastModified();
            assertTrue("Last modified date of bundle has increased after deleting class from package", lm2 > lm1);
            // windows has a very low resolution sometimes
            Thread.sleep(isWindows() ? 1000 : 100);
            IO.getFile("bin/a1/a/A.class").delete();
            classpath.remove("a/A.class");
            classpath.updateModified(System.currentTimeMillis(), "Removed file A");
            // windows has a very low resolution sometimes
            Thread.sleep(isWindows() ? 1000 : 100);
            result = b.build();
            long lm3 = result.lastModified();
            assertTrue("Last modified date of bundle has increased after deleting last class from package", lm3 > lm2);
        } finally {
            b.close();
        }
    } finally {
        try {
            IO.getFile("bin/a1/a/A.class").delete();
        } catch (Exception e) {
        }
        try {
            IO.getFile("bin/a1/a/B.class").delete();
        } catch (Exception e) {
        }
        try {
            IO.getFile("bin/a1/a").delete();
        } catch (Exception e) {
        }
        try {
            IO.getFile("bin/a1").delete();
        } catch (Exception e) {
        }
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) IOException(java.io.IOException)

Example 48 with Builder

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

the class BuilderTest method testMultipleExport2.

public static void testMultipleExport2() throws Exception {
    File[] cp = { IO.getFile("jar/asm.jar") };
    Builder bmaker = new Builder();
    try {
        Properties p = new Properties();
        p.setProperty("Export-Package", "org.objectweb.asm;version=1.1, org.objectweb.asm;version=1.2, org.objectweb.asm;version=2.3");
        bmaker.setProperties(p);
        bmaker.setClasspath(cp);
        Jar jar = bmaker.build();
        assertTrue(bmaker.check());
        jar.getManifest().write(System.err);
        Manifest m = jar.getManifest();
        m.write(System.err);
        String ip = m.getMainAttributes().getValue("Export-Package");
        assertTrue(ip.indexOf("org.objectweb.asm;version=\"1.1\"") >= 0);
        assertTrue(ip.indexOf("org.objectweb.asm;version=\"1.2\"") >= 0);
        assertTrue(ip.indexOf("org.objectweb.asm;version=\"2.3\"") >= 0);
    } finally {
        bmaker.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 49 with Builder

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

the class ClassParserTest method testJavaTypeAnnotations.

/**
	 * Java Type & Parameter annotations
	 * 
	 * @throws Exception
	 */
public void testJavaTypeAnnotations() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("java8/type_annotations/bin"));
    b.setExportPackage("reference.*");
    Jar build = b.build();
    assertTrue(b.check());
    assertTrue(b.getImports().containsFQN("runtime.annotations"));
    assertTrue(b.getImports().containsFQN("runtime.annotations.repeated"));
    assertFalse(b.getImports().containsFQN("invisible.annotations"));
    assertFalse(b.getImports().containsFQN("invisible.annotations.repeated"));
    assertEquals("reference.runtime.annotations.Foo,reference.runtime.annotations.ReferenceRuntime", b.getReplacer().process("${sort;${classes;ANNOTATION;runtime.annotations.RuntimeTypeAnnotation}}"));
    assertEquals("reference.invisible.annotations.ReferenceInvisible", b.getReplacer().process("${sort;${classes;ANNOTATION;invisible.annotations.InvisibleParameterAnnotation}}"));
    assertEquals("reference.runtime.annotations.ReferenceRuntime", b.getReplacer().process("${sort;${classes;ANNOTATION;runtime.annotations.RuntimeParameterAnnotation}}"));
    assertEquals("reference.invisible.annotations.ReferenceInvisible", b.getReplacer().process("${sort;${classes;ANNOTATION;invisible.annotations.InvisibleTypeAnnotation}}"));
    assertEquals("reference.invisible.annotations.ReferenceInvisible", b.getReplacer().process("${sort;${classes;ANNOTATION;invisible.annotations.InvisibleRepeatedAnnotation}}"));
    assertEquals("reference.runtime.annotations.ReferenceRuntime", b.getReplacer().process("${sort;${classes;ANNOTATION;runtime.annotations.RuntimeRepeatedAnnotation}}"));
    b.close();
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar)

Example 50 with Builder

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

the class ClasspathTest method testSimple.

/**
	 * Test if we can use URLs on the classpath
	 * 
	 * @throws Exception
	 */
public static void testSimple() throws Exception {
    Properties p = new Properties();
    p.put("-classpath", IO.getFile("jar/osgi.jar").toURI().toURL().toString());
    p.put("Export-Package", "org.osgi.service.event");
    p.put("Private-Package", "test.refer");
    Builder b = new Builder();
    b.setClasspath(new String[] { "bin" });
    b.setProperties(p);
    Jar jar = b.build();
    Manifest m = jar.getManifest();
    String importPackage = m.getMainAttributes().getValue("Import-Package");
    assertTrue(importPackage.contains("org.osgi.framework;version=\"[1.3,2)\""));
    assertTrue(importPackage.contains("org.osgi.service.event;version=\"[1.0,2)\""));
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties) Manifest(java.util.jar.Manifest)

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