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();
}
}
}
}
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();
}
Aggregations