Search in sources :

Example 51 with ClassFile

use of javassist.bytecode.ClassFile in project reflections by ronmamo.

the class VfsTest method vfsFromDirWithJarInJar.

@Test
public void vfsFromDirWithJarInJar() throws Exception {
    URL resource = ClasspathHelper.contextClassLoader().getResource("jarWithBootLibJar.jar");
    URL innerJarUrl = new URL("jar:" + resource.toExternalForm() + "!/BOOT-INF/lib/jarWithManifest.jar");
    assertFalse(Vfs.DefaultUrlTypes.jarUrl.matches(innerJarUrl));
    Vfs.Dir jarUrlDir = Vfs.DefaultUrlTypes.jarUrl.createDir(innerJarUrl);
    assertNotEquals(innerJarUrl.getPath(), jarUrlDir.getPath());
    assertTrue(Vfs.DefaultUrlTypes.jarInputStream.matches(innerJarUrl));
    Vfs.Dir jarInputStreamDir = Vfs.DefaultUrlTypes.jarInputStream.createDir(innerJarUrl);
    assertEquals(innerJarUrl.getPath(), jarInputStreamDir.getPath());
    List<Vfs.File> files = StreamSupport.stream(jarInputStreamDir.getFiles().spliterator(), false).collect(Collectors.toList());
    assertEquals(1, files.size());
    Vfs.File file1 = files.get(0);
    assertEquals("empty.class", file1.getName());
    assertEquals("pack/empty.class", file1.getRelativePath());
    for (Vfs.File file : jarInputStreamDir.getFiles()) {
        try (DataInputStream dis = new DataInputStream(new BufferedInputStream(file.openInputStream()))) {
            ClassFile classFile = new ClassFile(dis);
            assertEquals("org.reflections.empty", classFile.getName());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Vfs(org.reflections.vfs.Vfs) ClassFile(javassist.bytecode.ClassFile) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) ClassFile(javassist.bytecode.ClassFile) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) Test(org.junit.jupiter.api.Test)

Aggregations

ClassFile (javassist.bytecode.ClassFile)51 DataInputStream (java.io.DataInputStream)15 ClassPool (javassist.ClassPool)15 DataOutputStream (java.io.DataOutputStream)14 CtClass (javassist.CtClass)14 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)14 ConstPool (javassist.bytecode.ConstPool)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IOException (java.io.IOException)11 MethodInfo (javassist.bytecode.MethodInfo)11 CtField (javassist.CtField)10 NotFoundException (javassist.NotFoundException)9 Annotation (javassist.bytecode.annotation.Annotation)9 Test (org.junit.Test)9 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)8 HashSet (java.util.HashSet)7 CtMethod (javassist.CtMethod)7 FieldInfo (javassist.bytecode.FieldInfo)7 Bytecode (javassist.bytecode.Bytecode)5