Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList
// Ok, let's download and install the SDK
log(logger, Messages.INSTALLING_SDK());
try {
androidSdk = SdkInstaller.install(launcher, listener, androidSdkHome);
androidSdk = SdkInstaller.install(build, launcher, listener, androidSdkHome);
} catch (SdkInstallationException e) {
log(logger, Messages.SDK_INSTALLATION_FAILED(), e);
build.setResult(Result.NOT_BUILT);
Expand All @@ -253,7 +253,7 @@ public Environment setUp(AbstractBuild build, final Launcher launcher, BuildList

// Install the required SDK components for the desired platform, if necessary
if (descriptor.shouldInstallSdk) {
SdkInstaller.installDependencies(logger, launcher, androidSdk, emuConfig);
SdkInstaller.installDependencies(logger, build, launcher, androidSdk, emuConfig);
}

// Ok, everything looks good.. let's go
Expand All @@ -272,7 +272,7 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
// First ensure that emulator exists
final boolean emulatorAlreadyExists;
try {
Callable<Boolean, AndroidEmulatorException> task = emuConfig.getEmulatorCreationTask(androidSdk, listener);
Callable<Boolean, AndroidEmulatorException> task = emuConfig.getEmulatorCreationTask(build, androidSdk, listener);
emulatorAlreadyExists = launcher.getChannel().call(task);
} catch (EmulatorDiscoveryException ex) {
log(logger, Messages.CANNOT_START_EMULATOR(ex.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package hudson.plugins.android_emulator;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.TaskListener;
import hudson.plugins.android_emulator.AndroidEmulator.HardwareProperty;
Expand Down Expand Up @@ -229,9 +231,9 @@ public Tool getExecutable() {
* @param listener The listener to use for logging.
* @return A Callable that will handle the detection/creation of an appropriate AVD.
*/
public Callable<Boolean, AndroidEmulatorException> getEmulatorCreationTask(AndroidSdk androidSdk,
BuildListener listener) {
return new EmulatorCreationTask(androidSdk, listener);
public Callable<Boolean, AndroidEmulatorException> getEmulatorCreationTask(AbstractBuild<?, ?> build, AndroidSdk androidSdk,
BuildListener listener) throws IOException, InterruptedException{
return new EmulatorCreationTask(build.getEnvironment(listener), androidSdk, listener);
}

/**
Expand Down Expand Up @@ -373,12 +375,14 @@ public boolean hasExistingSnapshot(Launcher launcher, AndroidSdk androidSdk)
private final class EmulatorCreationTask implements Callable<Boolean, AndroidEmulatorException> {

private static final long serialVersionUID = 1L;
private final EnvVars env;
private final AndroidSdk androidSdk;

private final BuildListener listener;
private transient PrintStream logger;

public EmulatorCreationTask(AndroidSdk androidSdk, BuildListener listener) {
public EmulatorCreationTask(EnvVars env, AndroidSdk androidSdk, BuildListener listener) {
this.env = env;
this.androidSdk = androidSdk;
this.listener = listener;
}
Expand Down Expand Up @@ -528,6 +532,9 @@ public Boolean call() throws AndroidEmulatorException {
final Process process;
try {
ProcessBuilder procBuilder = new ProcessBuilder(builder.toList());
if (env != null) {
procBuilder.environment().putAll(env);
}
if (androidSdk.hasKnownHome()) {
procBuilder.environment().put("ANDROID_SDK_HOME", androidSdk.getSdkHome());
}
Expand Down
41 changes: 22 additions & 19 deletions src/main/java/hudson/plugins/android_emulator/SdkInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Proc;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.plugins.android_emulator.SdkInstaller.AndroidInstaller.SdkUnavailableException;
import hudson.plugins.android_emulator.sdk.AndroidSdk;
import hudson.plugins.android_emulator.sdk.Tool;
Expand Down Expand Up @@ -59,17 +61,17 @@ public class SdkInstaller {
*
* @return An {@code AndroidSdk} object for the newly-installed SDK.
*/
public static AndroidSdk install(Launcher launcher, BuildListener listener, String androidSdkHome)
public static AndroidSdk install(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, String androidSdkHome)
throws SdkInstallationException, IOException, InterruptedException {
Semaphore semaphore = acquireLock();
try {
return doInstall(launcher, listener, androidSdkHome);
return doInstall(build, launcher, listener, androidSdkHome);
} finally {
semaphore.release();
}
}

private static AndroidSdk doInstall(Launcher launcher, BuildListener listener, String androidSdkHome)
private static AndroidSdk doInstall(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, String androidSdkHome)
throws SdkInstallationException, IOException, InterruptedException {
// We should install the SDK on the current build machine
Node node = Computer.currentComputer().getNode();
Expand All @@ -91,12 +93,12 @@ private static AndroidSdk doInstall(Launcher launcher, BuildListener listener, S
AndroidSdk sdk = getAndroidSdkForNode(node, androidHome, androidSdkHome);

// Get the latest platform-tools
installComponent(logger, launcher, sdk, "platform-tool");
installComponent(logger, build, launcher, sdk, "platform-tool");

// Upgrade the tools if necessary and add the latest build-tools component
List<String> components = new ArrayList<String>(4);
components.add("tool");
String buildTools = getBuildToolsPackageName(logger, launcher, sdk);
String buildTools = getBuildToolsPackageName(logger, build, launcher, sdk);
if (buildTools != null) {
components.add(buildTools);
}
Expand All @@ -106,7 +108,7 @@ private static AndroidSdk doInstall(Launcher launcher, BuildListener listener, S
components.add("extra-google-m2repository");

// Install the lot
installComponent(logger, launcher, sdk, components.toArray(new String[0]));
installComponent(logger, build, launcher, sdk, components.toArray(new String[0]));

// If we made it this far, confirm completion by writing our our metadata file
getInstallationInfoFilename(node).write(SDK_VERSION, "UTF-8");
Expand All @@ -130,10 +132,10 @@ public AndroidSdk call() throws IOException {
});
}

private static String getBuildToolsPackageName(PrintStream logger, Launcher launcher, AndroidSdk sdk)
private static String getBuildToolsPackageName(PrintStream logger, AbstractBuild<?,?> build, Launcher launcher, AndroidSdk sdk)
throws IOException, InterruptedException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Utils.runAndroidTool(launcher, output, logger, sdk, Tool.ANDROID, "list sdk --extended", null);
Utils.runAndroidTool(launcher, build.getEnvironment(TaskListener.NULL), output, logger, sdk, Tool.ANDROID, "list sdk --extended", null);
Matcher m = Pattern.compile("\"(build-tools-.*?)\"").matcher(output.toString());
if (!m.find()) {
return null;
Expand Down Expand Up @@ -192,7 +194,7 @@ public Boolean invoke(File f, VirtualChannel channel)
* @param sdk Root of the SDK installation to install components for.
* @param components Name of the component(s) to install.
*/
private static void installComponent(PrintStream logger, Launcher launcher, AndroidSdk sdk,
private static void installComponent(PrintStream logger, AbstractBuild<?, ?> build, Launcher launcher, AndroidSdk sdk,
String... components) throws IOException, InterruptedException {
String proxySettings = getProxySettings();

Expand All @@ -203,11 +205,12 @@ private static void installComponent(PrintStream logger, Launcher launcher, Andr
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);
EnvVars env = new EnvVars();
env.putAll(build.getEnvironment(TaskListener.NULL));
if (sdk.hasKnownHome()) {
EnvVars env = new EnvVars();
env.put("ANDROID_SDK_HOME", sdk.getSdkHome());
procStarter = procStarter.envs(env);
}
procStarter = procStarter.envs(env);

// Run the command and accept any licence requests during installation
Proc proc = procStarter.start();
Expand All @@ -230,15 +233,15 @@ private static void installComponent(PrintStream logger, Launcher launcher, Andr
* @param sdk SDK installation to install components for.
* @param emuConfig Specifies the platform to be installed.
*/
static void installDependencies(PrintStream logger, Launcher launcher,
static void installDependencies(PrintStream logger, AbstractBuild<?, ?> build, Launcher launcher,
AndroidSdk sdk, EmulatorConfig emuConfig) throws IOException, InterruptedException {
// Get AVD platform from emulator config
String platform = getPlatformForEmulator(launcher, emuConfig);

// Install platform and any dependencies it may have
boolean requiresAbi = !emuConfig.isNamedEmulator() && emuConfig.getOsVersion().requiresAbi();
String abi = requiresAbi ? emuConfig.getTargetAbi() : null;
installPlatform(logger, launcher, sdk, platform, abi);
installPlatform(logger, build, launcher, sdk, platform, abi);
}

/**
Expand All @@ -250,10 +253,10 @@ static void installDependencies(PrintStream logger, Launcher launcher,
* @param platform Specifies the platform to be installed.
* @param abi Specifies the ABI to be installed; may be {@code null}.
*/
public static void installPlatform(PrintStream logger, Launcher launcher, AndroidSdk sdk,
public static void installPlatform(PrintStream logger, AbstractBuild<?, ?> build, Launcher launcher, AndroidSdk sdk,
String platform, String abi) throws IOException, InterruptedException {
// Check whether this platform is already installed
if (isPlatformInstalled(logger, launcher, sdk, platform, abi)) {
if (isPlatformInstalled(logger, build, launcher, sdk, platform, abi)) {
return;
}

Expand Down Expand Up @@ -287,7 +290,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, null)) {
if (isPlatformInstalled(logger, build, launcher, sdk, component, null)) {
it.remove();
}
}
Expand All @@ -296,18 +299,18 @@ public static void installPlatform(PrintStream logger, Launcher launcher, Androi
// Grab the lock and attempt installation
Semaphore semaphore = acquireLock();
try {
installComponent(logger, launcher, sdk, components.toArray(new String[0]));
installComponent(logger, build, launcher, sdk, components.toArray(new String[0]));
} finally {
semaphore.release();
}
}

private static boolean isPlatformInstalled(PrintStream logger, Launcher launcher,
private static boolean isPlatformInstalled(PrintStream logger, AbstractBuild<?, ?> build, Launcher launcher,
AndroidSdk sdk, String platform, String abi) throws IOException, InterruptedException {
ByteArrayOutputStream targetList = new ByteArrayOutputStream();
// 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);
Utils.runAndroidTool(launcher, build.getEnvironment(TaskListener.NULL), targetList, logger, sdk, Tool.ANDROID, "list target", null);
boolean platformInstalled = targetList.toString().contains('"'+ platform +'"');
if (!platformInstalled) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected static AndroidSdk getAndroidSdk(AbstractBuild<?, ?> build, Launcher la
// Ok, let's download and install the SDK
log(logger, Messages.INSTALLING_SDK());
try {
androidSdk = SdkInstaller.install(launcher, listener, null);
androidSdk = SdkInstaller.install(build, launcher, listener, null);
} catch (SdkInstallationException e) {
log(logger, Messages.SDK_INSTALLATION_FAILED(), e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
// Install platform(s)
log(logger, Messages.ENSURING_PLATFORMS_INSTALLED(platforms));
for (String platform : platforms) {
SdkInstaller.installPlatform(logger, launcher, androidSdk, platform, null);
SdkInstaller.installPlatform(logger, build, launcher, androidSdk, platform, null);
}

// Done!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.TaskListener;
import hudson.model.AbstractBuild;
import hudson.plugins.android_emulator.Messages;
import hudson.plugins.android_emulator.sdk.AndroidSdk;
Expand Down Expand Up @@ -152,7 +153,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
shortPath = project.path.substring(workspace.length() + 1);
}
log(logger, Messages.CREATING_BUILD_FILES(project.type.name.toString(), shortPath));
Utils.runAndroidTool(launcher, logger, logger, androidSdk, Tool.ANDROID, args, dir);
Utils.runAndroidTool(launcher, build.getEnvironment(TaskListener.NULL), logger, logger, androidSdk, Tool.ANDROID, args, dir);
}

// Done!
Expand Down