// if it's a dalvik-cache entry, grab the name of the jar/apk
if (entryName.endsWith("@classes.dex")) {
Matcher m = dalvikCacheOdexPattern.matcher(entryName);
if (!m.find()) {
throw new ExceptionWithContext(String.format("Cannot parse dependency value %s", bootClassPathEntry));
}
entryName = m.group(1);
}
int extIndex = entryName.lastIndexOf(".");
String baseEntryName;
if (extIndex == -1) {
baseEntryName = entryName;
} else {
baseEntryName = entryName.substring(0, extIndex);
}
for (String classPathDir: classPathDirs) {
for (String ext: new String[]{"", ".odex", ".jar", ".apk", ".zip"}) {
File file = new File(classPathDir, baseEntryName + ext);
if (file.exists() && file.isFile()) {
if (!file.canRead()) {
System.err.println(String.format(
"warning: cannot open %s for reading. Will continue looking.", file.getPath()));
} else {
try {
return DexFileFactory.loadDexFile(file, api);
} catch (DexFileFactory.NoClassesDexException ex) {
// ignore and continue
} catch (Exception ex) {
throw ExceptionWithContext.withContext(ex,
"Error while reading boot class path entry \"%s\"", bootClassPathEntry);
}
}
}
}
}
throw new ExceptionWithContext("Cannot locate boot class path file %s", bootClassPathEntry);
}