Permalink
Browse files

[FIXED JENKINS-17532] Ensure system images are installed as required.

Previously, if the platform itself was installed — e.g. due to using the
"Install Android project prerequisites" build step — we wouldn't check, when
trying to start an emulator, whether any required system images were also
installed. If they were missing, emulator creation would fail every time.

Now we check that both the platform and at least one system image have been
installed for the desired platform.

If there are no system images installed, all images will be downloaded.
This is slightly dumb at the moment, as we will also re-download the platform,
even if it already exists, and we won't download any system images if there is
at least one installed for the given platform — regardless of whether it's the
one required for the configured emulator.
  • Loading branch information...
orrc committed May 14, 2014
1 parent eef391e commit 9c7199a54e6575afb192f2accce714325d13df04
Showing with 24 additions and 7 deletions.
  1. +24 −7 src/main/java/hudson/plugins/android_emulator/SdkInstaller.java
@@ -1,6 +1,5 @@
package hudson.plugins.android_emulator;

import static hudson.plugins.android_emulator.AndroidEmulator.log;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
@@ -18,6 +17,7 @@
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.ArgumentListBuilder;
import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -41,7 +41,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import static hudson.plugins.android_emulator.AndroidEmulator.log;

public class SdkInstaller {

@@ -264,7 +264,7 @@ public static void installPlatform(PrintStream logger, Launcher launcher,
public static void installPlatform(PrintStream logger, Launcher launcher, AndroidSdk sdk,
String platform, boolean includeSystemImages) throws IOException, InterruptedException {
// Check whether this platform is already installed
if (isPlatformInstalled(logger, launcher, sdk, platform)) {
if (isPlatformInstalled(logger, launcher, sdk, platform, includeSystemImages)) {
return;
}

@@ -298,7 +298,7 @@ public static void installPlatform(PrintStream logger, Launcher launcher, Androi
if (components.size() > 1) {
for (Iterator<String> it = components.iterator(); it.hasNext(); ) {
String component = it.next();
if (isPlatformInstalled(logger, launcher, sdk, component)) {
if (isPlatformInstalled(logger, launcher, sdk, component, includeSystemImages)) {
it.remove();
}
}
@@ -314,11 +314,28 @@ public static void installPlatform(PrintStream logger, Launcher launcher, Androi
}

private static boolean isPlatformInstalled(PrintStream logger, Launcher launcher,
AndroidSdk sdk, String platform) throws IOException, InterruptedException {
AndroidSdk sdk, String platform, boolean includeSystemImages) throws IOException, InterruptedException {
ByteArrayOutputStream targetList = new ByteArrayOutputStream();
// Preferably we'd use the "--compact" flag here, but it wasn't added until r12
// Preferably we'd use the "--compact" flag here, but it wasn't added until r12,
// nor does it give any information about which system images are installed...
Utils.runAndroidTool(launcher, targetList, logger, sdk, Tool.ANDROID, "list target", null);
return targetList.toString().contains('"'+ platform +'"');
boolean platformInstalled = targetList.toString().contains('"'+ platform +'"');
if (!platformInstalled) {
return false;
}

if (includeSystemImages) {
// Check that the given platform does not have the "no ABIs" text (i.e. system images *are* installed)
Pattern regex = Pattern.compile(String.format("\"%s\".+?no ABIs", platform), Pattern.DOTALL);
Matcher matcher = regex.matcher(targetList.toString());
if (matcher.find() && !matcher.group(0).contains("---")) {
// We found the "no ABIs" text, within the section for the given platform
return false;
}
}

// Everything we wanted is installed
return true;
}

private static List<String> getSdkComponentsForPlatform(PrintStream logger, String platform,

0 comments on commit 9c7199a

Please sign in to comment.