Search in sources :

Example 6 with FileResource

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileResource(aQute.bnd.osgi.FileResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) Jar(aQute.bnd.osgi.Jar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest)

Example 7 with FileResource

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());
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 8 with FileResource

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);
    }
}
Also used : XMLAttributeFinder(aQute.bnd.xmlattribute.XMLAttributeFinder) FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 9 with FileResource

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")));
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz)

Example 10 with FileResource

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());
}
Also used : HashMap(java.util.HashMap) FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) File(java.io.File)

Aggregations

FileResource (aQute.bnd.osgi.FileResource)19 File (java.io.File)13 Jar (aQute.bnd.osgi.Jar)10 Manifest (java.util.jar.Manifest)7 Clazz (aQute.bnd.osgi.Clazz)6 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)6 Analyzer (aQute.bnd.osgi.Analyzer)5 Resource (aQute.bnd.osgi.Resource)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Container (aQute.bnd.build.Container)3 Parameters (aQute.bnd.header.Parameters)3 URLResource (aQute.bnd.osgi.URLResource)3 Attrs (aQute.bnd.header.Attrs)2 Domain (aQute.bnd.osgi.Domain)2 JarResource (aQute.bnd.osgi.JarResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Workspace (aQute.bnd.build.Workspace)1 PomResource (aQute.bnd.maven.PomResource)1