use of dalvik.system.DexFile in project android_frameworks_base by DirtyUnicorns.
the class ClassPathPackageInfoSource method findClassesInApk.
/**
* Finds all classes and sub packages that are below the packageName and
* add them to the respective sets. Searches the package in a single apk file.
*/
private void findClassesInApk(String apkPath, String packageName, Set<String> classNames, Set<String> subpackageNames) throws IOException {
DexFile dexFile = null;
try {
dexFile = new DexFile(apkPath);
Enumeration<String> apkClassNames = dexFile.entries();
while (apkClassNames.hasMoreElements()) {
String className = apkClassNames.nextElement();
if (className.startsWith(packageName)) {
String subPackageName = packageName;
int lastPackageSeparator = className.lastIndexOf('.');
if (lastPackageSeparator > 0) {
subPackageName = className.substring(0, lastPackageSeparator);
}
if (subPackageName.length() > packageName.length()) {
subpackageNames.add(subPackageName);
} else if (isToplevelClass(className)) {
classNames.add(className);
}
}
}
} catch (IOException e) {
if (false) {
Log.w("ClassPathPackageInfoSource", "Error finding classes at apk path: " + apkPath, e);
}
} finally {
if (dexFile != null) {
// Todo: figure out why closing causes a dalvik error resulting in vm shutdown.
// dexFile.close();
}
}
}
use of dalvik.system.DexFile in project android_frameworks_base by DirtyUnicorns.
the class RunTestCommand method addTestClassesFromJars.
/**
* Add test classes from jars passed on the command line. Use this if nothing was explicitly
* specified on the command line.
*/
private void addTestClassesFromJars() {
String jars = mParams.getString(JARS_PARAM);
if (jars == null)
return;
String[] jarFileNames = jars.split(JARS_SEPARATOR);
for (String fileName : jarFileNames) {
fileName = fileName.trim();
if (fileName.isEmpty())
continue;
try {
DexFile dexFile = new DexFile(fileName);
for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
String className = e.nextElement();
if (isTestClass(className)) {
mTestClasses.add(className);
}
}
dexFile.close();
} catch (IOException e) {
Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
}
}
}
use of dalvik.system.DexFile in project android_frameworks_base by AOSPA.
the class RunTestCommand method addTestClassesFromJars.
/**
* Add test classes from jars passed on the command line. Use this if nothing was explicitly
* specified on the command line.
*/
private void addTestClassesFromJars() {
String jars = mParams.getString(JARS_PARAM);
if (jars == null)
return;
String[] jarFileNames = jars.split(JARS_SEPARATOR);
for (String fileName : jarFileNames) {
fileName = fileName.trim();
if (fileName.isEmpty())
continue;
try {
DexFile dexFile = new DexFile(fileName);
for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
String className = e.nextElement();
if (isTestClass(className)) {
mTestClasses.add(className);
}
}
dexFile.close();
} catch (IOException e) {
Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
}
}
}
use of dalvik.system.DexFile in project platform_frameworks_base by android.
the class RunTestCommand method addTestClassesFromJars.
/**
* Add test classes from jars passed on the command line. Use this if nothing was explicitly
* specified on the command line.
*/
private void addTestClassesFromJars() {
String jars = mParams.getString(JARS_PARAM);
if (jars == null)
return;
String[] jarFileNames = jars.split(JARS_SEPARATOR);
for (String fileName : jarFileNames) {
fileName = fileName.trim();
if (fileName.isEmpty())
continue;
try {
DexFile dexFile = new DexFile(fileName);
for (Enumeration<String> e = dexFile.entries(); e.hasMoreElements(); ) {
String className = e.nextElement();
if (isTestClass(className)) {
mTestClasses.add(className);
}
}
dexFile.close();
} catch (IOException e) {
Log.w(LOGTAG, String.format("Could not read %s: %s", fileName, e.getMessage()));
}
}
}
use of dalvik.system.DexFile in project platform_frameworks_base by android.
the class ClassPathPackageInfoSource method findClassesInApk.
/**
* Finds all classes and sub packages that are below the packageName and
* add them to the respective sets. Searches the package in a single apk file.
*/
private void findClassesInApk(String apkPath, String packageName, Set<String> classNames, Set<String> subpackageNames) throws IOException {
DexFile dexFile = null;
try {
dexFile = new DexFile(apkPath);
Enumeration<String> apkClassNames = dexFile.entries();
while (apkClassNames.hasMoreElements()) {
String className = apkClassNames.nextElement();
if (className.startsWith(packageName)) {
String subPackageName = packageName;
int lastPackageSeparator = className.lastIndexOf('.');
if (lastPackageSeparator > 0) {
subPackageName = className.substring(0, lastPackageSeparator);
}
if (subPackageName.length() > packageName.length()) {
subpackageNames.add(subPackageName);
} else if (isToplevelClass(className)) {
classNames.add(className);
}
}
}
} catch (IOException e) {
if (false) {
Log.w("ClassPathPackageInfoSource", "Error finding classes at apk path: " + apkPath, e);
}
} finally {
if (dexFile != null) {
// Todo: figure out why closing causes a dalvik error resulting in vm shutdown.
// dexFile.close();
}
}
}
Aggregations