Search in sources :

Example 86 with TreeMap

use of java.util.TreeMap 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;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) TreeSet(java.util.TreeSet) ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap)

Example 87 with TreeMap

use of java.util.TreeMap 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;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap)

Example 88 with TreeMap

use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.

the class AsmAnalyzerTest method testFindGlobs.

@Test
public void testFindGlobs() throws IOException, LogAbortException {
    Map<String, ClassReader> zipClasses = mAa.parseZip(mOsJarPath);
    TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
    // this matches classes, a package match returns nothing
    found.clear();
    mAa.findGlobs("mock_android.view", zipClasses, found);
    assertArrayEquals(new String[] {}, found.keySet().toArray());
    // a complex glob search. * is a search pattern that matches names, not dots
    mAa.findGlobs("mock_android.*.*Group$*Layout*", zipClasses, found);
    assertArrayEquals(new String[] { "mock_android.view.ViewGroup$LayoutParams", "mock_android.view.ViewGroup$MarginLayoutParams" }, found.keySet().toArray());
    // a complex glob search. ** is a search pattern that matches names including dots
    mAa.findGlobs("mock_android.**Group*", zipClasses, found);
    assertArrayEquals(new String[] { "mock_android.view.ViewGroup", "mock_android.view.ViewGroup$LayoutParams", "mock_android.view.ViewGroup$MarginLayoutParams" }, found.keySet().toArray());
    // matches a single class
    found.clear();
    mAa.findGlobs("mock_android.view.View", zipClasses, found);
    assertArrayEquals(new String[] { "mock_android.view.View" }, found.keySet().toArray());
    // matches everyting inside the given package but not sub-packages
    found.clear();
    mAa.findGlobs("mock_android.view.*", zipClasses, found);
    assertArrayEquals(new String[] { "mock_android.view.View", "mock_android.view.ViewGroup", "mock_android.view.ViewGroup$LayoutParams", "mock_android.view.ViewGroup$MarginLayoutParams" }, found.keySet().toArray());
    for (String key : found.keySet()) {
        ClassReader value = found.get(key);
        assertNotNull("No value for " + key, value);
        assertEquals(key, AsmAnalyzer.classReaderToClassName(value));
    }
}
Also used : ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 89 with TreeMap

use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.

the class AsmAnalyzerTest method testFindClass.

@Test
public void testFindClass() throws IOException, LogAbortException {
    Map<String, ClassReader> zipClasses = mAa.parseZip(mOsJarPath);
    TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
    ClassReader cr = mAa.findClass("mock_android.view.ViewGroup$LayoutParams", zipClasses, found);
    assertNotNull(cr);
    assertEquals("mock_android/view/ViewGroup$LayoutParams", cr.getClassName());
    assertArrayEquals(new String[] { "mock_android.view.ViewGroup$LayoutParams" }, found.keySet().toArray());
    assertArrayEquals(new ClassReader[] { cr }, found.values().toArray());
}
Also used : ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 90 with TreeMap

use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.

the class AsmAnalyzerTest method testFindClassesDerivingFrom.

@Test
public void testFindClassesDerivingFrom() throws LogAbortException, IOException {
    Map<String, ClassReader> zipClasses = mAa.parseZip(mOsJarPath);
    TreeMap<String, ClassReader> found = new TreeMap<String, ClassReader>();
    mAa.findClassesDerivingFrom("mock_android.view.View", zipClasses, found);
    assertArrayEquals(new String[] { "mock_android.view.View", "mock_android.view.ViewGroup", "mock_android.widget.LinearLayout", "mock_android.widget.TableLayout" }, found.keySet().toArray());
    for (String key : found.keySet()) {
        ClassReader value = found.get(key);
        assertNotNull("No value for " + key, value);
        assertEquals(key, AsmAnalyzer.classReaderToClassName(value));
    }
}
Also used : ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

TreeMap (java.util.TreeMap)4400 Map (java.util.Map)1245 ArrayList (java.util.ArrayList)930 HashMap (java.util.HashMap)871 Test (org.junit.Test)614 List (java.util.List)542 Before (org.junit.Before)505 IOException (java.io.IOException)402 HashSet (java.util.HashSet)301 Set (java.util.Set)268 File (java.io.File)267 SortedMap (java.util.SortedMap)240 TreeSet (java.util.TreeSet)213 LinkedHashMap (java.util.LinkedHashMap)196 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)149 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)115 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)111