aboutsummaryrefslogtreecommitdiff
path: root/builder
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-12-20 14:38:41 -0800
committerXavier Ducrohet <xav@android.com>2012-12-20 15:15:22 -0800
commit3f02867a071f1ab88f24941e8e586aa2419dbee5 (patch)
tree74d1c1532a3d954d0b47b3ba166a333f2efce2f5 /builder
parent1b97db59f8b63d8cc33e5fd6b5412a02528beb01 (diff)
downloadbuild-3f02867a071f1ab88f24941e8e586aa2419dbee5.tar.gz
Fix misc issues from the 2 previous changes.
Change-Id: I4d384d3c5aa2af67cbdd1f68433104e279de3c07
Diffstat (limited to 'builder')
-rw-r--r--builder/src/main/java/com/android/builder/VariantConfiguration.java2
-rw-r--r--builder/src/main/java/com/android/builder/internal/CommandLineRunner.java2
-rw-r--r--builder/src/main/java/com/android/builder/internal/compiler/AidlProcessor.java4
-rw-r--r--builder/src/main/java/com/android/builder/internal/incremental/FileEntity.java108
-rw-r--r--builder/src/main/java/com/android/builder/internal/incremental/FileManager.java36
-rw-r--r--builder/src/main/java/com/android/builder/resources/NodeUtils.java15
-rw-r--r--builder/src/main/java/com/android/builder/resources/ResourceMerger.java6
-rw-r--r--builder/src/main/java/com/android/builder/resources/ValueResourceParser.java11
-rw-r--r--builder/src/test/resources/testData/changeManager/files.data2
9 files changed, 80 insertions, 106 deletions
diff --git a/builder/src/main/java/com/android/builder/VariantConfiguration.java b/builder/src/main/java/com/android/builder/VariantConfiguration.java
index f20c13c..4f22242 100644
--- a/builder/src/main/java/com/android/builder/VariantConfiguration.java
+++ b/builder/src/main/java/com/android/builder/VariantConfiguration.java
@@ -540,6 +540,8 @@ public class VariantConfiguration {
SourceProvider sourceProvider = mFlavorSourceProviders.get(n);
Set<File> flavorResDirs = sourceProvider.getResourcesDirectories();
+ // we need the same of the flavor config, but it's in a different list.
+ // This is fine as both list are parallel collections with the same number of items.
resourceSet = new ResourceSet(mFlavorConfigs.get(n).getName());
resourceSet.addSources(flavorResDirs);
resourceSets.add(resourceSet);
diff --git a/builder/src/main/java/com/android/builder/internal/CommandLineRunner.java b/builder/src/main/java/com/android/builder/internal/CommandLineRunner.java
index 81af9d9..8155108 100644
--- a/builder/src/main/java/com/android/builder/internal/CommandLineRunner.java
+++ b/builder/src/main/java/com/android/builder/internal/CommandLineRunner.java
@@ -44,7 +44,7 @@ public class CommandLineRunner {
// get the output and return code from the process
if (grabProcessOutput(process) != 0) {
- throw new RuntimeException(String.format("running %s failed. see output", command[0]));
+ throw new RuntimeException(String.format("Running %s failed. See output", command[0]));
}
}
diff --git a/builder/src/main/java/com/android/builder/internal/compiler/AidlProcessor.java b/builder/src/main/java/com/android/builder/internal/compiler/AidlProcessor.java
index d7401de..5d7de56 100644
--- a/builder/src/main/java/com/android/builder/internal/compiler/AidlProcessor.java
+++ b/builder/src/main/java/com/android/builder/internal/compiler/AidlProcessor.java
@@ -63,14 +63,14 @@ public class AidlProcessor implements SourceGenerator.Processor {
command.add("-p" + mFrameworkLocation);
command.add("-o" + sourceOutputDir.getAbsolutePath());
// add all the source folders as import in case an aidl file in a source folder
- // imports a parceleable from another source folder.
+ // imports a parcelable from another source folder.
for (File sourceFolder : sourceFolders) {
if (sourceFolder.isDirectory()) {
command.add("-I" + sourceFolder.getAbsolutePath());
}
}
- // add all the library aidl folders to access parceleables that are in libraries
+ // add all the library aidl folders to access parcelables that are in libraries
for (File f : mImportFolders) {
command.add("-I" + f.getAbsolutePath());
}
diff --git a/builder/src/main/java/com/android/builder/internal/incremental/FileEntity.java b/builder/src/main/java/com/android/builder/internal/incremental/FileEntity.java
index ba0174a..a981d8e 100644
--- a/builder/src/main/java/com/android/builder/internal/incremental/FileEntity.java
+++ b/builder/src/main/java/com/android/builder/internal/incremental/FileEntity.java
@@ -16,11 +16,12 @@
package com.android.builder.internal.incremental;
+import com.google.common.hash.HashCode;
+import com.google.common.hash.Hashing;
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Files;
+
import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.security.MessageDigest;
-import java.util.Formatter;
/**
* A {@link File} and its associated data needed to figure out if a file changed or not.
@@ -29,10 +30,10 @@ class FileEntity {
private static final byte[] sBuffer = new byte[4096];
- private final File file;
- private final long lastModified;
- private long length;
- private String sha1;
+ private final File mFile;
+ private final long mLastModified;
+ private long mLength;
+ private String mSha1;
/**
* Exception to indicate a failure to check a jar file's content.
@@ -60,10 +61,10 @@ class FileEntity {
* @param sha1 its sha1
*/
FileEntity(File file, long lastModified, long length, String sha1) {
- this.file = file;
- this.lastModified = lastModified;
- this.length = length;
- this.sha1 = sha1;
+ mFile = file;
+ mLastModified = lastModified;
+ mLength = length;
+ mSha1 = sha1;
}
/**
@@ -74,9 +75,9 @@ class FileEntity {
* @param file the file.
*/
FileEntity(File file) {
- this.file = file;
- lastModified = file.lastModified();
- length = file.length();
+ mFile = file;
+ mLastModified = file.lastModified();
+ mLength = file.length();
}
/**
@@ -84,7 +85,7 @@ class FileEntity {
* @return the file's last modified info.
*/
long getLastModified() {
- return lastModified;
+ return mLastModified;
}
/**
@@ -92,7 +93,7 @@ class FileEntity {
* @return the file length.
*/
long getLength() {
- return length;
+ return mLength;
}
/**
@@ -100,13 +101,13 @@ class FileEntity {
* @return the file.
*/
File getFile() {
- return file;
+ return mFile;
}
/**
* Returns the file's sha1, computing it if necessary.
*
- * @return the sha1 or null if it couldn't be computed.
+ * @return the fha1 or null if it couldn't be computed.
*/
String getSha1() {
try {
@@ -123,9 +124,9 @@ class FileEntity {
* @return return whether the file was changed.
*/
private boolean checkValidity() {
- if (lastModified != file.lastModified()) {
- length = file.length();
- sha1 = null;
+ if (mLastModified != mFile.lastModified()) {
+ mLength = mFile.length();
+ mSha1 = null;
return true;
}
@@ -141,17 +142,17 @@ class FileEntity {
* @return true if the files are the same, false otherwise.
*/
public boolean isDifferentThan(FileEntity fileEntity) {
- assert fileEntity.file.equals(file);
+ assert fileEntity.mFile.equals(mFile);
// same date, same files.
- if (lastModified == fileEntity.lastModified) {
+ if (mLastModified == fileEntity.mLastModified) {
return false;
}
try {
// different date doesn't necessarily mean different file.
// start with size, less computing intensive than sha1.
- return length != fileEntity.length ||
+ return mLength != fileEntity.mLength ||
!computeAndReturnSha1().equals(fileEntity.computeAndReturnSha1());
} catch (Sha1Exception e) {
// if we can't compute the sha1, we consider the files different.
@@ -166,10 +167,10 @@ class FileEntity {
* @throws Sha1Exception
*/
private String computeAndReturnSha1() throws Sha1Exception {
- if (sha1 == null) {
- sha1 = getSha1(file);
+ if (mSha1 == null) {
+ mSha1 = getSha1(mFile);
}
- return sha1;
+ return mSha1;
}
/**
@@ -181,60 +182,23 @@ class FileEntity {
*/
static String getSha1(File f) throws Sha1Exception {
synchronized (sBuffer) {
- FileInputStream fis = null;
- try {
- MessageDigest md = MessageDigest.getInstance("SHA-1");
-
- fis = new FileInputStream(f);
- while (true) {
- int length = fis.read(sBuffer);
- if (length > 0) {
- md.update(sBuffer, 0, length);
- } else {
- break;
- }
- }
-
- return byteArray2Hex(md.digest());
+ try {
+ HashCode value = ByteStreams.hash(Files.newInputStreamSupplier(f), Hashing.sha1());
+ return value.toString();
} catch (Exception e) {
throw new Sha1Exception(f, e);
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
- }
-
- /**
- * Converts a byte array to an Hex string.
- * @param hash the byte array to convert,
- * @return the converted string.
- */
- private static String byteArray2Hex(final byte[] hash) {
- Formatter formatter = new Formatter();
- try {
- for (byte b : hash) {
- formatter.format("%02x", b);
}
- return formatter.toString();
- } finally {
- formatter.close();
}
}
@Override
public String toString() {
return "FileEntity{" +
- "file=" + file +
- ", lastModified=" + lastModified +
- ", length=" + length +
- ", sha1='" + sha1 + '\'' +
+ "mFile=" + mFile +
+ ", mLastModified=" + mLastModified +
+ ", mLength=" + mLength +
+ ", mSha1='" + mSha1 + '\'' +
'}';
}
}
diff --git a/builder/src/main/java/com/android/builder/internal/incremental/FileManager.java b/builder/src/main/java/com/android/builder/internal/incremental/FileManager.java
index 42055e5..2dbebd8 100644
--- a/builder/src/main/java/com/android/builder/internal/incremental/FileManager.java
+++ b/builder/src/main/java/com/android/builder/internal/incremental/FileManager.java
@@ -18,9 +18,19 @@ package com.android.builder.internal.incremental;
import com.android.annotations.NonNull;
import com.android.builder.resources.FileStatus;
+import com.google.common.base.Charsets;
import com.google.common.collect.Maps;
-
-import java.io.*;
+import com.google.common.io.Closeables;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -36,7 +46,8 @@ import java.util.regex.Pattern;
*/
class FileManager {
- private static final Pattern READ_PATTERN = Pattern.compile("^(\\d+) (\\d+) ([0-9a-f]+) (.+)$");
+ private static final Pattern READ_PATTERN = Pattern.compile(
+ "^(\\d+)\\s+(\\d+)\\s+([0-9a-f]+)\\s+(.+)$");
private Map<File, FileEntity> mLoadedFiles = Maps.newHashMap();
private Map<File, FileEntity> mProcessedFiles = Maps.newHashMap();
@@ -62,7 +73,7 @@ class FileManager {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(
- new FileInputStream(stateFile), "UTF-8"));
+ new FileInputStream(stateFile), Charsets.UTF_8));
String line = null;
while ((line = reader.readLine()) != null) {
@@ -95,13 +106,7 @@ class FileManager {
} catch (IOException ignored) {
// shouldn't happen, but if it does, we just won't have a cache.
} finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException ignored) {
- // ignore
- }
- }
+ Closeables.closeQuietly(reader);
}
return false;
@@ -121,7 +126,7 @@ class FileManager {
parentFolder.mkdirs();
// then write the file.
- writer = new OutputStreamWriter(new FileOutputStream(stateFile), "UTF-8");
+ writer = new OutputStreamWriter(new FileOutputStream(stateFile), Charsets.UTF_8);
writer.write("# incremental data. DO NOT EDIT.\n");
writer.write("# format is <lastModified> <length> <SHA-1> <path>\n");
@@ -141,12 +146,7 @@ class FileManager {
}
} catch (IOException ignored) {
} finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException ignored) {
- }
- }
+ Closeables.closeQuietly(writer);
}
}
diff --git a/builder/src/main/java/com/android/builder/resources/NodeUtils.java b/builder/src/main/java/com/android/builder/resources/NodeUtils.java
index dcdfa2a..2de1137 100644
--- a/builder/src/main/java/com/android/builder/resources/NodeUtils.java
+++ b/builder/src/main/java/com/android/builder/resources/NodeUtils.java
@@ -18,7 +18,12 @@ package com.android.builder.resources;
import com.android.SdkConstants;
import com.android.annotations.VisibleForTesting;
-import org.w3c.dom.*;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
/**
* Utility class to handle Nodes.
@@ -44,17 +49,17 @@ class NodeUtils {
}
static void addAttribute(Document document, Node node,
- String NamespaceUri, String attrName, String attrValue) {
+ String namespaceUri, String attrName, String attrValue) {
Attr attr;
- if (NamespaceUri != null) {
- attr = document.createAttributeNS(NamespaceUri, attrName);
+ if (namespaceUri != null) {
+ attr = document.createAttributeNS(namespaceUri, attrName);
} else {
attr = document.createAttribute(attrName);
}
attr.setValue(attrValue);
- if (NamespaceUri != null) {
+ if (namespaceUri != null) {
node.getAttributes().setNamedItemNS(attr);
} else {
node.getAttributes().setNamedItem(attr);
diff --git a/builder/src/main/java/com/android/builder/resources/ResourceMerger.java b/builder/src/main/java/com/android/builder/resources/ResourceMerger.java
index 88dab2f..3f3b043 100644
--- a/builder/src/main/java/com/android/builder/resources/ResourceMerger.java
+++ b/builder/src/main/java/com/android/builder/resources/ResourceMerger.java
@@ -42,7 +42,11 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Merges {@link ResourceSet}s and writes a resource folder that can be fed to aapt.
diff --git a/builder/src/main/java/com/android/builder/resources/ValueResourceParser.java b/builder/src/main/java/com/android/builder/resources/ValueResourceParser.java
index fd1b0ec..9adda0a 100644
--- a/builder/src/main/java/com/android/builder/resources/ValueResourceParser.java
+++ b/builder/src/main/java/com/android/builder/resources/ValueResourceParser.java
@@ -19,6 +19,7 @@ package com.android.builder.resources;
import com.android.annotations.NonNull;
import com.android.resources.ResourceType;
import com.google.common.collect.Lists;
+import com.google.common.io.Closeables;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -36,7 +37,9 @@ import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import static com.android.SdkConstants.*;
+import static com.android.SdkConstants.ATTR_NAME;
+import static com.android.SdkConstants.ATTR_TYPE;
+import static com.android.SdkConstants.TAG_ITEM;
/**
* Parser for "values" files.
@@ -168,11 +171,7 @@ class ValueResourceParser {
} catch (SAXException e) {
throw new IOException(e);
} finally {
- try {
- stream.close();
- } catch (IOException e) {
- // ignore
- }
+ Closeables.closeQuietly(stream);
}
}
}
diff --git a/builder/src/test/resources/testData/changeManager/files.data b/builder/src/test/resources/testData/changeManager/files.data
index 7c1c157..f91a8ff 100644
--- a/builder/src/test/resources/testData/changeManager/files.data
+++ b/builder/src/test/resources/testData/changeManager/files.data
@@ -1,4 +1,4 @@
-# golden files created manually to differ form the actual
+# golden files created manually to differ from the actual
# files in key ways to test various detectors.
$lm_untouched$ 98 272fbc249474f5c842db3c6273ca94e30e641d06 $TOP$$SEP$untouched.png
1000000000000 98 272fbc249474f5c842db3c6273ca94e30e641d06 $TOP$$SEP$untouched_date_changed.png