use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class JarTest method testNoManifest.
public static void testNoManifest() throws Exception {
Jar jar = new Jar("dot");
jar.setManifest(new Manifest());
jar.setDoNotTouchManifest();
jar.putResource("a/b", new FileResource(IO.getFile("testresources/bnd.jar")));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
jar.write(bout);
Jar jin = new Jar("dotin", new ByteArrayInputStream(bout.toByteArray()));
Resource m = jin.getResource("META-INF/MANIFEST.MF");
assertNull(m);
Resource r = jin.getResource("a/b");
assertNotNull(r);
}
use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class JarTest method testSimple.
public static void testSimple() throws ZipException, IOException {
File file = IO.getFile("jar/asm.jar");
Jar jar = new Jar("asm.jar", file);
long jarTime = jar.lastModified();
long fileTime = file.lastModified();
long now = System.currentTimeMillis();
// Sanity check
assertTrue(jarTime < fileTime);
assertTrue(fileTime <= now);
// TODO see if we can improve this test case
// // We should use the highest modification time
// // of the files in the JAR not the JAR (though
// // this is a backup if time is not set in the jar)
// assertEquals(1144412850000L, jarTime);
// Now add the file and check that
// the modification time has changed
jar.putResource("asm", new FileResource(file));
assertEquals(file.lastModified(), jar.lastModified());
}
use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class ClazzTest method testRecursiveAnnotation.
public void testRecursiveAnnotation() throws Exception {
File file = IO.getFile("bin/test/ClazzTest$RecursiveAnno.class");
try (Analyzer analyzer = new Analyzer()) {
Clazz clazz = new Clazz(analyzer, file.getPath(), new FileResource(file));
clazz.parseClassFile();
analyzer.getClassspace().put(clazz.getClassName(), clazz);
AnnotationReader.getDefinition(clazz, analyzer, EnumSet.noneOf(DSAnnotations.Options.class), new XMLAttributeFinder(analyzer), AnnotationReader.V1_3);
}
}
use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class ClassParserTest method testGenericsSignature.
public static void testGenericsSignature() throws Exception {
Clazz c = new Clazz(a, "genericstest", new FileResource(IO.getFile("src/test/generics.clazz")));
c.parseClassFile();
assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing/table")));
assertTrue(c.getReferred().contains(a.getPackageRef("javax/swing")));
}
use of aQute.bnd.osgi.FileResource in project bnd by bndtools.
the class ClassParserTest method testConstantValues.
/**
* Test the constant values
*
* @throws Exception
*/
public void testConstantValues() throws Exception {
final Map<String, Object> values = new HashMap<String, Object>();
Clazz c = new Clazz(a, "ConstantValues", new FileResource(IO.getFile(new File("").getAbsoluteFile(), "bin/test/ConstantValues.class")));
c.parseClassFileWithCollector(new ClassDataCollector() {
Clazz.FieldDef last;
@Override
public void field(Clazz.FieldDef referenced) {
last = referenced;
}
@Override
public void constant(Object value) {
values.put(last.getName(), value);
}
});
assertEquals(1, values.get("t"));
assertEquals(0, values.get("f"));
assertEquals((int) Byte.MAX_VALUE, values.get("bt"));
assertEquals((int) Short.MAX_VALUE, values.get("shrt"));
assertEquals((int) Character.MAX_VALUE, values.get("chr"));
assertEquals(Integer.MAX_VALUE, values.get("intgr"));
assertEquals(Long.MAX_VALUE, values.get("lng"));
assertEquals(Float.MAX_VALUE, values.get("flt"));
assertEquals(Double.MAX_VALUE, values.get("dbl"));
assertEquals("blabla", values.get("strng"));
// Classes are special
// assertEquals("java.lang.Object", ((Clazz.ClassConstant)
// values.get("clss")).getName());
}
Aggregations