Search in sources :

Example 66 with Builder

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

the class BuilderTest method testFromOSGiDirective.

/**
	 * Test the from: directive on expanding packages.
	 */
public static void testFromOSGiDirective() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(IO.getFile("jar/osgi.jar"));
        b.addClasspath(IO.getFile("jar/org.eclipse.osgi-3.5.0.jar"));
        b.setProperty("Export-Package", "org.osgi.framework;from:=osgi");
        b.build();
        assertTrue(b.check());
        assertEquals("1.3", b.getExports().getByFQN("org.osgi.framework").get("version"));
        assertEquals("osgi", b.getExports().getByFQN("org.osgi.framework").get(Constants.FROM_DIRECTIVE));
    } finally {
        b.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder)

Example 67 with Builder

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

the class BuilderTest method testIncludeResourceFromZipDeep.

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

Example 68 with Builder

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

the class BuilderTest method testLastModifiedForManifest.

/**
	 * Test if the Manifest gets the last modified date
	 */
public void testLastModifiedForManifest() throws Exception {
    File file = new File("tmp.jar");
    try {
        long time = System.currentTimeMillis();
        Builder b = new Builder();
        b.addClasspath(IO.getFile("jar/osgi.jar"));
        b.setExportPackage("org.osgi.framework");
        Jar build = b.build();
        try {
            assertTrue(b.check());
            build.write("tmp.jar");
            Jar ajr = new Jar(file);
            try {
                Resource r = ajr.getResource("META-INF/MANIFEST.MF");
                assertNotNull(r);
                long t = r.lastModified();
                Date date = new Date(t);
                System.out.println(date + " " + t);
                // TODO we need to adapt the timestamp handling
                assertTrue(date + " " + t, t == 1142555622000L);
            } finally {
                ajr.close();
            }
        } finally {
            build.close();
        }
    } finally {
        file.delete();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Date(java.util.Date)

Example 69 with Builder

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

the class BuilderTest method testImportRangeCalculatedFromClasspath_2.

/**
	 * Check if we imported the package with the correct version range when
	 * there's an empty package in front of it in the classpath. Second form.
	 */
public static void testImportRangeCalculatedFromClasspath_2() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.IMPORT_PACKAGE, "javax.servlet,javax.servlet.http");
    String pwd = System.getProperty("user.dir");
    base.put("pwd", new File(pwd).toURI().toString());
    base.put("-classpath", "${pwd}/jar/jsp-api.jar,${pwd}/jar/servlet-api.jar");
    Builder analyzer = new Builder();
    try {
        analyzer.addClasspath(new File("bin"));
        analyzer.setPrivatePackage("test");
        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 70 with Builder

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

the class BuilderTest method testMissingImportsWithDynamicImport.

/**
	 * #479 I have now tested this locally. Apparently the fix doesn't change
	 * the reported behavior. In my test bundle, I have removed all imports. Bnd
	 * builds this with no errors reported. I add: DynamicImport-Package: dummy
	 */
public void testMissingImportsWithDynamicImport() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(new File("bin"));
        b.setPedantic(true);
        b.setExportPackage("test.classreference;version=1");
        b.setImportPackage("!*");
        b.setProperty(Constants.DYNAMICIMPORT_PACKAGE, "dummy");
        b.build();
        assertTrue(b.check());
        Verifier v = new Verifier(b.getJar());
        try {
            v.verify();
            assertTrue(v.check("Unresolved references to \\[javax.swing\\] by class\\(es\\)"));
        } finally {
            v.close();
        }
    } finally {
        b.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Verifier(aQute.bnd.osgi.Verifier) 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