More tweaks to 'missing jdk warnings' and JDK finding logic
1. allways use java.exe that goest with found tools.jar 2. better support for Java 9 jdk finding
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.boot.java.ls;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingJDKException;
|
||||
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingToolsJarException;
|
||||
|
||||
public class MissingJdkWarning {
|
||||
|
||||
private static boolean missingToolsJarWarningIssued = false;
|
||||
|
||||
public static void show(MissingJDKException e) {
|
||||
//Don't warn more than once per Eclipse session.
|
||||
if (!missingToolsJarWarningIssued) {
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
missingToolsJarWarningIssued = true;
|
||||
if (e instanceof MissingToolsJarException) {
|
||||
show((MissingToolsJarException)e);
|
||||
} else {
|
||||
MessageDialog.openWarning(null, "Missing JDK",
|
||||
"The JRE you are running Eclipse with appears to not be a JDK.\n\n"+
|
||||
"Spring Boot Live hovers will not work with a plain JRE.\n\n" +
|
||||
"The JRE you are running Eclipse with is:\n "+e.javaHome+"\n\n"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void show(MissingToolsJarException e) {
|
||||
StringBuilder lookedIn = new StringBuilder();
|
||||
for (File file : e.lookedIn) {
|
||||
lookedIn.append(" ");
|
||||
lookedIn.append(file);
|
||||
lookedIn.append("\n");
|
||||
}
|
||||
|
||||
MessageDialog.openWarning(null, "Missing 'tools.jar'",
|
||||
"Could not find 'tools.jar' in the active JRE.\n\n"+
|
||||
"Spring Boot Live hovers will not work without it.\n\n" +
|
||||
"The JRE you are running Eclipse with is:\n "+e.javaHome+"\n\n" +
|
||||
"Where we looked for 'tools.jar':\n" +
|
||||
lookedIn
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.boot.java.ls;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector.MissingToolsJarException;
|
||||
|
||||
public class MissingToolsJarWarning {
|
||||
|
||||
private static boolean missingToolsJarWarningIssued = false;
|
||||
|
||||
public static void show(MissingToolsJarException e) {
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
|
||||
//Don't warn more than once per Eclipse session.
|
||||
if (!missingToolsJarWarningIssued) {
|
||||
missingToolsJarWarningIssued = true;
|
||||
|
||||
StringBuilder lookedIn = new StringBuilder();
|
||||
for (File file : e.lookedIn) {
|
||||
lookedIn.append(" ");
|
||||
lookedIn.append(file);
|
||||
lookedIn.append("\n");
|
||||
}
|
||||
|
||||
MessageDialog.openWarning(null, "Missing 'tools.jar'",
|
||||
"Could not find 'tools.jar' in the active JRE.\n\n"+
|
||||
"Spring Boot Live hovers will not work without it.\n\n" +
|
||||
"The JRE you are running Eclipse with is:\n "+e.javaHome+"\n\n" +
|
||||
"Where we looked for 'tools.jar':\n" +
|
||||
lookedIn
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -21,6 +21,9 @@ import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.springframework.tooling.ls.eclipse.commons.JRE;
|
||||
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingJDKException;
|
||||
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingToolsJarException;
|
||||
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
|
||||
|
||||
/**
|
||||
@@ -30,7 +33,8 @@ public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStrea
|
||||
|
||||
public SpringBootJavaLanguageServer() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add(getJDKLocation());
|
||||
JRE jre = getJRE();
|
||||
commands.add(jre.getJavaExecutable());
|
||||
|
||||
// commands.add("-Xdebug");
|
||||
// commands.add("-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n");
|
||||
@@ -40,13 +44,8 @@ public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStrea
|
||||
commands.add("-Xmx1024m");
|
||||
commands.add("-cp");
|
||||
String classpath = getLanguageServerJARLocation();
|
||||
try {
|
||||
File toolsJar = getToolsJAR();
|
||||
if (toolsJar!=null) {
|
||||
classpath = toolsJar + File.pathSeparator + classpath;
|
||||
}
|
||||
} catch (MissingToolsJarException e) {
|
||||
MissingToolsJarWarning.show(e);
|
||||
if (jre.toolsJar!=null) {
|
||||
classpath = jre.toolsJar + File.pathSeparator + classpath;
|
||||
}
|
||||
commands.add(classpath);
|
||||
commands.add("org.springframework.boot.loader.JarLauncher");
|
||||
@@ -57,6 +56,15 @@ public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStrea
|
||||
setWorkingDirectory(workingDir);
|
||||
}
|
||||
|
||||
private JRE getJRE() {
|
||||
try {
|
||||
return JRE.findJRE(true);
|
||||
} catch (MissingJDKException e) {
|
||||
MissingJdkWarning.show(e);
|
||||
return new JRE(e.javaHome, null); //Not everything will work without tools jar. But some of it will. So fallback on JRE without toolsjar.
|
||||
}
|
||||
}
|
||||
|
||||
protected String getLanguageServerJARLocation() {
|
||||
String languageServer = "boot-java-language-server-" + Constants.LANGUAGE_SERVER_VERSION;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user