Permalink
Browse files

[FIXED JENKINS-17816] Fix detection of SDK from PATH.

  • Loading branch information...
orrc committed May 17, 2013
1 parent f67c1e2 commit dc6e2ca7eacbe4809f39cdf82b69de9510a57880
Showing with 14 additions and 16 deletions.
  1. +14 −16 src/main/java/hudson/plugins/android_emulator/util/Utils.java
@@ -303,37 +303,35 @@ public static File getHomeDirectory(String androidSdkHome) {
* @return The root directory of an Android SDK, or {@code null} if none could be determined.
*/
private static String getSdkRootFromPath(boolean isUnix) {
// Get list of required tools when working from PATH
Tool[] tools = { Tool.ADB, Tool.EMULATOR };
// List of tools which should be found together in an Android SDK tools directory
Tool[] tools = { Tool.ANDROID, Tool.EMULATOR };

// Get list of directories from the PATH environment variable
List<String> paths = Arrays.asList(System.getenv("PATH").split(File.pathSeparator));

// Examine each directory to see whether it contains Android SDK Tools
// Examine each directory to see whether it contains the expected Android tools
for (String path : paths) {
File toolsDirectory = new File(path);
if (isSdkToolsDirectory(tools, toolsDirectory, isUnix)) {
// Return the parent path (i.e. the SDK root)
return toolsDirectory.getParent();
File toolsDir = new File(path);
if (!toolsDir.exists() || !toolsDir.isDirectory()) {
continue;
}
}

return null;
}

private static boolean isSdkToolsDirectory(Tool[] tools, File toolsDir, boolean isUnix) {
int toolCount = 0;
if (toolsDir.isDirectory()) {
int toolCount = 0;
for (Tool tool : tools) {
String executable = tool.getExecutable(isUnix);
if (new File(toolsDir, executable).exists()) {
toolCount++;
}
}

// If all the tools were found in this directory, we have a winner
if (toolCount == tools.length) {
// Return the parent path (i.e. the SDK root)
return toolsDir.getParent();
}
}

// If all the tools were found in this directory, we have a winner
return (toolCount == tools.length);
return null;
}

/**

2 comments on commit dc6e2ca

@shreepawar

This comment has been minimized.

Copy link

shreepawar replied May 29, 2013

Hi,
Still observing this issue , [android] Required Android tools not found in PATH; cannot continue

Android emulator version 2.9.1 and android sdk version , android-sdk_r22.0.1. Rest everything looks fine.

@orrc

This comment has been minimized.

Copy link
Member

orrc replied May 29, 2013

Yeah, this change will be in the next plugin release, soon-ish.

Please sign in to comment.