am 4f133894: Exclude KXmlParser from LayoutLib.
* commit '4f133894a6e98d8d30557ea42cec92cfb21fa5c9': Exclude KXmlParser from LayoutLib.
This commit is contained in:
@@ -242,7 +242,8 @@ public class AsmAnalyzer {
|
|||||||
|
|
||||||
for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
|
for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
|
||||||
String class_name = entry.getKey();
|
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);
|
findClass(class_name, zipClasses, inOutFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,6 +274,9 @@ public class AsmAnalyzer {
|
|||||||
*/
|
*/
|
||||||
void findClassesDerivingFrom(String super_name, Map<String, ClassReader> zipClasses,
|
void findClassesDerivingFrom(String super_name, Map<String, ClassReader> zipClasses,
|
||||||
Map<String, ClassReader> inOutFound) throws LogAbortException {
|
Map<String, ClassReader> inOutFound) throws LogAbortException {
|
||||||
|
if (mExcludedClasses.contains(getOuterClassName(super_name))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
findClass(super_name, zipClasses, inOutFound);
|
findClass(super_name, zipClasses, inOutFound);
|
||||||
|
|
||||||
for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
|
for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
|
||||||
@@ -351,7 +355,13 @@ public class AsmAnalyzer {
|
|||||||
return deps;
|
return deps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getOuterClassName(String className) {
|
||||||
|
int pos = className.indexOf('$');
|
||||||
|
if (pos > 0) {
|
||||||
|
return className.substring(0, pos);
|
||||||
|
}
|
||||||
|
return className;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
@@ -416,7 +426,7 @@ public class AsmAnalyzer {
|
|||||||
mOutKeep.containsKey(className) ||
|
mOutKeep.containsKey(className) ||
|
||||||
mInDeps.containsKey(className) ||
|
mInDeps.containsKey(className) ||
|
||||||
mOutDeps.containsKey(className) ||
|
mOutDeps.containsKey(className) ||
|
||||||
mExcludedClasses.contains(getBaseName(className))) {
|
mExcludedClasses.contains(getOuterClassName(className))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,14 +510,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
|
// --- ClassVisitor, FieldVisitor
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ import com.android.tools.layoutlib.java.IntegralToString;
|
|||||||
import com.android.tools.layoutlib.java.Objects;
|
import com.android.tools.layoutlib.java.Objects;
|
||||||
import com.android.tools.layoutlib.java.UnsafeByteSequence;
|
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}.
|
* Describes the work to be done by {@link AsmGenerator}.
|
||||||
*/
|
*/
|
||||||
@@ -98,6 +102,17 @@ public final class CreateInfo implements ICreateInfo {
|
|||||||
public String[] getJavaPkgClasses() {
|
public String[] getJavaPkgClasses() {
|
||||||
return JAVA_PKG_CLASSES;
|
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;
|
||||||
|
}
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,6 +252,11 @@ public final class CreateInfo implements ICreateInfo {
|
|||||||
"java.lang.UnsafeByteSequence", "com.android.tools.layoutlib.java.UnsafeByteSequence",
|
"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.
|
* 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
|
* The array contains a list of null terminated section starting with the name of the class
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.tools.layoutlib.create;
|
package com.android.tools.layoutlib.create;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface describing the work to be done by {@link AsmGenerator}.
|
* 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.
|
* The list can be empty but must not be null.
|
||||||
*/
|
*/
|
||||||
public abstract String[] getJavaPkgClasses();
|
public abstract String[] getJavaPkgClasses();
|
||||||
|
|
||||||
|
public abstract Set<String> getExcludedClasses();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.tools.layoutlib.create;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -88,7 +89,7 @@ public class Main {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
CreateInfo info = new CreateInfo();
|
CreateInfo info = new CreateInfo();
|
||||||
Set<String> excludeClasses = getExcludedClasses(info);
|
Set<String> excludeClasses = info.getExcludedClasses();
|
||||||
AsmGenerator agen = new AsmGenerator(log, osDestJar, info);
|
AsmGenerator agen = new AsmGenerator(log, osDestJar, info);
|
||||||
|
|
||||||
AsmAnalyzer aa = new AsmAnalyzer(log, osJarPath, agen,
|
AsmAnalyzer aa = new AsmAnalyzer(log, osJarPath, agen,
|
||||||
@@ -157,16 +158,6 @@ public class Main {
|
|||||||
return 1;
|
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) {
|
private static int listDeps(ArrayList<String> osJarPath, Log log) {
|
||||||
DependencyFinder df = new DependencyFinder(log);
|
DependencyFinder df = new DependencyFinder(log);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.tools.layoutlib.create;
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -36,6 +37,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -118,6 +120,11 @@ public class AsmGeneratorTest {
|
|||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getExcludedClasses() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getDeleteReturns() {
|
public String[] getDeleteReturns() {
|
||||||
// methods deleted from their return type.
|
// methods deleted from their return type.
|
||||||
@@ -183,6 +190,11 @@ public class AsmGeneratorTest {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getExcludedClasses() {
|
||||||
|
return Collections.singleton("java.lang.JavaClass");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getDeleteReturns() {
|
public String[] getDeleteReturns() {
|
||||||
// methods deleted from their return type.
|
// methods deleted from their return type.
|
||||||
@@ -217,6 +229,80 @@ public class AsmGeneratorTest {
|
|||||||
filesFound.keySet().toArray());
|
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,
|
private void parseZip(String jarPath,
|
||||||
Map<String, ClassReader> classes,
|
Map<String, ClassReader> classes,
|
||||||
Map<String, InputStream> filesFound) throws IOException {
|
Map<String, InputStream> filesFound) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user