}
// Get configured, expanded Android SDK root value
String androidHome = Utils.expandVariables(build, listener,
Utils.getConfiguredAndroidHome());
EnvVars envVars = Utils.getEnvironment(build, listener);
// Retrieve actual SDK root based on given value
Node node = Computer.currentComputer().getNode();
String discoveredAndroidHome = Utils.discoverAndroidHome(launcher, node, envVars,
androidHome);
// Get Android SDK object from the given root (or locate on PATH)
final String androidSdkHome = (envVars != null && keepInWorkspace ? envVars
.get("WORKSPACE") : null);
AndroidSdk androidSdk = Utils
.getAndroidSdk(launcher, discoveredAndroidHome, androidSdkHome);
// Check whether we should install the SDK
if (androidSdk == null) {
PrintStream logger = listener.getLogger();
if (!shouldInstallSdk) {
// Couldn't find an SDK, don't want to install it, give up
log(logger, Messages.SDK_TOOLS_NOT_FOUND());
return null;
}
// Ok, let's download and install the SDK
log(logger, Messages.INSTALLING_SDK());
try {
androidSdk = SdkInstaller.install(launcher, listener, null);
} catch (SdkInstallationException e) {
log(logger, Messages.SDK_INSTALLATION_FAILED(), e);
return null;
}
// Check whether anything went wrong
if (androidSdk == null) {
log(logger, Messages.SDK_INSTALLATION_FAILED());
return null;
}
}
// Export environment variables
final String sdkRoot = androidSdk.getSdkRoot();
build.addAction(new EnvironmentContributingAction() {
public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars envVars) {
if (envVars != null) {
envVars.put("ANDROID_HOME", sdkRoot);
}
}
public String getUrlName() {
return null;