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();
}
}
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) {
}
}
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class BuilderTest method testMultipleExport2.
public static void testMultipleExport2() 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;version=1.1, org.objectweb.asm;version=1.2, org.objectweb.asm;version=2.3");
bmaker.setProperties(p);
bmaker.setClasspath(cp);
Jar jar = bmaker.build();
assertTrue(bmaker.check());
jar.getManifest().write(System.err);
Manifest m = jar.getManifest();
m.write(System.err);
String ip = m.getMainAttributes().getValue("Export-Package");
assertTrue(ip.indexOf("org.objectweb.asm;version=\"1.1\"") >= 0);
assertTrue(ip.indexOf("org.objectweb.asm;version=\"1.2\"") >= 0);
assertTrue(ip.indexOf("org.objectweb.asm;version=\"2.3\"") >= 0);
} finally {
bmaker.close();
}
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class ClassParserTest method testJavaTypeAnnotations.
/**
* Java Type & Parameter annotations
*
* @throws Exception
*/
public void testJavaTypeAnnotations() throws Exception {
Builder b = new Builder();
b.addClasspath(IO.getFile("java8/type_annotations/bin"));
b.setExportPackage("reference.*");
Jar build = b.build();
assertTrue(b.check());
assertTrue(b.getImports().containsFQN("runtime.annotations"));
assertTrue(b.getImports().containsFQN("runtime.annotations.repeated"));
assertFalse(b.getImports().containsFQN("invisible.annotations"));
assertFalse(b.getImports().containsFQN("invisible.annotations.repeated"));
assertEquals("reference.runtime.annotations.Foo,reference.runtime.annotations.ReferenceRuntime", b.getReplacer().process("${sort;${classes;ANNOTATION;runtime.annotations.RuntimeTypeAnnotation}}"));
assertEquals("reference.invisible.annotations.ReferenceInvisible", b.getReplacer().process("${sort;${classes;ANNOTATION;invisible.annotations.InvisibleParameterAnnotation}}"));
assertEquals("reference.runtime.annotations.ReferenceRuntime", b.getReplacer().process("${sort;${classes;ANNOTATION;runtime.annotations.RuntimeParameterAnnotation}}"));
assertEquals("reference.invisible.annotations.ReferenceInvisible", b.getReplacer().process("${sort;${classes;ANNOTATION;invisible.annotations.InvisibleTypeAnnotation}}"));
assertEquals("reference.invisible.annotations.ReferenceInvisible", b.getReplacer().process("${sort;${classes;ANNOTATION;invisible.annotations.InvisibleRepeatedAnnotation}}"));
assertEquals("reference.runtime.annotations.ReferenceRuntime", b.getReplacer().process("${sort;${classes;ANNOTATION;runtime.annotations.RuntimeRepeatedAnnotation}}"));
b.close();
}
use of aQute.bnd.osgi.Builder in project bnd by bndtools.
the class ClasspathTest method testSimple.
/**
* Test if we can use URLs on the classpath
*
* @throws Exception
*/
public static void testSimple() throws Exception {
Properties p = new Properties();
p.put("-classpath", IO.getFile("jar/osgi.jar").toURI().toURL().toString());
p.put("Export-Package", "org.osgi.service.event");
p.put("Private-Package", "test.refer");
Builder b = new Builder();
b.setClasspath(new String[] { "bin" });
b.setProperties(p);
Jar jar = b.build();
Manifest m = jar.getManifest();
String importPackage = m.getMainAttributes().getValue("Import-Package");
assertTrue(importPackage.contains("org.osgi.framework;version=\"[1.3,2)\""));
assertTrue(importPackage.contains("org.osgi.service.event;version=\"[1.0,2)\""));
}
Aggregations