use of org.objectweb.asm.ClassReader in project buck by facebook.
the class ClassesImpl method acceptClassVisitor.
@Override
public void acceptClassVisitor(String qualifiedName, int flags, ClassVisitor cv) throws IOException {
Path classFilePath = resolveClassFilePath(qualifiedName);
try (InputStream stream = Files.newInputStream(classFilePath)) {
ClassReader reader = new ClassReader(stream);
reader.accept(cv, flags);
}
}
use of org.objectweb.asm.ClassReader in project android_frameworks_base by ParanoidAndroid.
the class AsmAnalyzer method parseZip.
/**
* Parses a JAR file and returns a list of all classes founds using a map
* class name => ASM ClassReader. Class names are in the form "android.view.View".
*/
Map<String, ClassReader> parseZip(List<String> jarPathList) throws IOException {
TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
for (String jarPath : jarPathList) {
ZipFile zip = new ZipFile(jarPath);
Enumeration<? extends ZipEntry> entries = zip.entries();
ZipEntry entry;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
ClassReader cr = new ClassReader(zip.getInputStream(entry));
String className = classReaderToClassName(cr);
classes.put(className, cr);
}
}
}
return classes;
}
use of org.objectweb.asm.ClassReader in project android_frameworks_base by ParanoidAndroid.
the class AsmGenerator method generate.
/** Generates the final JAR */
public void generate() throws FileNotFoundException, IOException {
TreeMap<String, byte[]> all = new TreeMap<String, byte[]>();
for (Class<?> clazz : mInjectClasses) {
String name = classToEntryPath(clazz);
InputStream is = ClassLoader.getSystemResourceAsStream(name);
ClassReader cr = new ClassReader(is);
byte[] b = transform(cr, true);
name = classNameToEntryPath(transformName(cr.getClassName()));
all.put(name, b);
}
for (Entry<String, ClassReader> entry : mDeps.entrySet()) {
ClassReader cr = entry.getValue();
byte[] b = transform(cr, true);
String name = classNameToEntryPath(transformName(cr.getClassName()));
all.put(name, b);
}
for (Entry<String, ClassReader> entry : mKeep.entrySet()) {
ClassReader cr = entry.getValue();
byte[] b = transform(cr, true);
String name = classNameToEntryPath(transformName(cr.getClassName()));
all.put(name, b);
}
mLog.info("# deps classes: %d", mDeps.size());
mLog.info("# keep classes: %d", mKeep.size());
mLog.info("# renamed : %d", mRenameCount);
createJar(new FileOutputStream(mOsDestJar), all);
mLog.info("Created JAR file %s", mOsDestJar);
}
use of org.objectweb.asm.ClassReader in project android_frameworks_base by ParanoidAndroid.
the class DependencyFinder method findClassesDeps.
/**
* Finds all dependencies for all classes in keepClasses which are also
* listed in zipClasses. Returns a map of all the dependencies found.
*/
Map<String, Set<String>> findClassesDeps(Map<String, ClassReader> zipClasses) {
// The dependencies that we'll collect.
// It's a map Class name => uses class names.
Map<String, Set<String>> dependencyMap = new TreeMap<String, Set<String>>();
DependencyVisitor visitor = getVisitor();
int count = 0;
try {
for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
String name = entry.getKey();
TreeSet<String> set = new TreeSet<String>();
dependencyMap.put(name, set);
visitor.setDependencySet(set);
ClassReader cr = entry.getValue();
cr.accept(visitor, 0);
visitor.setDependencySet(null);
mLog.debugNoln("Visited %d classes\r", ++count);
}
} finally {
mLog.debugNoln("\n");
}
return dependencyMap;
}
use of org.objectweb.asm.ClassReader in project android_frameworks_base by ParanoidAndroid.
the class DependencyFinder method parseZip.
// ----------------
/**
* Parses a JAR file and returns a list of all classes founds using a map
* class name => ASM ClassReader. Class names are in the form "android.view.View".
*/
Map<String, ClassReader> parseZip(List<String> jarPathList) throws IOException {
TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
for (String jarPath : jarPathList) {
ZipFile zip = new ZipFile(jarPath);
Enumeration<? extends ZipEntry> entries = zip.entries();
ZipEntry entry;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
ClassReader cr = new ClassReader(zip.getInputStream(entry));
String className = classReaderToClassName(cr);
classes.put(className, cr);
}
}
}
return classes;
}
Aggregations