Search in sources :

Example 76 with Builder

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

the class BuilderTest method testResourceNotFound.

/**
	 * Test Resource inclusion that do not exist
	 * 
	 * @throws Exception
	 */
public static void testResourceNotFound() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.EXPORT_PACKAGE, "*;x-test:=true");
    base.put(Analyzer.INCLUDE_RESOURCE, "does_not_exist");
    Builder analyzer = new Builder();
    try {
        analyzer.setClasspath(new File[] { IO.getFile("jar/asm.jar") });
        analyzer.setProperties(base);
        analyzer.build();
        assertTrue(analyzer.check("file does not exist: does_not_exist"));
    } finally {
        analyzer.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) Properties(java.util.Properties)

Example 77 with Builder

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

the class ClassParserTest method testUnacceptableReference.

/**
	 * Included an aop alliance class that is not directly referenced.
	 */
public static void testUnacceptableReference() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/nl.fuji.general.jar"));
    b.addClasspath(IO.getFile("jar/spring.jar"));
    b.setProperty("Export-Package", "nl.fuji.log");
    b.build();
    assertFalse(b.getImports().getByFQN("org.aopalliance.aop") != null);
}
Also used : Builder(aQute.bnd.osgi.Builder)

Example 78 with Builder

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

the class ClassParserTest method testJQuantlib.

/**
	 * @Neil: I'm trying to use bnd to bundleize a library called JQuantLib, but
	 *        it causes an ArrayIndexOutOfBoundsException while parsing a class.
	 *        The problem is reproducible and I have even rebuilt the library
	 *        from source and get the same problem. Here's the stack trace:
	 *        java.lang.ArrayIndexOutOfBoundsException: -29373 at
	 *        aQute.bnd.osgi.Clazz.parseClassFile(Clazz.java:262) at
	 *        aQute.bnd.osgi.Clazz.<init>(Clazz.java:101) at
	 *        aQute.bnd.osgi.Analyzer.analyzeJar(Analyzer.java:1647) at
	 *        aQute.bnd.osgi.Analyzer.analyzeBundleClasspath(Analyzer.java:1563)
	 *        at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:108) at
	 *        aQute.bnd.osgi.Builder.analyze(Builder.java:192) at
	 *        aQute.bnd.osgi.Builder.doConditional(Builder.java:158) at
	 *        aQute.bnd.osgi.Builder.build(Builder.java:71) at
	 *        aQute.bnd.main.bnd.doBuild(bnd.java:379) at
	 *        aQute.bnd.main.bnd.run(bnd.java:130) at
	 *        aQute.bnd.main.bnd.main(bnd.java:39)
	 * @throws Exception
	 */
public static void testJQuantlib() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("testresources/jquantlib-0.1.2.jar"));
    b.setProperty("Export-Package", "*");
    b.build();
}
Also used : Builder(aQute.bnd.osgi.Builder)

Example 79 with Builder

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

the class ProjectTest method testGetOutputFile.

/**
	 * Check that the output property can be used to name the output binary.
	 */
public void testGetOutputFile() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project top = ws.getProject("p1");
    //
    // We expect p1 to be a single project (no sub builders)
    //
    assertEquals("p1 must be singleton", 1, top.getSubBuilders().size());
    Builder builder = top.getSubBuilders().iterator().next();
    assertEquals("p1 must be singleton", "p1", builder.getBsn());
    // Check the default bsn.jar form
    assertEquals(new File(top.getTarget(), "p1.jar"), top.getOutputFile("p1"));
    assertEquals(new File(top.getTarget(), "p1.jar"), top.getOutputFile("p1", "0"));
    // Add the version to the filename
    top.setProperty("-outputmask", "${@bsn}-${version;===s;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("Bundle-Version", "1.260.0.SNAPSHOT");
    assertEquals(new File(top.getTarget(), "p1-1.260.0-SNAPSHOT.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("-outputmask", "${@bsn}-${version;===S;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0-SNAPSHOT.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("Bundle-Version", "1.260.0.NOTSNAPSHOT");
    top.setProperty("-outputmask", "${@bsn}-${version;===S;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0.NOTSNAPSHOT.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("-outputmask", "${@bsn}-${version;===s;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-1.260.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("Bundle-Version", "42");
    top.setProperty("-outputmask", "${@bsn}-${version;===S;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-42.0.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
    top.setProperty("-outputmask", "${@bsn}-${version;===s;${@version}}.jar");
    assertEquals(new File(top.getTarget(), "p1-42.0.0.jar"), top.getOutputFile(builder.getBsn(), builder.getVersion()));
}
Also used : Project(aQute.bnd.build.Project) Builder(aQute.bnd.osgi.Builder) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 80 with Builder

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

the class UsesTest method checkUses.

private static void checkUses(String export, String uses) throws IOException, Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setExportPackage(export);
    a.setProperty("build", "123");
    Jar jar = a.build();
    assertTrue(a.check());
    Manifest m = jar.getManifest();
    m.write(System.err);
    Domain d = Domain.domain(m);
    Parameters parameters = d.getExportPackage();
    Attrs attrs = parameters.get(export);
    assertNotNull(attrs);
    assertEquals(uses, attrs.get("uses:"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) 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