hudson.plugins.android_emulator
Class Utils

java.lang.Object
  extended by hudson.plugins.android_emulator.Utils

public class Utils
extends java.lang.Object


Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String discoverAndroidHome(hudson.Launcher launcher, hudson.EnvVars envVars, java.lang.String androidHome)
          Tries to validate the given Android SDK root directory; otherwise tries to locate a copy of the SDK by checking for common environment variables.
static java.lang.String expandVariables(hudson.model.AbstractBuild<?,?> build, hudson.model.BuildListener listener, java.lang.String token)
          Expands the variable in the given string to its value in the environment variables available to this build.
static java.lang.String expandVariables(hudson.EnvVars envVars, java.util.Map<java.lang.String,java.lang.String> buildVars, java.lang.String token)
          Expands the variable in the given string to its value in the environment variables available to this build.
static hudson.plugins.android_emulator.AndroidSdk getAndroidSdk(hudson.Launcher launcher, java.lang.String androidHome)
          Determines the properties of the SDK installed on the build machine.
static java.lang.String getConfiguredAndroidHome()
          Retrieves the configured Android SDK root directory.
static hudson.EnvVars getEnvironment(hudson.model.AbstractBuild<?,?> build, hudson.model.BuildListener listener)
          Gets a combined set of environment variables for the current computer and build.
static hudson.util.ArgumentListBuilder getToolCommand(hudson.plugins.android_emulator.AndroidSdk androidSdk, boolean isUnix, hudson.plugins.android_emulator.Tool tool, java.lang.String args)
          Generates a ready-to-use ArgumentListBuilder for one of the Android SDK tools.
static java.util.Map<java.lang.String,java.lang.String> parseConfigFile(java.io.File configFile)
          Parses the contents of a properties file into a map.
static void runAndroidTool(hudson.Launcher launcher, java.io.OutputStream stdout, java.io.OutputStream stderr, hudson.plugins.android_emulator.AndroidSdk androidSdk, hudson.plugins.android_emulator.Tool tool, java.lang.String args, hudson.FilePath workingDirectory)
          Runs an Android tool on the remote build node and waits for completion before returning.
static ValidationResult validateAndroidHome(java.io.File sdkRoot, boolean fromWebConfig)
          Validates whether the given directory looks like a valid Android SDK directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

getConfiguredAndroidHome

public static java.lang.String getConfiguredAndroidHome()
Retrieves the configured Android SDK root directory.

Returns:
The configured Android SDK root, if any. May include un-expanded variables.

getEnvironment

public static hudson.EnvVars getEnvironment(hudson.model.AbstractBuild<?,?> build,
                                            hudson.model.BuildListener listener)
Gets a combined set of environment variables for the current computer and build.

Parameters:
build - The build for which we should retrieve environment variables.
listener - The listener used to get the environment variables.
Returns:
Environment variables for the current computer, with the build variables taking precedence.

discoverAndroidHome

public static java.lang.String discoverAndroidHome(hudson.Launcher launcher,
                                                   hudson.EnvVars envVars,
                                                   java.lang.String androidHome)
Tries to validate the given Android SDK root directory; otherwise tries to locate a copy of the SDK by checking for common environment variables.

Parameters:
launcher - The launcher for the remote node.
envVars - Environment variables for the build.
androidHome - The (variable-expanded) SDK root given in global config.
Returns:
Either a discovered SDK path or, if all else fails, the given androidHome value.

getAndroidSdk

public static hudson.plugins.android_emulator.AndroidSdk getAndroidSdk(hudson.Launcher launcher,
                                                                       java.lang.String androidHome)
Determines the properties of the SDK installed on the build machine.

Parameters:
launcher - The launcher for the remote node.
androidHome - The SDK root directory specified in the job/system configuration.
Returns:
AndroidSdk object representing the properties of the installed SDK.

validateAndroidHome

public static ValidationResult validateAndroidHome(java.io.File sdkRoot,
                                                   boolean fromWebConfig)
Validates whether the given directory looks like a valid Android SDK directory.

Parameters:
sdkRoot - The directory to validate.
fromWebConfig - Whether we are being called from the web config and should be more lax.
Returns:
Whether the SDK looks valid or not (or a warning if the SDK install is incomplete).

getToolCommand

public static hudson.util.ArgumentListBuilder getToolCommand(hudson.plugins.android_emulator.AndroidSdk androidSdk,
                                                             boolean isUnix,
                                                             hudson.plugins.android_emulator.Tool tool,
                                                             java.lang.String args)
Generates a ready-to-use ArgumentListBuilder for one of the Android SDK tools.

Parameters:
androidSdk - The Android SDK to use.
isUnix - Whether the system where this command should run is sane.
tool - The Android tool to run.
args - Any extra arguments for the command.
Returns:
Arguments including the full path to the SDK and any extra Windows stuff required.

runAndroidTool

public static void runAndroidTool(hudson.Launcher launcher,
                                  java.io.OutputStream stdout,
                                  java.io.OutputStream stderr,
                                  hudson.plugins.android_emulator.AndroidSdk androidSdk,
                                  hudson.plugins.android_emulator.Tool tool,
                                  java.lang.String args,
                                  hudson.FilePath workingDirectory)
                           throws java.io.IOException,
                                  java.lang.InterruptedException
Runs an Android tool on the remote build node and waits for completion before returning.

Parameters:
launcher - The launcher for the remote node.
stdout - The stream to which standard output should be redirected.
stderr - The stream to which standard error should be redirected.
androidSdk - The Android SDK to use.
tool - The Android tool to run.
args - Any extra arguments for the command.
workingDirectory - The directory to run the tool from, or null if irrelevant
Throws:
java.io.IOException - If execution of the tool fails.
java.lang.InterruptedException - If execution of the tool is interrupted.

parseConfigFile

public static java.util.Map<java.lang.String,java.lang.String> parseConfigFile(java.io.File configFile)
                                                                        throws java.io.IOException
Parses the contents of a properties file into a map.

Parameters:
configFile - The file to read.
Returns:
The key-value pairs contained in the file, ignoring any comments or blank lines.
Throws:
java.io.IOException - If the file could not be read.

expandVariables

public static java.lang.String expandVariables(hudson.model.AbstractBuild<?,?> build,
                                               hudson.model.BuildListener listener,
                                               java.lang.String token)
Expands the variable in the given string to its value in the environment variables available to this build. The Jenkins-specific build variables for this build are then substituted.

Parameters:
build - The build from which to get the build-specific and environment variables.
listener - The listener used to get the environment variables.
token - The token which may or may not contain variables in the format ${foo}.
Returns:
The given token, with applicable variable expansions done.

expandVariables

public static java.lang.String expandVariables(hudson.EnvVars envVars,
                                               java.util.Map<java.lang.String,java.lang.String> buildVars,
                                               java.lang.String token)
Expands the variable in the given string to its value in the environment variables available to this build. The Jenkins-specific build variables for this build are then substituted.

Parameters:
envVars - Map of the environment variables.
buildVars - Map of the build-specific variables.
token - The token which may or may not contain variables in the format ${foo}.
Returns:
The given token, with applicable variable expansions done.


Copyright © 2011. All Rights Reserved.