summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2012-08-14 12:54:17 +0100
committerNarayan Kamath <narayan@google.com>2012-08-14 13:05:28 +0100
commite028ec166b5a270d0c330800d12a270494176fdf (patch)
treea3b4fe35f0b3b71511d381a5c6e15c5942fa4bc5 /src/com
parent39909902f8225d886e40f929aaa25a2ef2aa58ec (diff)
downloadlittlemock-e028ec166b5a270d0c330800d12a270494176fdf.tar.gz
Fix app cache dir guessing.
A change to BaseDexClassLoader changed the format of its toString output which we rely upon (yuck) to figure out what the cache dir should be. Change-Id: I0f28e3eff9eba70a1f5e6c538aa8da32c264515b
Diffstat (limited to 'src/com')
-rw-r--r--src/com/google/testing/littlemock/AppDataDirGuesser.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/com/google/testing/littlemock/AppDataDirGuesser.java b/src/com/google/testing/littlemock/AppDataDirGuesser.java
index e661ed6..254ed7e 100644
--- a/src/com/google/testing/littlemock/AppDataDirGuesser.java
+++ b/src/com/google/testing/littlemock/AppDataDirGuesser.java
@@ -75,7 +75,7 @@ public class AppDataDirGuesser {
}
// Parsing toString() method: yuck. But no other way to get the path.
- // Strip out the bit between angle brackets, that's our path.
+ // Strip out the bit between square brackets, that's our path.
String result = classLoader.toString();
int index = result.lastIndexOf('[');
result = (index == -1) ? result : result.substring(index + 1);
@@ -86,7 +86,7 @@ public class AppDataDirGuesser {
// @VisibleForTesting
File[] guessPath(String input) {
List<File> results = new ArrayList<File>();
- for (String potential : input.split(":")) {
+ for (String potential : splitPathList(input)) {
if (!potential.startsWith("/data/app/")) {
continue;
}
@@ -110,10 +110,25 @@ public class AppDataDirGuesser {
}
}
}
+
return results.toArray(new File[results.size()]);
}
// @VisibleForTesting
+ static String[] splitPathList(String input) {
+ String trimmed = input;
+ if (input.startsWith("dexPath=")) {
+ int start = "dexPath=".length();
+ int end = input.indexOf(',');
+
+ trimmed = (end == -1) ? input.substring(start) :
+ input.substring(start, end);
+ }
+
+ return trimmed.split(":");
+ }
+
+ // @VisibleForTesting
boolean fileOrDirExists(File file) {
return file.exists();
}