Skip to content

Commit

Permalink
[FIXED JENKINS-17532] Ensure system images are installed as required.
Browse files Browse the repository at this point in the history
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 9c7199a
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions 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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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,
Expand Down

0 comments on commit 9c7199a

Please sign in to comment.