diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-10-09 13:16:36 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-10-09 13:16:36 +0000 |
commit | d8497e45c72fbb27961d096499984906af19d35f (patch) | |
tree | 16e744c57effe254d733e5d4a6862d9e1bfa633c | |
parent | 8a1df4154d0e1296a3f03fa2aaf852ac08f68f36 (diff) | |
parent | 0a61c7ee4a94326b7524d58f456973b68ac62d35 (diff) | |
download | frameworks_base-d8497e45c72fbb27961d096499984906af19d35f.zip frameworks_base-d8497e45c72fbb27961d096499984906af19d35f.tar.gz frameworks_base-d8497e45c72fbb27961d096499984906af19d35f.tar.bz2 |
am 0a61c7ee: am 985d59d7: am 908a4f9a: am 4f133894: Exclude KXmlParser from LayoutLib.
* commit '0a61c7ee4a94326b7524d58f456973b68ac62d35':
Exclude KXmlParser from LayoutLib.
5 files changed, 125 insertions, 22 deletions
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java index 9a10f79..aa51c46 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java @@ -242,7 +242,8 @@ public class AsmAnalyzer { for (Entry<String, ClassReader> entry : zipClasses.entrySet()) { String class_name = entry.getKey(); - if (regexp.matcher(class_name).matches()) { + if (regexp.matcher(class_name).matches() && + !mExcludedClasses.contains(getOuterClassName(class_name))) { findClass(class_name, zipClasses, inOutFound); } } @@ -273,6 +274,9 @@ public class AsmAnalyzer { */ void findClassesDerivingFrom(String super_name, Map<String, ClassReader> zipClasses, Map<String, ClassReader> inOutFound) throws LogAbortException { + if (mExcludedClasses.contains(getOuterClassName(super_name))) { + return; + } findClass(super_name, zipClasses, inOutFound); for (Entry<String, ClassReader> entry : zipClasses.entrySet()) { @@ -352,7 +356,13 @@ public class AsmAnalyzer { return deps; } - + private String getOuterClassName(String className) { + int pos = className.indexOf('$'); + if (pos > 0) { + return className.substring(0, pos); + } + return className; + } // ---------------------------------- @@ -417,7 +427,7 @@ public class AsmAnalyzer { mOutKeep.containsKey(className) || mInDeps.containsKey(className) || mOutDeps.containsKey(className) || - mExcludedClasses.contains(getBaseName(className))) { + mExcludedClasses.contains(getOuterClassName(className))) { return; } @@ -501,14 +511,6 @@ public class AsmAnalyzer { } } - private String getBaseName(String className) { - int pos = className.indexOf('$'); - if (pos > 0) { - return className.substring(0, pos); - } - return className; - } - // --------------------------------------------------- // --- ClassVisitor, FieldVisitor // --------------------------------------------------- diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 89cbaeb..f20b890 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -23,6 +23,10 @@ import com.android.tools.layoutlib.java.IntegralToString; import com.android.tools.layoutlib.java.Objects; import com.android.tools.layoutlib.java.UnsafeByteSequence; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + /** * Describes the work to be done by {@link AsmGenerator}. */ @@ -98,6 +102,17 @@ public final class CreateInfo implements ICreateInfo { public String[] getJavaPkgClasses() { return JAVA_PKG_CLASSES; } + + public Set<String> getExcludedClasses() { + String[] refactoredClasses = getJavaPkgClasses(); + int count = refactoredClasses.length / 2 + EXCLUDED_CLASSES.length; + Set<String> excludedClasses = new HashSet<String>(count); + for (int i = 0; i < refactoredClasses.length; i+=2) { + excludedClasses.add(refactoredClasses[i]); + } + excludedClasses.addAll(Arrays.asList(EXCLUDED_CLASSES)); + return excludedClasses; + } //----- /** @@ -243,6 +258,11 @@ public final class CreateInfo implements ICreateInfo { "java.lang.UnsafeByteSequence", "com.android.tools.layoutlib.java.UnsafeByteSequence", }; + private final static String[] EXCLUDED_CLASSES = + new String[] { + "org.kxml2.io.KXmlParser" + }; + /** * List of classes for which the methods returning them should be deleted. * The array contains a list of null terminated section starting with the name of the class diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ICreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ICreateInfo.java index 9387814..e49a668 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ICreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ICreateInfo.java @@ -16,6 +16,8 @@ package com.android.tools.layoutlib.create; +import java.util.Set; + /** * Interface describing the work to be done by {@link AsmGenerator}. */ @@ -69,4 +71,6 @@ public interface ICreateInfo { * The list can be empty but must not be null. */ public abstract String[] getJavaPkgClasses(); + + public abstract Set<String> getExcludedClasses(); } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java index 02f2c02..cd3c39e 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java @@ -18,6 +18,7 @@ package com.android.tools.layoutlib.create; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -87,7 +88,7 @@ public class Main { try { CreateInfo info = new CreateInfo(); - Set<String> excludeClasses = getExcludedClasses(info); + Set<String> excludeClasses = info.getExcludedClasses(); AsmGenerator agen = new AsmGenerator(log, osDestJar, info); AsmAnalyzer aa = new AsmAnalyzer(log, osJarPath, agen, @@ -156,16 +157,6 @@ public class Main { return 1; } - private static Set<String> getExcludedClasses(CreateInfo info) { - String[] refactoredClasses = info.getJavaPkgClasses(); - Set<String> excludedClasses = new HashSet<String>(refactoredClasses.length); - for (int i = 0; i < refactoredClasses.length; i+=2) { - excludedClasses.add(refactoredClasses[i]); - } - return excludedClasses; - - } - private static int listDeps(ArrayList<String> osJarPath, Log log) { DependencyFinder df = new DependencyFinder(log); try { diff --git a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java index 0dbc238..cf91386 100644 --- a/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java +++ b/tools/layoutlib/create/tests/com/android/tools/layoutlib/create/AsmGeneratorTest.java @@ -19,6 +19,7 @@ package com.android.tools.layoutlib.create; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.After; @@ -36,6 +37,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.Map; @@ -119,6 +121,11 @@ public class AsmGeneratorTest { } @Override + public Set<String> getExcludedClasses() { + return null; + } + + @Override public String[] getDeleteReturns() { // methods deleted from their return type. return new String[0]; @@ -184,6 +191,11 @@ public class AsmGeneratorTest { } @Override + public Set<String> getExcludedClasses() { + return Collections.singleton("java.lang.JavaClass"); + } + + @Override public String[] getDeleteReturns() { // methods deleted from their return type. return new String[0]; @@ -217,6 +229,80 @@ public class AsmGeneratorTest { filesFound.keySet().toArray()); } + @Test + public void testClassExclusion() throws IOException, LogAbortException { + ICreateInfo ci = new ICreateInfo() { + @Override + public Class<?>[] getInjectedClasses() { + return new Class<?>[0]; + } + + @Override + public String[] getDelegateMethods() { + return new String[0]; + } + + @Override + public String[] getDelegateClassNatives() { + return new String[0]; + } + + @Override + public String[] getOverriddenMethods() { + // methods to force override + return new String[0]; + } + + @Override + public String[] getRenamedClasses() { + // classes to rename (so that we can replace them) + return new String[0]; + } + + @Override + public String[] getJavaPkgClasses() { + // classes to refactor (so that we can replace them) + return new String[0]; + } + + @Override + public Set<String> getExcludedClasses() { + Set<String> set = new HashSet<String>(2); + set.add("mock_android.dummy.InnerTest"); + set.add("java.lang.JavaClass"); + return set; + } + + @Override + public String[] getDeleteReturns() { + // methods deleted from their return type. + return new String[0]; + } + }; + + AsmGenerator agen = new AsmGenerator(mLog, mOsDestJar, ci); + Set<String> excludedClasses = ci.getExcludedClasses(); + AsmAnalyzer aa = new AsmAnalyzer(mLog, mOsJarPath, agen, + null, // derived from + new String[] { // include classes + "**" + }, + excludedClasses, + new String[] { /* include files */ + "mock_android/data/data*" + }); + aa.analyze(); + agen.generate(); + Map<String, ClassReader> output = new TreeMap<String, ClassReader>(); + Map<String, InputStream> filesFound = new TreeMap<String, InputStream>(); + parseZip(mOsDestJar, output, filesFound); + for (String s : output.keySet()) { + assertFalse(excludedClasses.contains(s)); + } + assertArrayEquals(new String[] {"mock_android/data/dataFile"}, + filesFound.keySet().toArray()); + } + private void parseZip(String jarPath, Map<String, ClassReader> classes, Map<String, InputStream> filesFound) throws IOException { |