Search in sources :

Example 1 with ClassReader

use of gate.util.asm.ClassReader in project gate-core by GateNLP.

the class Plugin method fillInResInfos.

protected void fillInResInfos(List<ResourceInfo> incompleteResInfos, List<String> allJars) throws IOException {
    // now create a temporary class loader with all the JARs (scanned or
    // not), so we can look up all the referenced classes in the normal
    // way and read their CreoleResource annotations (if any).
    URL[] jarUrls = new URL[allJars.size()];
    for (int i = 0; i < jarUrls.length; i++) {
        jarUrls[i] = new URL(getBaseURL(), allJars.get(i));
    }
    // can then throw away?
    try (URLClassLoader tempClassLoader = new URLClassLoader(jarUrls, Gate.class.getClassLoader())) {
        for (ResourceInfo ri : incompleteResInfos) {
            String classFile = ri.getResourceClassName().replace('.', '/') + ".class";
            InputStream classStream = tempClassLoader.getResourceAsStream(classFile);
            if (classStream != null) {
                ClassReader classReader = new ClassReader(classStream);
                ClassVisitor visitor = new ResourceInfoVisitor(ri);
                classReader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
                classStream.close();
            }
        }
    }
}
Also used : ResourceInfo(gate.Gate.ResourceInfo) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) URLClassLoader(java.net.URLClassLoader) ClassReader(gate.util.asm.ClassReader) Gate(gate.Gate) ClassVisitor(gate.util.asm.ClassVisitor) URL(java.net.URL)

Example 2 with ClassReader

use of gate.util.asm.ClassReader in project gate-core by GateNLP.

the class Plugin method scanJar.

protected void scanJar(URL jarUrl, Map<String, ResourceInfo> resInfos) throws IOException {
    JarInputStream jarInput = new JarInputStream(jarUrl.openStream(), false);
    JarEntry entry = null;
    while ((entry = jarInput.getNextJarEntry()) != null) {
        String entryName = entry.getName();
        if (entryName != null && entryName.endsWith(".class")) {
            final String className = entryName.substring(0, entryName.length() - 6).replace('/', '.');
            if (!resInfos.containsKey(className)) {
                ClassReader classReader = new ClassReader(jarInput);
                ResourceInfo resInfo = new ResourceInfo(null, className, null);
                ResourceInfoVisitor visitor = new ResourceInfoVisitor(resInfo);
                classReader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
                if (visitor.isCreoleResource()) {
                    resInfos.put(className, resInfo);
                }
            }
        }
    }
    jarInput.close();
}
Also used : ResourceInfo(gate.Gate.ResourceInfo) JarInputStream(java.util.jar.JarInputStream) ClassReader(gate.util.asm.ClassReader) JarEntry(java.util.jar.JarEntry)

Aggregations

ResourceInfo (gate.Gate.ResourceInfo)2 ClassReader (gate.util.asm.ClassReader)2 JarInputStream (java.util.jar.JarInputStream)2 Gate (gate.Gate)1 ClassVisitor (gate.util.asm.ClassVisitor)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 JarEntry (java.util.jar.JarEntry)1