Skip to content
Permalink
Browse files

[FIXED JENKINS-14741] Ignore configured ABI when creating emulators w…

…hich don't support ABIs.
  • Loading branch information...
orrc committed Feb 24, 2013
1 parent 4da9495 commit e8c62cf6cf405d85a84879767a92ee3a09241472
@@ -1,6 +1,7 @@
package hudson.plugins.android_emulator;

import hudson.Util;
import hudson.plugins.android_emulator.util.Utils;

import java.io.Serializable;

@@ -85,9 +86,14 @@

private final String name;
private final int level;
private final boolean isAddon;

private AndroidPlatform(String name, int level) {
this.name = name;
this.isAddon = level <= 0;
if (isAddon) {
level = Utils.getApiLevelFromPlatform(name);
}
this.level = level;
}

@@ -111,7 +117,18 @@ public static AndroidPlatform valueOf(String version) {
}

public boolean isCustomPlatform() {
return level == -1;
return isAddon;
}

/**
* @return {@code true} if this platform requires an ABI to be explicitly specified during
* emulator creation.
*/
public boolean requiresAbi() {
// TODO: Could be improved...
// This is a relatively naive approach; e.g. addons for level <= 13 can have ABIs, though
// the only example seen so far is the Intel x86 level 10 image we explicitly include here..
return level >= 14 || Util.fixNull(name).contains("Intel Atom x86 System Image");
}

public String getTargetName() {
@@ -122,18 +139,14 @@ public String getTargetName() {
return "android-"+ level;
}

public String getOldTargetName() {
return "android-"+ name;
}

public int getSdkLevel() {
return level;
}

@Override
public String toString() {
return name;
};
}

}

@@ -153,7 +153,7 @@ private String getGeneratedAvdName() {
String resolution = screenResolution.toString();
String platform = osVersion.getTargetName().replace(':', '_').replace(' ', '_');
String abi = "";
if (Util.fixEmptyAndTrim(targetAbi) != null) {
if (Util.fixEmptyAndTrim(targetAbi) != null && osVersion.requiresAbi()) {
abi = "_" + targetAbi.replace(' ', '-');
}
return String.format("hudson_%s_%s_%s_%s%s", locale, density, resolution, platform, abi);
@@ -501,7 +501,7 @@ public Boolean call() throws AndroidEmulatorException {
builder.add("-t");
builder.add(osVersion.getTargetName());

if (targetAbi != null) {
if (targetAbi != null && osVersion.requiresAbi()) {
builder.add("--abi");
builder.add(targetAbi);
}
@@ -32,8 +32,6 @@
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.Semaphore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

@@ -264,18 +262,8 @@ private static boolean isPlatformInstalled(PrintStream logger, Launcher launcher
// Gather list of required components
List<String> components = new ArrayList<String>();

// Check for dependent platform
int dependentPlatform = -1;
Matcher matcher = Pattern.compile("[0-9]{1,2}$").matcher(platform);
if (matcher.find()) {
String end = matcher.group();
try {
dependentPlatform = Integer.parseInt(end);
} catch (NumberFormatException e) {
}
}

// Add dependent platform
int dependentPlatform = Utils.getApiLevelFromPlatform(platform);
if (dependentPlatform > 0) {
components.add(String.format("android-%s", dependentPlatform));
}
@@ -667,6 +667,30 @@ public static int parseRevisionString(String revisionStr) {
}
}

/**
* Determines the API level for the given platform name.
*
* @param platform String like "android-4" or "Google:Google APIs:14".
* @return The detected version, or {@code -1} if not determined.
*/
public static int getApiLevelFromPlatform(String platform) {
int apiLevel = -1;
platform = Util.fixEmptyAndTrim(platform);
if (platform == null) {
return apiLevel;
}

Matcher matcher = Pattern.compile("[-:]([0-9]{1,2})$").matcher(platform);
if (matcher.find()) {
String end = matcher.group(1);
try {
apiLevel = Integer.parseInt(end);
} catch (NumberFormatException e) {
}
}
return apiLevel;
}

/** Task that will execute a command on the given emulator's console port, then quit. */
private static final class EmulatorCommandTask implements Callable<Boolean, IOException> {

@@ -0,0 +1,49 @@
package hudson.plugins.android_emulator;

import junit.framework.TestCase;

public class AndroidPlatformTest extends TestCase {

public void testCreateKnownPlatform() {
assertEquals(AndroidPlatform.SDK_1_6, AndroidPlatform.valueOf("1.6"));
assertEquals(AndroidPlatform.SDK_1_6, AndroidPlatform.valueOf("4"));
assertEquals(AndroidPlatform.SDK_1_6, AndroidPlatform.valueOf("android-4"));
}

public void testCreateAddonPlatform() {
final String name = "Some:Addon:11";
AndroidPlatform platform = AndroidPlatform.valueOf(name);
assertEquals(name, platform.getTargetName());
}

public void testCreateInvalidPlatform() {
assertNull(AndroidPlatform.valueOf(null));

final String name = "iOS 6.1";
AndroidPlatform platform = AndroidPlatform.valueOf(name);
assertEquals(name, platform.getTargetName());
assertEquals(-1, platform.getSdkLevel());
}

public void testGetSdkLevel() {
assertEquals(9, AndroidPlatform.SDK_2_3.getSdkLevel());
assertEquals(10, AndroidPlatform.valueOf("2.3.3").getSdkLevel());
assertEquals(11, AndroidPlatform.valueOf("Some:Addon:11").getSdkLevel());
}

public void testIsCustomPlatform() {
assertFalse(AndroidPlatform.SDK_2_3.isCustomPlatform());
assertTrue(AndroidPlatform.valueOf("Some:Addon:12").isCustomPlatform());
}

public void testRequiresAbi() {
assertFalse(AndroidPlatform.SDK_1_1.requiresAbi());
assertFalse(AndroidPlatform.SDK_2_3_3.requiresAbi());
assertFalse(AndroidPlatform.SDK_3_2.requiresAbi());
assertTrue(AndroidPlatform.SDK_4_0.requiresAbi());
assertTrue(AndroidPlatform.SDK_4_2.requiresAbi());
assertTrue(AndroidPlatform.valueOf("android-99").requiresAbi());
assertTrue(AndroidPlatform.valueOf("Intel Atom x86 System Image").requiresAbi());
}

}
@@ -3,14 +3,14 @@
import junit.framework.TestCase;

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() throws Exception {
@@ -65,4 +65,14 @@ private static void assertRelative(String from, String to, String expectedResult
assertEquals(expectedResult, Utils.getRelativePath(from, to));
}

public void testGetApiLevelFromPlatform() {
assertEquals(4, Utils.getApiLevelFromPlatform("android-4"));
assertEquals(16, Utils.getApiLevelFromPlatform("android-16"));
assertEquals(16, Utils.getApiLevelFromPlatform("Google Inc.:Google APIs:16"));
assertEquals(-1, Utils.getApiLevelFromPlatform(null));
assertEquals(-1, Utils.getApiLevelFromPlatform(""));
assertEquals(-1, Utils.getApiLevelFromPlatform("jellybean"));
assertEquals(-1, Utils.getApiLevelFromPlatform("Android 4.2"));
}

}

0 comments on commit e8c62cf

Please sign in to comment.
You can’t perform that action at this time.