Permalink
Browse files

[FIXED JENKINS-12120] Check for config.ini before starting or after c…

…reating AVD.

Also show error output if AVD creation fails for some unknown reason.

This allows the plugin to detect and recover from incorrectly-created AVDs;
existing AVDs found without a config.ini file will be replaced with a new AVD.
  • Loading branch information...
orrc committed Mar 23, 2012
1 parent 8a087d8 commit 21b1693bafc80a989a31f7b08290f9492ed1d4c1
Showing with 14 additions and 3 deletions.
  1. +14 −3 src/main/java/hudson/plugins/android_emulator/EmulatorConfig.java
@@ -237,8 +237,12 @@ public File getAvdMetadataFile(boolean isUnix) {
return new File(getAvdHome(homeDir), getAvdName() +".ini");
}

private File getAvdConfigFile(File homeDir) {
return new File(getAvdDirectory(homeDir), "config.ini");
}

private Map<String,String> parseAvdConfigFile(File homeDir) throws IOException {
File configFile = new File(getAvdDirectory(homeDir), "config.ini");
File configFile = getAvdConfigFile(homeDir);
return Utils.parseConfigFile(configFile);
}

@@ -354,7 +358,7 @@ public Boolean call() throws AndroidEmulatorException {

final File homeDir = Utils.getHomeDirectory(isUnix);
final File avdDirectory = getAvdDirectory(homeDir);
final boolean emulatorExists = avdDirectory.exists();
final boolean emulatorExists = getAvdConfigFile(homeDir).exists();

// Can't do anything if a named emulator doesn't exist
if (isNamedEmulator() && !emulatorExists) {
@@ -436,6 +440,9 @@ public Boolean call() throws AndroidEmulatorException {
final StringBuilder args = new StringBuilder(100);
args.append("create avd ");

// Overwrite any existing files
args.append("-f ");

// Initialise snapshot support, regardless of whether we will actually use it
if (androidSdk.supportsSnapshots()) {
args.append("-a ");
@@ -456,6 +463,9 @@ public Boolean call() throws AndroidEmulatorException {
builder.add("-t");
builder.add(osVersion.getTargetName());

// Log command line used, for info
AndroidEmulator.log(logger, builder.toStringWithQuote());

// Run!
boolean avdCreated = false;
final Process process;
@@ -501,7 +511,8 @@ public Boolean call() throws AndroidEmulatorException {

// Wait for happy ending
if (process.waitFor() == 0) {
avdCreated = true;
// Do a sanity check to ensure the AVD was really created
avdCreated = getAvdConfigFile(homeDir).exists();
}

} catch (IOException e) {

0 comments on commit 21b1693

Please sign in to comment.