Skip to content

Commit

Permalink
[FIXED JENKINS-26893] Disable the Android bug #34233 workaround on ne…
Browse files Browse the repository at this point in the history
…wer SDKs.

We no longer need to avoid the 64-bit emulators as of SDK tools version 22.6,
and the 32-bit emulators are no longer bundled on OS X, so hardcoding the usage
of `emulator-arm` was no longer working.

Now we only apply the workaround if an affected SDK tools version is installed.
  • Loading branch information
orrc committed Feb 12, 2015
1 parent 8c2cf36 commit b02c1cf
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 72 deletions.
Expand Up @@ -372,7 +372,7 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
//
// With the adb socket open we know the correct process is running, so we set this flag to
// indicate that any methods wanting to check the "emulator" process state should ignore it.
boolean ignoreProcess = !launcher.isUnix() && androidSdk.getSdkToolsVersion() >= 12;
boolean ignoreProcess = !launcher.isUnix() && androidSdk.getSdkToolsMajorVersion() >= 12;

// Notify adb of our existence
int result = emu.getToolProcStarter(Tool.ADB, "connect " + emu.serial()).join();
Expand Down
Expand Up @@ -357,10 +357,8 @@ public boolean hasExistingSnapshot(Launcher launcher, AndroidSdk androidSdk)
// List available snapshots for this emulator
ByteArrayOutputStream listOutput = new ByteArrayOutputStream();
String args = String.format("-snapshot-list -no-window -avd %s", getAvdName());
// Work around
// https://code.google.com/p/android/issues/detail?id=34233
// by always using EMULATOR_ARM to view the snapshot list.
Utils.runAndroidTool(launcher, listOutput, logger, androidSdk, Tool.EMULATOR_ARM, args, null);
Tool executable = androidSdk.requiresAndroidBug34233Workaround() ? Tool.EMULATOR_ARM : Tool.EMULATOR;
Utils.runAndroidTool(launcher, listOutput, logger, androidSdk, executable, args, null);

