Search in sources :

Example 11 with Analyzer

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

the class AnalyzerTest method testRemoveheaders.

/**
	 * The -removeheaders header removes any necessary after the manifest is
	 * calculated.
	 */
public static void testRemoveheaders() throws Exception {
    try (Analyzer a = new Analyzer()) {
        a.setJar(IO.getFile("jar/asm.jar"));
        Manifest m = a.calcManifest();
        assertNotNull(m.getMainAttributes().getValue("Implementation-Title"));
    }
    try (Analyzer a = new Analyzer()) {
        a.setJar(IO.getFile("jar/asm.jar"));
        a.setProperty("-removeheaders", "Implementation-Title");
        Manifest m = a.calcManifest();
        assertNull(m.getMainAttributes().getValue("Implementation-Title"));
    }
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) Manifest(java.util.jar.Manifest)

Example 12 with Analyzer

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

the class AnalyzerTest method testGenerateManifest.

/**
	 * Fastest way to create a manifest
	 * 
	 * @throws Exception
	 */
public static void testGenerateManifest() throws Exception {
    Analyzer analyzer = new Analyzer();
    try {
        Jar bin = new Jar(IO.getFile("jar/osgi.jar"));
        bin.setManifest(new Manifest());
        analyzer.setJar(bin);
        analyzer.addClasspath(IO.getFile("jar/spring.jar"));
        analyzer.setProperty("Bundle-SymbolicName", "org.osgi.core");
        analyzer.setProperty("Export-Package", "org.osgi.framework,org.osgi.service.event");
        analyzer.setProperty("Bundle-Version", "1.0.0.x");
        analyzer.setProperty("Import-Package", "*");
        Manifest manifest = analyzer.calcManifest();
        assertTrue(analyzer.check());
        manifest.write(System.err);
        Domain main = Domain.domain(manifest);
        Parameters export = main.getExportPackage();
        Parameters expected = new Parameters("org.osgi.framework;version=\"1.3\",org.osgi.service.event;uses:=\"org.osgi.framework\";version=\"1.0.1\"");
        assertTrue(expected.isEqual(export));
        assertEquals("1.0.0.x", manifest.getMainAttributes().getValue("Bundle-Version"));
    } finally {
        analyzer.close();
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Jar(aQute.bnd.osgi.Jar) Analyzer(aQute.bnd.osgi.Analyzer) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain)

Example 13 with Analyzer

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

the class AnalyzerTest method testAsm.

/**
	 * asm is a simple library with two packages. No imports are done.
	 */
public static void testAsm() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.IMPORT_PACKAGE, "*");
    base.put(Analyzer.EXPORT_PACKAGE, "*;-noimport:=true");
    try (Analyzer analyzer = new Analyzer()) {
        analyzer.setJar(IO.getFile("jar/asm.jar"));
        analyzer.setProperties(base);
        analyzer.calcManifest().write(System.err);
        assertTrue(analyzer.check());
        assertTrue(analyzer.getExports().getByFQN("org.objectweb.asm.signature") != null);
        assertTrue(analyzer.getExports().getByFQN("org.objectweb.asm") != null);
        assertFalse(analyzer.getImports().getByFQN("org.objectweb.asm.signature") != null);
        assertFalse(analyzer.getImports().getByFQN("org.objectweb.asm") != null);
        assertEquals("Expected size", 2, analyzer.getExports().size());
    }
}
Also used : Properties(java.util.Properties) Analyzer(aQute.bnd.osgi.Analyzer)

Example 14 with Analyzer

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

the class AnalyzerTest method testVersion.

/**
	 * Test if version works
	 * 
	 * @throws IOException
	 */
public static void testVersion() throws IOException {
    try (Analyzer a = new Analyzer()) {
        String v = a.getBndVersion();
        assertNotNull(v);
    }
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer)

Example 15 with Analyzer

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

the class AnalyzerTest method testAsm2.

/**
	 * See if we set attributes on export
	 * 
	 * @throws IOException
	 */
public static void testAsm2() throws Exception {
    Properties base = new Properties();
    base.put(Analyzer.IMPORT_PACKAGE, "*");
    base.put(Analyzer.EXPORT_PACKAGE, "org.objectweb.asm;name=short, org.objectweb.asm.signature;name=long");
    try (Analyzer h = new Analyzer()) {
        h.setJar(IO.getFile("jar/asm.jar"));
        h.setProperties(base);
        h.calcManifest().write(System.err);
        assertTrue(h.check());
        Packages exports = h.getExports();
        assertTrue(exports.getByFQN("org.objectweb.asm.signature") != null);
        assertTrue(exports.getByFQN("org.objectweb.asm") != null);
        assertTrue(Arrays.asList("org.objectweb.asm", "org.objectweb.asm.signature").removeAll(h.getImports().keySet()) == false);
        assertEquals("Expected size", 2, h.getExports().size());
        assertEquals("short", get(h.getExports(), h.getPackageRef("org.objectweb.asm"), "name"));
        assertEquals("long", get(h.getExports(), h.getPackageRef("org.objectweb.asm.signature"), "name"));
    }
}
Also used : Packages(aQute.bnd.osgi.Packages) Properties(java.util.Properties) Analyzer(aQute.bnd.osgi.Analyzer)

Aggregations

Analyzer (aQute.bnd.osgi.Analyzer)55 File (java.io.File)21 Clazz (aQute.bnd.osgi.Clazz)14 Properties (java.util.Properties)14 Manifest (java.util.jar.Manifest)12 Jar (aQute.bnd.osgi.Jar)11 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)9 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)8 Parameters (aQute.bnd.header.Parameters)7 FileResource (aQute.bnd.osgi.FileResource)7 FileInputStream (java.io.FileInputStream)6 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)5 Description (aQute.lib.getopt.Description)5 Attrs (aQute.bnd.header.Attrs)4 Descriptors (aQute.bnd.osgi.Descriptors)4 Packages (aQute.bnd.osgi.Packages)4 Resource (aQute.bnd.osgi.Resource)4 Map (java.util.Map)4 PomFromManifest (aQute.bnd.maven.PomFromManifest)3 Domain (aQute.bnd.osgi.Domain)3