aboutsummaryrefslogtreecommitdiffstats
path: root/find_java
diff options
context:
space:
mode:
authorDavid Herman <davidherman@google.com>2014-10-17 17:25:10 -0700
committerDavid Herman <davidherman@google.com>2014-10-23 11:48:41 -0700
commit171072b90ed953304b1bbfa96022ab71b82d9969 (patch)
tree79e000253f69e7e5d1f4e956ab7998273e462cae /find_java
parent8ebbf9d423fe3fdbbf57d972dd3a88160ccee823 (diff)
downloadsdk-171072b90ed953304b1bbfa96022ab71b82d9969.zip
sdk-171072b90ed953304b1bbfa96022ab71b82d9969.tar.gz
sdk-171072b90ed953304b1bbfa96022ab71b82d9969.tar.bz2
New -error arg for find_java
We want our installer to show a (potentially) helpful error message when find_java can't, well, find java. (Before, find_java would print nothing). After this CL is in, then if you pass -e(rror) in as an argument, find_java will either print the found java.exe path and return 0, or it will print an error message and return 1. Change-Id: I5c411ea75a8eecdb0c60aa84350a2a762a30c6d1
Diffstat (limited to 'find_java')
-rw-r--r--find_java/src/source/find_java_exe.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/find_java/src/source/find_java_exe.cpp b/find_java/src/source/find_java_exe.cpp
index f14c037..e311646 100644
--- a/find_java/src/source/find_java_exe.cpp
+++ b/find_java/src/source/find_java_exe.cpp
@@ -50,6 +50,7 @@ static int showHelpMessage() {
"Options:\n"
"-h / -help : This help.\n"
"-t / -test : Internal test.\n"
+ "-e / -error : Print an error message to the console if Java.exe isn't found.\n"
"-j / -jdk : Only returns java.exe found in a JDK.\n"
"-s / -short : Print path in short DOS form.\n"
"-w / -javaw : Search a matching javaw.exe; defaults to java.exe if not found.\n"
@@ -59,6 +60,13 @@ static int showHelpMessage() {
return 2;
}
+static void printError(const char *message) {
+
+ CString error;
+ error.setLastWin32Error(message);
+ printf(error.cstr());
+}
+
static void testFindJava(bool isJdk, int minVersion) {
CPath javaPath("<not found>");
@@ -108,6 +116,7 @@ int main(int argc, char* argv[]) {
bool doVersion = false;
bool doJavaW = false;
bool isJdk = false;
+ bool shouldPrintError = false;
int minVersion = MIN_JAVA_VERSION;
for (int i = 1; i < argc; i++) {
@@ -118,6 +127,9 @@ int main(int argc, char* argv[]) {
} else if (strncmp(argv[i], "-j", 2) == 0) {
isJdk = true;
+ } else if (strncmp(argv[i], "-e", 2) == 0) {
+ shouldPrintError = true;
+
} else if (strncmp(argv[i], "-d", 2) == 0) {
gIsDebug = true;
@@ -153,19 +165,33 @@ int main(int argc, char* argv[]) {
version = findJavaInProgramFiles(&javaPath, isJdk, minVersion);
}
- if (version == 0 || javaPath.isEmpty()) {
+ if (version == 0) {
+ CString s;
+ s.setf("Failed to find Java %d.%d (or newer) on your system. ", JAVA_MAJOR(minVersion),
+ JAVA_MINOR(minVersion));
+
if (gIsDebug) {
- fprintf(stderr, "Failed to find Java on your system.\n");
+ fprintf(stderr, s.cstr());
}
+
+ if (shouldPrintError) {
+ printError(s.cstr());
+ }
+
return 1;
}
_ASSERT(!javaPath.isEmpty());
if (doShortPath) {
if (!javaPath.toShortPath(&javaPath)) {
- fprintf(stderr,
- "Failed to convert path to a short DOS path: %s\n",
- javaPath.cstr());
+ CString s;
+ s.setf("Failed to convert path (%s) to a short DOS path. ", javaPath.cstr());
+ fprintf(stderr, s.cstr());
+
+ if (shouldPrintError) {
+ printError(s.cstr());
+ }
+
return 1;
}
}
@@ -188,7 +214,7 @@ int main(int argc, char* argv[]) {
}
// Print java.exe path found
- printf("%s", javaPath.cstr());
+ printf(javaPath.cstr());
return 0;
}