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"));
}
}
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();
}
}
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());
}
}
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);
}
}
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"));
}
}
Aggregations