aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks/src/com
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-09-18 12:21:44 -0700
committerXavier Ducrohet <xav@android.com>2012-09-18 12:24:04 -0700
commitf92c116240bc645a89b12975dd438a46645abe88 (patch)
treed724df7a991b2c7ed27c29a51f5b8c08735a0bbc /anttasks/src/com
parent0f86143e55290c4851e51b9a46ff21e198a35acc (diff)
downloadsdk-f92c116240bc645a89b12975dd438a46645abe88.zip
sdk-f92c116240bc645a89b12975dd438a46645abe88.tar.gz
sdk-f92c116240bc645a89b12975dd438a46645abe88.tar.bz2
Fix possible NPE reading dep file.
Fix this by using guava Files instead. Also fixes sdklib's manifest. Change-Id: I5dd4123f389ce1bd8c900933021fc2179e6caa3b
Diffstat (limited to 'anttasks/src/com')
-rw-r--r--anttasks/src/com/android/ant/DependencyGraph.java40
1 files changed, 11 insertions, 29 deletions
diff --git a/anttasks/src/com/android/ant/DependencyGraph.java b/anttasks/src/com/android/ant/DependencyGraph.java
index 4a02aa8..f8564da 100644
--- a/anttasks/src/com/android/ant/DependencyGraph.java
+++ b/anttasks/src/com/android/ant/DependencyGraph.java
@@ -16,13 +16,13 @@
package com.android.ant;
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
import org.apache.tools.ant.BuildException;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -145,7 +145,7 @@ public class DependencyGraph {
mDepFileLastModified = depFile.lastModified();
// Read in our dependency file
- String content = readFile(dependencyFilePath);
+ List<String> content = readFile(depFile);
if (content == null) {
System.err.println("ERROR: Couldn't read " + dependencyFilePath);
return;
@@ -155,9 +155,8 @@ public class DependencyGraph {
// output1 output2 [...]: dep1 dep2 [...]
// expect it's likely split on several lines. So let's move it back on a single line
// first
- String[] lines = content.toString().split("\n");
- StringBuilder sb = new StringBuilder(content.length());
- for (String line : lines) {
+ StringBuilder sb = new StringBuilder();
+ for (String line : content) {
line = line.trim();
if (line.endsWith("\\")) {
line = line.substring(0, line.length() - 1);
@@ -427,33 +426,16 @@ public class DependencyGraph {
/**
* Reads and returns the content of a text file.
- * @param filepath the file path to the text file
+ * @param file the file path to the text file
* @return null if the file could not be read
*/
- private static String readFile(String filepath) {
- FileInputStream fStream = null;
- BufferedReader reader = null;
+ private static List<String> readFile(File file) {
try {
- fStream = new FileInputStream(filepath);
- reader = new BufferedReader(new InputStreamReader(fStream));
-
- String line;
- StringBuilder total = new StringBuilder(reader.readLine());
- while ((line = reader.readLine()) != null) {
- total.append('\n');
- total.append(line);
- }
- return total.toString();
+ return Files.readLines(file, Charsets.UTF_8);
} catch (IOException e) {
- // we'll just return null
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- }
- }
+ // return null below
}
+
return null;
}
}