Search in sources :

Example 36 with Builder

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

the class BuilderTest method testSplitOnExportAndPrivate.

/**
	 * There is an error that gives a split package when you export a package
	 * that is also private I think.
	 * 
	 * @throws Exception
	 */
public static void testSplitOnExportAndPrivate() 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.signature");
        p.setProperty("Private-Package", "org.objectweb.asm");
        bmaker.setProperties(p);
        bmaker.setClasspath(cp);
        bmaker.build();
        assertTrue(bmaker.check());
    } finally {
        bmaker.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Properties(java.util.Properties) File(java.io.File)

Example 37 with Builder

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

the class BuilderTest method testNoImportDirective2.

public static void testNoImportDirective2() throws Exception {
    Builder b = new Builder();
    try {
        b.setProperty("Export-Package", "org.osgi.util.measurement;-noimport:=true, org.osgi.service.http");
        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
        assertFalse(imports.contains("org.osgi.util.measurement"));
        // to
        // but
        // no
        // private
        // references
        // (does
        // not
        // use
        // fw).
        // referred
        assertTrue(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 38 with Builder

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

the class BuilderTest method testImportRangeCalculatedFromClasspath_1.

/**
	 * Check if we imported the package with the correct version range when
	 * there's an empty package in front of it in the classpath. First form.
	 */
public static void testImportRangeCalculatedFromClasspath_1() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.IMPORT_PACKAGE, "javax.servlet,javax.servlet.http");
    Builder analyzer = new Builder();
    try {
        analyzer.addClasspath(new File("bin"));
        analyzer.setPrivatePackage("test");
        analyzer.setClasspath(new File[] { IO.getFile("jar/jsp-api.jar"), IO.getFile("jar/servlet-api.jar") });
        analyzer.setProperties(base);
        analyzer.build();
        assertTrue(analyzer.check());
        Packages imports = analyzer.getImports();
        Attrs attrs = imports.getByFQN("javax.servlet.http");
        assertEquals("[3.0,4)", attrs.getVersion());
        attrs = imports.getByFQN("javax.servlet");
        assertEquals("[3.0,4)", attrs.getVersion());
    } finally {
        analyzer.close();
    }
}
Also used : Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Properties(java.util.Properties) File(java.io.File)

Example 39 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 40 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)

Aggregations

Builder (aQute.bnd.osgi.Builder)426 Jar (aQute.bnd.osgi.Jar)225 File (java.io.File)197 Manifest (java.util.jar.Manifest)93 Properties (java.util.Properties)91 Resource (aQute.bnd.osgi.Resource)82 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 Domain (aQute.bnd.osgi.Domain)16 ArrayList (java.util.ArrayList)13 Project (aQute.bnd.build.Project)10 Baseline (aQute.bnd.differ.Baseline)9 Packages (aQute.bnd.osgi.Packages)9 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9