Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<artifactId>android-emulator</artifactId>
<packaging>hpi</packaging>
<version>2.16-SNAPSHOT</version>
<version>10.0-SNAPSHOT</version>
<name>Android Emulator Plugin</name>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin</url>
<developers>
Expand Down
214 changes: 49 additions & 165 deletions src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public AndroidEmulatorContext(AbstractBuild<?, ?> build_,
// ADB servers will race to register with each emulator, meaning that each build will most
// likely end up with an emulator that always ends up appearing to be "offline".
// See http://b.android.com/205197
final int PORT_RANGE_START = 5554 + (2 * 64);
final int PORT_RANGE_END = PORT_RANGE_START + (2 * 64);
final int PORT_RANGE_START = 5554;
final int PORT_RANGE_END = 5586;

// When using the emulator `-port` option, the first port must be even, so here we reserve
// three consecutive ports, ensuring that we will get an even port followed by an odd
Expand Down Expand Up @@ -147,7 +147,12 @@ public ProcStarter getProcStarter() throws IOException, InterruptedException {
buildEnvironment.put("ANDROID_SDK_HOME", sdk.getSdkHome());
}
if (launcher.isUnix()) {
buildEnvironment.put("LD_LIBRARY_PATH", String.format("%s/tools/lib", sdk.getSdkRoot()));
StringBuilder libPath = new StringBuilder();
libPath.append(String.format("%s/emulator/lib64:", sdk.getSdkRoot()));
libPath.append(String.format("%s/emulator/lib64/qt/lib:", sdk.getSdkRoot()));
libPath.append(String.format("%s/emulator/lib64/libstdc++:", sdk.getSdkRoot()));
libPath.append(String.format("%s/tools/lib:", sdk.getSdkRoot()));
buildEnvironment.put("LD_LIBRARY_PATH", libPath.toString());
}
return launcher.launch().stdout(new NullStream()).stderr(logger()).envs(buildEnvironment);
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/hudson/plugins/android_emulator/AvdDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package hudson.plugins.android_emulator;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public enum AvdDevice implements Serializable {
NEXUS_7_W_SKIN(AvdDeviceSpecs.NEXUS_7_SPECS, AvdDeviceSpecs.NEXUS_7_SKIN_NAME),
NEXUS_7(AvdDeviceSpecs.NEXUS_7_SPECS, null);

private final String specs;
private final String skin;

private AvdDevice(String avdDeviceSpecs, String skinName) {
specs = avdDeviceSpecs;
skin = skinName;
}

public Map<String, String> getDeviceSpecs() {
Map<String, String> specMap = new HashMap<String, String>();

if (specs != null) {

StringTokenizer tokenizeList = new StringTokenizer(specs, AvdDeviceSpecs.DELEMIN);

while (tokenizeList.hasMoreTokens()) {
String keyValue = tokenizeList.nextToken();
String parts[] = keyValue.split("=");
if (parts.length != 2) {
continue;
}
specMap.put(parts[0], parts[1]);
}
}

if (skin != null) {
specMap.put("skin.dynamic", "yes");
specMap.put("skin.name", skin);
String skinPath = "/skins/" + skin;
specMap.put("skin.path", skinPath);
}

return specMap;

}

}
19 changes: 19 additions & 0 deletions src/main/java/hudson/plugins/android_emulator/AvdDeviceSpecs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hudson.plugins.android_emulator;

import java.io.Serializable;

public class AvdDeviceSpecs implements Serializable {

private static final long serialVersionUID = -7211323867009992722L;

public static final String DELEMIN = ";";

public static final String NEXUS_7_SPECS = "hw.device.manufacturer=Google;"
+ "hw.device.name=Nexus 7 2013" + DELEMIN
+ "hw.lcd.density=320" + DELEMIN
+ "showDeviceFrame=yes" + DELEMIN;

public static final String NEXUS_7_SKIN_NAME = "nexus_7_2013";


}
188 changes: 9 additions & 179 deletions src/main/java/hudson/plugins/android_emulator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface Constants {

}


enum SnapshotState {
NONE,
INITIALISE,
Expand All @@ -58,7 +59,7 @@ enum SnapshotState {

class AndroidPlatform implements Serializable {

private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 4L;

static final AndroidPlatform SDK_1_1 = new AndroidPlatform("1.1", 2);
static final AndroidPlatform SDK_1_5 = new AndroidPlatform("1.5", 3);
Expand All @@ -82,9 +83,15 @@ class AndroidPlatform implements Serializable {
static final AndroidPlatform SDK_5_0 = new AndroidPlatform("5.0", 21);
static final AndroidPlatform SDK_5_1 = new AndroidPlatform("5.1", 22);
static final AndroidPlatform SDK_6_0 = new AndroidPlatform("6.0", 23);
static final AndroidPlatform SDK_7_0 = new AndroidPlatform("7.0", 24);
static final AndroidPlatform SDK_7_1 = new AndroidPlatform("7.1", 25);
static final AndroidPlatform SDK_8_0 = new AndroidPlatform("8.0", 26);
static final AndroidPlatform SDK_8_1 = new AndroidPlatform("8.1", 27);
static final AndroidPlatform SDK_9_0 = new AndroidPlatform("9.0", 28);
static final AndroidPlatform[] ALL = new AndroidPlatform[] { SDK_1_1, SDK_1_5, SDK_1_6, SDK_2_0,
SDK_2_0_1, SDK_2_1, SDK_2_2, SDK_2_3, SDK_2_3_3, SDK_3_0, SDK_3_1, SDK_3_2, SDK_4_0,
SDK_4_0_3, SDK_4_1, SDK_4_2, SDK_4_3, SDK_4_4, SDK_4_4W, SDK_5_0, SDK_5_1, SDK_6_0 };
SDK_4_0_3, SDK_4_1, SDK_4_2, SDK_4_3, SDK_4_4, SDK_4_4W, SDK_5_0, SDK_5_1, SDK_6_0, SDK_7_0, SDK_7_1,
SDK_8_0, SDK_8_1, SDK_9_0 };

private final String name;
private final int level;
Expand Down Expand Up @@ -122,19 +129,6 @@ public boolean isCustomPlatform() {
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 logic should ideally be moved to emulator creation time...
// 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..
// But, since the Intel x86 for SDK 10 is now hosted by Google, we can't rely on the name...
return level == 10 || level >= 15
|| Util.fixNull(name).contains("Intel Atom x86 System Image");
}

public String getTargetName() {
if (isCustomPlatform()) {
return name;
Expand All @@ -154,168 +148,4 @@ public String toString() {

}

class ScreenDensity implements Serializable {

private static final long serialVersionUID = 1L;

static final ScreenDensity LOW = new ScreenDensity(120, "ldpi");
static final ScreenDensity MEDIUM = new ScreenDensity(160, "mdpi");
static final ScreenDensity TV_720P = new ScreenDensity(213, "tvdpi");
static final ScreenDensity HIGH = new ScreenDensity(240, "hdpi");
static final ScreenDensity EXTRA_HIGH = new ScreenDensity(320, "xhdpi");
static final ScreenDensity EXTRA_HIGH_400 = new ScreenDensity(400);
static final ScreenDensity EXTRA_HIGH_420 = new ScreenDensity(420);
static final ScreenDensity EXTRA_EXTRA_HIGH = new ScreenDensity(480, "xxhdpi");
static final ScreenDensity EXTRA_EXTRA_HIGH_560 = new ScreenDensity(560);
static final ScreenDensity EXTRA_EXTRA_EXTRA_HIGH = new ScreenDensity(640, "xxxhdpi");
static final ScreenDensity[] PRESETS = new ScreenDensity[] { LOW, MEDIUM, TV_720P, HIGH,
EXTRA_HIGH, EXTRA_HIGH_400, EXTRA_HIGH_420, EXTRA_EXTRA_HIGH, EXTRA_EXTRA_HIGH_560,
EXTRA_EXTRA_EXTRA_HIGH };

private final int dpi;
private final String alias;

private ScreenDensity(int dpi, String alias) {
this.dpi = dpi;
this.alias = alias;
}

private ScreenDensity(int density) {
this(density, null);
}

public static ScreenDensity valueOf(String density) {
if (Util.fixEmptyAndTrim(density) == null) {
return null;
} else {
density = density.toLowerCase();
}

for (ScreenDensity preset : PRESETS) {
if (density.equals(preset.alias) || density.equals(preset.toString())) {
return preset;
}
}

// Return custom value, if things look valid
try {
int dpi = Integer.parseInt(density);
return new ScreenDensity(dpi);
} catch (NumberFormatException ex) {
return null;
}
}

public boolean isCustomDensity() {
return alias == null;
}

public int getDpi() {
return dpi;
}

@Override
public String toString() {
return Integer.toString(dpi);
};

}

class ScreenResolution implements Serializable {

private static final long serialVersionUID = 1L;

static final ScreenResolution QVGA = new ScreenResolution(240, 320, "QVGA", "QVGA");
static final ScreenResolution WQVGA = new ScreenResolution(240, 400, "WQVGA", "WQVGA400");
static final ScreenResolution FWQVGA = new ScreenResolution(240, 432, "FWQVGA", "WQVGA432");
static final ScreenResolution HVGA = new ScreenResolution(320, 480, "HVGA", "HVGA");
static final ScreenResolution WVGA = new ScreenResolution(480, 800, "WVGA", "WVGA800");
static final ScreenResolution FWVGA = new ScreenResolution(480, 854, "FWVGA", "WVGA854");
static final ScreenResolution WSVGA = new ScreenResolution(1024, 654, "WSVGA", "WSVGA");
static final ScreenResolution WXGA_720 = new ScreenResolution(1280, 720, "WXGA720", "WXGA720");
static final ScreenResolution WXGA_800 = new ScreenResolution(1280, 800, "WXGA800", "WXGA800");
static final ScreenResolution WXGA = new ScreenResolution(1280, 800, "WXGA", "WXGA");
static final ScreenResolution[] PRESETS = new ScreenResolution[] { QVGA, WQVGA, FWQVGA, HVGA,
WVGA, FWVGA, WSVGA,
WXGA_720, WXGA_800, WXGA };

private final int width;
private final int height;
private final String alias;
private final String skinName;

private ScreenResolution(int width, int height, String alias, String skinName) {
this.width = width;
this.height = height;
this.alias = alias;
this.skinName = skinName;
}

private ScreenResolution(int width, int height) {
this(width, height, null, null);
}

public static ScreenResolution valueOf(String resolution) {
if (Util.fixEmptyAndTrim(resolution) == null) {
return null;
}

// Try matching against aliases
for (ScreenResolution preset : PRESETS) {
if (resolution.equalsIgnoreCase(preset.alias)) {
return preset;
}
}

// Check for pixel values
resolution = resolution.toLowerCase();
if (!resolution.matches(Constants.REGEX_SCREEN_RESOLUTION)) {
return null;
}

// Try matching against pixel values
int index = resolution.indexOf('x');
int width = 0;
int height = 0;
try {
width = Integer.parseInt(resolution.substring(0, index));
height = Integer.parseInt(resolution.substring(index+1));
} catch (NumberFormatException ex) {
return null;
}
for (ScreenResolution preset : PRESETS) {
if (width == preset.width && height == preset.height) {
return preset;
}
}

// Return custom value
return new ScreenResolution(width, height);
}

public boolean isCustomResolution() {
return alias == null;
}

public String getSkinName() {
if (isCustomResolution()) {
return getDimensionString();
}

return skinName;
}

public String getDimensionString() {
return width +"x"+ height;
}

@Override
public String toString() {
if (isCustomResolution()) {
return getDimensionString();
}

return alias;
};

}
Loading