aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herman <davidherman@google.com>2014-11-14 00:12:07 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-11-14 00:12:08 +0000
commit892639ff55d3425b1f82559c8a646a600ab9f328 (patch)
treee85ee0d9f566ea2cc6606c489e078b498027ba28
parenta82332e9eed2c974ea3a5f1c4331a7992b016533 (diff)
parent171072b90ed953304b1bbfa96022ab71b82d9969 (diff)
downloadsdk-892639ff55d3425b1f82559c8a646a600ab9f328.zip
sdk-892639ff55d3425b1f82559c8a646a600ab9f328.tar.gz
sdk-892639ff55d3425b1f82559c8a646a600ab9f328.tar.bz2
Merge "New -error arg for find_java" into studio-1.0-dev
-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;
}