Search in sources :

Example 1 with ClassVisitor

use of gate.util.asm.ClassVisitor 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)

Aggregations

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