// Check whether a Jenkins snapshot was listed in the output
return Pattern.compile(Constants.REGEX_SNAPSHOT).matcher(listOutput.toString()).find();
Expand Down
Expand Up @@ -199,7 +199,7 @@ private static void installComponent(PrintStream logger, Launcher launcher, Andr
// Build the command to install the given component(s)
String list = StringUtils.join(components, ',');
log(logger, Messages.INSTALLING_SDK_COMPONENTS(list));
String all = sdk.getSdkToolsVersion() < 17 ? "-o" : "-a";
String all = sdk.getSdkToolsMajorVersion() < 17 ? "-o" : "-a";
String upgradeArgs = String.format("update sdk -u %s %s -t %s", all, proxySettings, list);
ArgumentListBuilder cmd = Utils.getToolCommand(sdk, launcher.isUnix(), Tool.ANDROID, upgradeArgs);
ProcStarter procStarter = launcher.launch().stderr(logger).readStdout().writeStdin().cmds(cmd);
Expand Down Expand Up @@ -259,7 +259,7 @@ public static void installPlatform(PrintStream logger, Launcher launcher, Androi

// Check whether we are capable of installing individual components
log(logger, Messages.PLATFORM_INSTALL_REQUIRED(platform));
if (!launcher.isUnix() && platform.contains(":") && sdk.getSdkToolsVersion() < 16) {
if (!launcher.isUnix() && platform.contains(":") && sdk.getSdkToolsMajorVersion() < 16) {
// SDK add-ons can't be installed on Windows until r16 due to http://b.android.com/18868
log(logger, Messages.SDK_ADDON_INSTALLATION_UNSUPPORTED());
return;
Expand Down
55 changes: 27 additions & 28 deletions src/main/java/hudson/plugins/android_emulator/sdk/AndroidSdk.java
@@ -1,7 +1,9 @@
package hudson.plugins.android_emulator.sdk;

import com.google.common.annotations.VisibleForTesting;
import hudson.Util;
import hudson.plugins.android_emulator.util.Utils;
import hudson.util.VersionNumber;

import java.io.File;
import java.io.IOException;
Expand All @@ -26,9 +28,7 @@ public class AndroidSdk implements Serializable {

private final String sdkRoot;
private final String sdkHome;
private boolean usesPlatformTools;
private int sdkToolsVersion;
private String sdkToolsRevision;
private String sdkToolsVersion;

public AndroidSdk(String root, String home) throws IOException {
this.sdkRoot = root;
Expand All @@ -39,18 +39,11 @@ public AndroidSdk(String root, String home) throws IOException {
}

private void determineVersion() throws IOException {
// Determine whether SDK has platform tools installed
File toolsDirectory = new File(sdkRoot, "platform-tools");
setUsesPlatformTools(toolsDirectory.isDirectory());

// Determine SDK tools version
File toolsPropFile = new File(sdkRoot, "tools/source.properties");
Map<String, String> toolsProperties;
toolsProperties = Utils.parseConfigFile(toolsPropFile);
String revisionStr = Util.fixEmptyAndTrim(toolsProperties.get("Pkg.Revision"));
if (revisionStr != null) {
setSdkToolsVersion(Utils.parseRevisionString(revisionStr));
}
sdkToolsVersion = Util.fixEmptyAndTrim(toolsProperties.get("Pkg.Revision"));
}

public boolean hasKnownRoot() {
Expand All @@ -69,37 +62,43 @@ public String getSdkHome() {
return this.sdkHome;
}

public boolean usesPlatformTools() {
return this.usesPlatformTools;
}

public void setUsesPlatformTools(boolean usesPlatformTools) {
this.usesPlatformTools = usesPlatformTools;
}

public void setSdkToolsVersion(int version) {
this.sdkToolsVersion = version;
@VisibleForTesting
void setSdkToolsVersion(String version) {
sdkToolsVersion = version;
}

/** @return The major version number of the SDK tools being used. */
public int getSdkToolsVersion() {
return this.sdkToolsVersion;
/** @return The major version number of the SDK tools being used, or {@code 0} if unknown. */
public int getSdkToolsMajorVersion() {
if (sdkToolsVersion == null) {
return 0;
}
// We create this object on-demand rather than holding on to it, as VersionNumber is not Serializable
return new VersionNumber(sdkToolsVersion).digit(0);
}

public boolean supportsSnapshots() {
return sdkToolsVersion >= SDK_TOOLS_SNAPSHOTS;
return getSdkToolsMajorVersion() >= SDK_TOOLS_SNAPSHOTS;
}

public boolean supportsComponentInstallation() {
return sdkToolsVersion >= SDK_AUTO_INSTALL;
return getSdkToolsMajorVersion() >= SDK_AUTO_INSTALL;
}

public boolean supportsSystemImageInstallation() {
return sdkToolsVersion >= SDK_SYSTEM_IMAGE_INSTALL;
return getSdkToolsMajorVersion() >= SDK_SYSTEM_IMAGE_INSTALL;
}

public boolean supportsSystemImageNewFormat() {
return sdkToolsVersion >= SDK_SYSTEM_IMAGE_NEW_FORMAT;
return getSdkToolsMajorVersion() >= SDK_SYSTEM_IMAGE_NEW_FORMAT;
}

/** {@return true} if we should explicitly select a non-64-bit emulator executable for snapshot-related tasks. */
public boolean requiresAndroidBug34233Workaround() {
if (sdkToolsVersion == null) {
return true;
}
final VersionNumber sdk = new VersionNumber(sdkToolsVersion);
return sdk.isNewerThan(new VersionNumber("20.0.3")) && sdk.isOlderThan(new VersionNumber("22.6"));
}

}
19 changes: 0 additions & 19 deletions src/main/java/hudson/plugins/android_emulator/util/Utils.java
Expand Up @@ -691,25 +691,6 @@ public static int getRelativePathDistance(String from, String to) {
return parts.length;
}

/**
* Attempts to parse an SDK revision string.
*
* @param revisionStr Version string.
* @return The major version (i.e. "26.0.2" returns 26).
* @throws java.lang.NumberFormatException If no number could be determined.
*/
public static int parseRevisionString(String revisionStr) {
try {
return Integer.parseInt(revisionStr);
} catch (NumberFormatException e) {
Matcher matcher = REVISION.matcher(revisionStr);
if (matcher.matches()) {
return Integer.parseInt(matcher.group(1));
}
throw new NumberFormatException("Could not parse "+revisionStr);
}
}

/**
* Determines the API level for the given platform name.
*
Expand Down
@@ -0,0 +1,38 @@
package hudson.plugins.android_emulator.sdk;

import junit.framework.TestCase;

import java.io.IOException;

public class AndroidSdkTest extends TestCase {

public void testGetSdkToolsMajorVersion() throws Exception {
assertEquals(0, createSdkWithTools(null).getSdkToolsMajorVersion());
assertEquals(20, createSdkWithTools("20").getSdkToolsMajorVersion());
assertEquals(20, createSdkWithTools("20.0").getSdkToolsMajorVersion());
assertEquals(20, createSdkWithTools("20.0.1").getSdkToolsMajorVersion());
assertEquals(21, createSdkWithTools("21 rc3").getSdkToolsMajorVersion());
assertEquals(22, createSdkWithTools("22.6").getSdkToolsMajorVersion());
}

public void testRequiresAndroidBug34233Workaround() {
assertTrue(createSdkWithTools(null).requiresAndroidBug34233Workaround());
assertFalse(createSdkWithTools("20").requiresAndroidBug34233Workaround());
assertTrue(createSdkWithTools("21").requiresAndroidBug34233Workaround());
assertTrue(createSdkWithTools("22.2.1").requiresAndroidBug34233Workaround());
assertTrue(createSdkWithTools("22.3").requiresAndroidBug34233Workaround());
assertFalse(createSdkWithTools("22.6").requiresAndroidBug34233Workaround());
}

private static AndroidSdk createSdkWithTools(String version) {
AndroidSdk sdk = null;
try {
sdk = new AndroidSdk(null, null);
sdk.setSdkToolsVersion(version);
} catch (IOException e) {
e.printStackTrace();
}
return sdk;
}

}
18 changes: 0 additions & 18 deletions src/test/java/hudson/plugins/android_emulator/util/UtilsTest.java
Expand Up @@ -9,24 +9,6 @@
@SuppressWarnings("static-method")
public class UtilsTest extends TestCase {

public void testParseRevisionString() throws Exception {
assertEquals(20, Utils.parseRevisionString("20.0.1"));
assertEquals(20, Utils.parseRevisionString("20.0"));
assertEquals(20, Utils.parseRevisionString("20"));
assertEquals(20, Utils.parseRevisionString("20.foo"));
assertEquals(21, Utils.parseRevisionString("21 rc4"));
assertEquals(21, Utils.parseRevisionString("21 rc3"));
}

public void testParseRevisionStringFailureCase() {
try {
Utils.parseRevisionString("foo");
fail("expected exception");
} catch (NumberFormatException e) {
// Expected
}
}

public void testRelativeSubdirectory() {
assertRelative("/foo/bar", "/foo/bar/baz", "baz/");
}
Expand Down

0 comments on commit b02c1cf

Please sign in to comment.