Bug 475640 - To open "Eclipse" you need to install the legacy Java SE 6
runtime.

Change-Id: I53d06915592283618c2c2b8298f57bb1d659d766
Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c
index deba3ef..4529c34 100644
--- a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -377,8 +377,12 @@
 	if (fp == NULL) {
 		return NULL;
 	}
+	path[0] = 0;
 	while (fgets(path, sizeof(path)-1, fp) != NULL) {
 	}
+	if(path[0]==0) {
+		return NULL;
+	}
 	result = path;
 	start = strchr(result, '\n');
 	if (start) {
@@ -421,6 +425,9 @@
 	cmd = command;
 	if (strstr(cmd, "/JavaVM.framework/") != NULL && (strstr(cmd, "/Current/") != NULL || strstr(cmd, "/A/") != NULL)) {
 		cmd = getJavaHome();
+		if (cmd == NULL) {
+			return NULL;
+		}
 	}
 	// This is necessary to initialize isModularJVM
 	checkJavaVersion(cmd);
@@ -554,7 +561,15 @@
 
 JavaResults* launchJavaVM( _TCHAR* args[] )
 {
-	/*for now always do JNI on Mac, should not come in here */
+	/*
+	 * On macOS, JNI is always used, so this point is only reached, if no usable JVM was found.
+	 * Request a JDK install: The 'script' command makes stdin and stdout look like a tty,
+	 * so it looks for /usr/libexec/java_home that this is for a command line tool and a dialog
+	 * with a link to the JDK download page is shown.
+	 */
+	execl("/usr/bin/script", "/usr/bin/script", "/dev/null", "/usr/libexec/java_home", "--request", NULL);
+
+	/* not reached. */
 	JavaResults * results = malloc(sizeof(JavaResults));
 	results->launchResult = -1;
 	results->runResult = 0;