am 985d59d7: am 908a4f9a: am 4f133894: Exclude KXmlParser from LayoutLib.
* commit '985d59d7e3e676a02892b2a5e131510a993b3449':
Exclude KXmlParser from LayoutLib.
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 @@
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 @@
*/
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 @@
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 @@
mOutKeep.containsKey(className) ||
mInDeps.containsKey(className) ||
mOutDeps.containsKey(className) ||
- mExcludedClasses.contains(getBaseName(className))) {
+ mExcludedClasses.contains(getOuterClassName(className))) {
return;
}
@@ -501,14 +511,6 @@
}
}
- 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.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 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 @@
"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 @@
* 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 @@
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 @@
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 @@
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 @@
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.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 @@
}
@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 @@
}
@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 @@
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 {