diff options
author | David Herman <davidherman@google.com> | 2014-10-17 15:57:22 -0700 |
---|---|---|
committer | David Herman <davidherman@google.com> | 2014-10-23 11:44:12 -0700 |
commit | 8ebbf9d423fe3fdbbf57d972dd3a88160ccee823 (patch) | |
tree | 2121a7aa470a3d3c758c1eeb078adb9ffc2467b0 /find_java/src/source/find_java_lib.cpp | |
parent | 1b9e6f635463f50548ef24e83ba73c8efd6b6fb3 (diff) | |
download | sdk-8ebbf9d423fe3fdbbf57d972dd3a88160ccee823.zip sdk-8ebbf9d423fe3fdbbf57d972dd3a88160ccee823.tar.gz sdk-8ebbf9d423fe3fdbbf57d972dd3a88160ccee823.tar.bz2 |
Added new -minv (version) option to find_java
find_java historically checks for v1.6, which is defined by a
constant in find_java.h, and simply bumping the value up may
cause problems with existing tools. Therefore, I've added an
argument that takes an input minimum version to look for.
Change-Id: I901dbf3621a262b3e8ee5a42ce9e46ce49126363
Diffstat (limited to 'find_java/src/source/find_java_lib.cpp')
-rwxr-xr-x | find_java/src/source/find_java_lib.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/find_java/src/source/find_java_lib.cpp b/find_java/src/source/find_java_lib.cpp index bf69546..93bc705 100755 --- a/find_java/src/source/find_java_lib.cpp +++ b/find_java/src/source/find_java_lib.cpp @@ -124,13 +124,13 @@ static int checkBinPath(CPath *inOutPath) { }
// Test for the existence of java.exe in a custom path
-int checkJavaInPath(const CPath &path) {
+int checkJavaInPath(const CPath &path, int minVersion) {
SetLastError(0);
int currVersion = 0;
CPath temp(path);
currVersion = checkBinPath(&temp);
- if (currVersion > 0) {
+ if (currVersion > minVersion) {
if (gIsDebug) {
fprintf(stderr, "Java %d found in path: %s\n", currVersion, temp.cstr());
}
@@ -140,7 +140,7 @@ int checkJavaInPath(const CPath &path) { }
// Search java.exe in the environment
-int findJavaInEnvPath(CPath *outJavaPath, bool isJdk) {
+int findJavaInEnvPath(CPath *outJavaPath, bool isJdk, int minVersion) {
SetLastError(0);
int currVersion = 0;
@@ -157,7 +157,7 @@ int findJavaInEnvPath(CPath *outJavaPath, bool isJdk) { }
*outJavaPath = p;
}
- if (currVersion >= MIN_JAVA_VERSION) {
+ if (currVersion >= minVersion) {
// As an optimization for runtime, if we find a suitable java
// version in JAVA_HOME we won't waste time looking at the PATH.
return currVersion;
@@ -180,7 +180,7 @@ int findJavaInEnvPath(CPath *outJavaPath, bool isJdk) { }
int v = checkPath(&p);
- if (v > currVersion) {
+ if (v >= minVersion && v > currVersion) {
if (gIsDebug) {
fprintf(stderr, "Java %d found via env PATH: %s\n", v, p.cstr());
}
@@ -245,7 +245,8 @@ static bool getRegValue(const char *keyPath, // Returns an int which is the version of Java found (e.g. 1006 for 1.6) and the
// matching path in outJavaPath.
// Returns 0 if nothing suitable was found.
-static int exploreJavaRegistry(const char *entry, REGSAM access, CPath *outJavaPath) {
+static int exploreJavaRegistry(const char *entry, REGSAM access, int minVersion,
+ CPath *outJavaPath) {
// Let's visit HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment [CurrentVersion]
CPath rootKey("SOFTWARE\\JavaSoft\\");
@@ -269,7 +270,7 @@ static int exploreJavaRegistry(const char *entry, REGSAM access, CPath *outJavaP }
*outJavaPath = javaHome;
}
- if (versionInt >= MIN_JAVA_VERSION) {
+ if (versionInt >= minVersion) {
// Heuristic: if the current version is good enough, stop here
return versionInt;
}
@@ -328,7 +329,7 @@ static int exploreJavaRegistry(const char *entry, REGSAM access, CPath *outJavaP static bool getMaxJavaInRegistry(const char *entry, REGSAM access, CPath *outJavaPath, int *inOutVersion) {
CPath path;
- int version = exploreJavaRegistry(entry, access, &path);
+ int version = exploreJavaRegistry(entry, access, *inOutVersion, &path);
if (version > *inOutVersion) {
*outJavaPath = path;
*inOutVersion = version;
@@ -337,9 +338,9 @@ static bool getMaxJavaInRegistry(const char *entry, REGSAM access, CPath *outJav return false;
}
-int findJavaInRegistry(CPath *outJavaPath, bool isJdk) {
+int findJavaInRegistry(CPath *outJavaPath, bool isJdk, int minVersion) {
// Check the JRE first, then the JDK.
- int version = MIN_JAVA_VERSION - 1;
+ int version = minVersion - 1; // Inner methods check if they're greater than this version.
bool result = false;
result |= (!isJdk && getMaxJavaInRegistry("Java Runtime Environment", 0, outJavaPath, &version));
result |= getMaxJavaInRegistry("Java Development Kit", 0, outJavaPath, &version);
@@ -403,11 +404,11 @@ static bool checkProgramFiles(CPath *outJavaPath, int *inOutVersion, bool isJdk, return found;
}
-int findJavaInProgramFiles(CPath *outJavaPath, bool isJdk) {
+int findJavaInProgramFiles(CPath *outJavaPath, bool isJdk, int minVersion) {
// Check the C:\Program Files directory
bool result = false;
- int version = MIN_JAVA_VERSION - 1;
+ int version = minVersion - 1; // Inner methods check if they're greater than this version.
result |= checkProgramFiles(outJavaPath, &version, isJdk, false);
// Even if we're 64-bit, try again but check the C:\Program Files (x86) directory, looking for
@@ -421,7 +422,6 @@ int findJavaInProgramFiles(CPath *outJavaPath, bool isJdk) { // --------------
-
// Tries to invoke the java.exe at the given path and extract it's
// version number.
// - outVersionStr: if not null, will capture version as a string (e.g. "1.6")
|