Skip to content

Commit

Permalink
Avoid calling adb.terminate()
Browse files Browse the repository at this point in the history
This implementation should be closer to what Android Gradle plugin does.
They use `initIfNeeded` in `ConnectedDevice` before creating an ADB instance
and do not call `terminate()`.
  • Loading branch information
Roman Mazur committed Mar 17, 2015
1 parent 3372915 commit cb3eb95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
31 changes: 13 additions & 18 deletions spoon-runner/src/main/java/com/squareup/spoon/SpoonRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,21 @@ public boolean run() {

AndroidDebugBridge adb = SpoonUtils.initAdb(androidSdk);

try {
// If we were given an empty serial set, load all available devices.
Set<String> serials = this.serials;
if (serials.isEmpty()) {
serials = SpoonUtils.findAllDevices(adb);
}
if (failIfNoDeviceConnected && serials.isEmpty()) {
throw new RuntimeException("No device(s) found.");
}
// If we were given an empty serial set, load all available devices.
Set<String> serials = this.serials;
if (serials.isEmpty()) {
serials = SpoonUtils.findAllDevices(adb);
}
if (failIfNoDeviceConnected && serials.isEmpty()) {
throw new RuntimeException("No device(s) found.");
}

// Execute all the things...
SpoonSummary summary = runTests(adb, serials);
// ...and render to HTML
new HtmlRenderer(summary, SpoonUtils.GSON, output).render();
// Execute all the things...
SpoonSummary summary = runTests(adb, serials);
// ...and render to HTML
new HtmlRenderer(summary, SpoonUtils.GSON, output).render();

return parseOverallSuccess(summary);
} finally {
AndroidDebugBridge.disconnectBridge();
AndroidDebugBridge.terminate();
}
return parseOverallSuccess(summary);
}

private SpoonSummary runTests(AndroidDebugBridge adb, Set<String> serials) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static Set<String> findAllDevices(AndroidDebugBridge adb) {

/** Get an {@link com.android.ddmlib.AndroidDebugBridge} instance given an SDK path. */
static AndroidDebugBridge initAdb(File sdk) {
AndroidDebugBridge.init(false);
AndroidDebugBridge.initIfNeeded(false);
File adbPath = FileUtils.getFile(sdk, "platform-tools", "adb");
AndroidDebugBridge adb = AndroidDebugBridge.createBridge(adbPath.getAbsolutePath(), true);
waitForAdb(adb);
Expand Down

0 comments on commit cb3eb95

Please sign in to comment.