Skip to content

Commit

Permalink
[FIXED JENKINS-17816] Fix detection of SDK from PATH.
Browse files Browse the repository at this point in the history
  • Loading branch information
orrc committed May 17, 2013
1 parent f67c1e2 commit dc6e2ca
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/main/java/hudson/plugins/android_emulator/util/Utils.java
Expand Up @@ -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;
}

/**
Expand Down

2 comments on commit dc6e2ca

@shreepawar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@orrc orrc commented on dc6e2ca May 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.