summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/create/src/com
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2014-05-02 19:31:59 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-05-02 19:31:59 +0000
commit495c14d8b8e8a52554cfc0776c48d328657cda95 (patch)
treee3f73b7342973b53a8dc8406a6b66cc509f2a2f1 /tools/layoutlib/create/src/com
parent8ad4b8b1fedc9a200b49f322e73d406d43e32327 (diff)
parent47ad22edb7df502356598d417adbce0b0ce35616 (diff)
downloadframeworks_base-495c14d8b8e8a52554cfc0776c48d328657cda95.zip
frameworks_base-495c14d8b8e8a52554cfc0776c48d328657cda95.tar.gz
frameworks_base-495c14d8b8e8a52554cfc0776c48d328657cda95.tar.bz2
am 47ad22ed: am 961e3281: am 6df2860b: Add missing files to fix libphonenumber for layoutlib. [DO NOT MERGE]
* commit '47ad22edb7df502356598d417adbce0b0ce35616': Add missing files to fix libphonenumber for layoutlib. [DO NOT MERGE]
Diffstat (limited to 'tools/layoutlib/create/src/com')
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java69
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java31
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java5
3 files changed, 88 insertions, 17 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 1572a40..9a31705 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
@@ -29,6 +29,7 @@ import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@@ -60,6 +61,9 @@ public class AsmAnalyzer {
private final String[] mIncludeGlobs;
/** The set of classes to exclude.*/
private final Set<String> mExcludedClasses;
+ /** Glob patterns of files to keep as is. */
+ private final String[] mIncludeFileGlobs;
+ /** Copy these files into the output as is. */
/**
* Creates a new analyzer.
@@ -70,15 +74,19 @@ public class AsmAnalyzer {
* @param deriveFrom Keep all classes that derive from these one (these included).
* @param includeGlobs Glob patterns of classes to keep, e.g. "com.foo.*"
* ("*" does not matches dots whilst "**" does, "." and "$" are interpreted as-is)
+ * @param includeFileGlobs Glob patterns of files which are kept as is. This is only for files
+ * not ending in .class.
*/
public AsmAnalyzer(Log log, List<String> osJarPath, AsmGenerator gen,
- String[] deriveFrom, String[] includeGlobs, Set<String> excludeClasses) {
+ String[] deriveFrom, String[] includeGlobs, Set<String> excludeClasses,
+ String[] includeFileGlobs) {
mLog = log;
mGen = gen;
mOsSourceJar = osJarPath != null ? osJarPath : new ArrayList<String>();
mDeriveFrom = deriveFrom != null ? deriveFrom : new String[0];
mIncludeGlobs = includeGlobs != null ? includeGlobs : new String[0];
mExcludedClasses = excludeClasses;
+ mIncludeFileGlobs = includeFileGlobs != null ? includeFileGlobs : new String[0];
}
/**
@@ -86,7 +94,11 @@ public class AsmAnalyzer {
* Fills the generator with classes & dependencies found.
*/
public void analyze() throws IOException, LogAbortException {
- Map<String, ClassReader> zipClasses = parseZip(mOsSourceJar);
+
+ TreeMap<String, ClassReader> zipClasses = new TreeMap<String, ClassReader>();
+ Map<String, InputStream> filesFound = new TreeMap<String, InputStream>();
+
+ parseZip(mOsSourceJar, zipClasses, filesFound);
mLog.info("Found %d classes in input JAR%s.", zipClasses.size(),
mOsSourceJar.size() > 1 ? "s" : "");
@@ -96,15 +108,29 @@ public class AsmAnalyzer {
if (mGen != null) {
mGen.setKeep(found);
mGen.setDeps(deps);
+ mGen.setCopyFiles(filesFound);
}
}
/**
- * 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".
+ * Parses a JAR file and adds all the classes found to <code>classes</code>
+ * and all other files to <code>filesFound</code>.
+ *
+ * @param classes The map of class name => ASM ClassReader. Class names are
+ * in the form "android.view.View".
+ * @param fileFound The map of file name => InputStream. The file name is
+ * in the form "android/data/dataFile".
*/
- Map<String,ClassReader> parseZip(List<String> jarPathList) throws IOException {
- TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
+ void parseZip(List<String> jarPathList, Map<String, ClassReader> classes,
+ Map<String, InputStream> filesFound) throws IOException {
+ if (classes == null || filesFound == null) {
+ return;
+ }
+
+ Pattern[] includeFilePatterns = new Pattern[mIncludeFileGlobs.length];
+ for (int i = 0; i < mIncludeFileGlobs.length; ++i) {
+ includeFilePatterns[i] = getPatternFromGlob(mIncludeFileGlobs[i]);
+ }
for (String jarPath : jarPathList) {
ZipFile zip = new ZipFile(jarPath);
@@ -116,11 +142,17 @@ public class AsmAnalyzer {
ClassReader cr = new ClassReader(zip.getInputStream(entry));
String className = classReaderToClassName(cr);
classes.put(className, cr);
+ } else {
+ for (int i = 0; i < includeFilePatterns.length; ++i) {
+ if (includeFilePatterns[i].matcher(entry.getName()).matches()) {
+ filesFound.put(entry.getName(), zip.getInputStream(entry));
+ break;
+ }
+ }
}
}
}
- return classes;
}
/**
@@ -202,7 +234,19 @@ public class AsmAnalyzer {
*/
void findGlobs(String globPattern, Map<String, ClassReader> zipClasses,
Map<String, ClassReader> inOutFound) throws LogAbortException {
- // transforms the glob pattern in a regexp:
+
+ Pattern regexp = getPatternFromGlob(globPattern);
+
+ for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
+ String class_name = entry.getKey();
+ if (regexp.matcher(class_name).matches()) {
+ findClass(class_name, zipClasses, inOutFound);
+ }
+ }
+ }
+
+ Pattern getPatternFromGlob(String globPattern) {
+ // transforms the glob pattern in a regexp:
// - escape "." with "\."
// - replace "*" by "[^.]*"
// - escape "$" with "\$"
@@ -216,14 +260,7 @@ public class AsmAnalyzer {
globPattern = globPattern.replaceAll("@", ".*");
globPattern += "$";
- Pattern regexp = Pattern.compile(globPattern);
-
- for (Entry<String, ClassReader> entry : zipClasses.entrySet()) {
- String class_name = entry.getKey();
- if (regexp.matcher(class_name).matches()) {
- findClass(class_name, zipClasses, inOutFound);
- }
- }
+ return Pattern.compile(globPattern);
}
/**
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java
index b102561..207d8ae 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmGenerator.java
@@ -20,6 +20,7 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
+import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -52,6 +53,8 @@ public class AsmGenerator {
private Map<String, ClassReader> mKeep;
/** All dependencies that must be completely stubbed. */
private Map<String, ClassReader> mDeps;
+ /** All files that are to be copied as-is. */
+ private Map<String, InputStream> mCopyFiles;
/** Counter of number of classes renamed during transform. */
private int mRenameCount;
/** FQCN Names of the classes to rename: map old-FQCN => new-FQCN */
@@ -195,6 +198,11 @@ public class AsmGenerator {
mDeps = deps;
}
+ /** Sets the map of files to output as-is. */
+ public void setCopyFiles(Map<String, InputStream> copyFiles) {
+ mCopyFiles = copyFiles;
+ }
+
/** Gets the map of classes to output as-is, except if they have native methods */
public Map<String, ClassReader> getKeep() {
return mKeep;
@@ -205,6 +213,11 @@ public class AsmGenerator {
return mDeps;
}
+ /** Gets the map of files to output as-is. */
+ public Map<String, InputStream> getCopyFiles() {
+ return mCopyFiles;
+ }
+
/** Generates the final JAR */
public void generate() throws FileNotFoundException, IOException {
TreeMap<String, byte[]> all = new TreeMap<String, byte[]>();
@@ -232,6 +245,15 @@ public class AsmGenerator {
all.put(name, b);
}
+ for (Entry<String, InputStream> entry : mCopyFiles.entrySet()) {
+ try {
+ byte[] b = inputStreamToByteArray(entry.getValue());
+ all.put(entry.getKey(), b);
+ } catch (IOException e) {
+ // Ignore.
+ }
+
+ }
mLog.info("# deps classes: %d", mDeps.size());
mLog.info("# keep classes: %d", mKeep.size());
mLog.info("# renamed : %d", mRenameCount);
@@ -381,4 +403,13 @@ public class AsmGenerator {
return cv.hasNativeMethods();
}
+ private byte[] inputStreamToByteArray(InputStream is) throws IOException {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ byte[] data = new byte[8192]; // 8KB
+ int n;
+ while ((n = is.read(data, 0, data.length)) != -1) {
+ buffer.write(data, 0, n);
+ }
+ return buffer.toByteArray();
+ }
}
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 ee501d2..a79fba1 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
@@ -115,7 +115,10 @@ public class Main {
"android.database.ContentObserver", // for Digital clock
"com.android.i18n.phonenumbers.*", // for TextView with autolink attribute
},
- excludeClasses);
+ excludeClasses,
+ new String[] {
+ "com/android/i18n/phonenumbers/data/*",
+ });
aa.analyze();
agen.generate();