Add warning message in Eclipse for missing tools.jar on boot-java ls
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -39,7 +39,16 @@ public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStrea
|
||||
commands.add("-Dlsp.completions.indentation.enable=true");
|
||||
commands.add("-Xmx1024m");
|
||||
commands.add("-cp");
|
||||
commands.add(getToolsJAR() + File.pathSeparator + getLanguageServerJARLocation());
|
||||
String classpath = getLanguageServerJARLocation();
|
||||
try {
|
||||
File toolsJar = getToolsJAR();
|
||||
if (toolsJar!=null) {
|
||||
classpath = toolsJar + File.pathSeparator + classpath;
|
||||
}
|
||||
} catch (MissingToolsJarException e) {
|
||||
MissingToolsJarWarning.show(e);
|
||||
}
|
||||
commands.add(classpath);
|
||||
commands.add("org.springframework.boot.loader.JarLauncher");
|
||||
|
||||
String workingDir = getWorkingDirLocation();
|
||||
|
||||
@@ -12,14 +12,27 @@ package org.springframework.tooling.ls.eclipse.commons;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jdt.internal.launching.StandardVMType;
|
||||
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConnectionProvider {
|
||||
|
||||
public static class MissingToolsJarException extends Exception {
|
||||
|
||||
public final File javaHome;
|
||||
public final List<File> lookedIn;
|
||||
|
||||
public MissingToolsJarException(File javaHome, List<File> lookedIn) {
|
||||
super();
|
||||
this.javaHome = javaHome;
|
||||
this.lookedIn = lookedIn;
|
||||
}
|
||||
}
|
||||
|
||||
private static LanguageServerProcessReaper processReaper = new LanguageServerProcessReaper();
|
||||
|
||||
@Override
|
||||
@@ -50,9 +63,32 @@ public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConne
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getToolsJAR() {
|
||||
File jre = new File(System.getProperty("java.home"));
|
||||
return new File(jre.getParent(), "lib" + Path.SEPARATOR + "tools.jar").getAbsolutePath();
|
||||
/**
|
||||
* Different places to look for tools jar, relative to Java home.
|
||||
*/
|
||||
private static String[] TOOLS_JAR_PATHS = {
|
||||
"../lib/tools.jar",
|
||||
"lib/tools.jar"
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a tools jar if it is needed based on current JRE version.
|
||||
*
|
||||
* @return The tools.jar, or null if none is needed.
|
||||
* @throws MissingToolsJarException If tools jar is needed but could not be found.
|
||||
*/
|
||||
protected File getToolsJAR() throws MissingToolsJarException {
|
||||
List<File> lookedIn = new ArrayList<>();
|
||||
File jhome = new File(System.getProperty("java.home"));
|
||||
// resolve(System.getenv("JAVA_HOME"), jhomes::add);
|
||||
for (String tjPath : TOOLS_JAR_PATHS) {
|
||||
File toolsJar = new File(jhome, tjPath).toPath().normalize().toFile();
|
||||
lookedIn.add(toolsJar);
|
||||
if (toolsJar.isFile()) {
|
||||
return toolsJar;
|
||||
}
|
||||
}
|
||||
throw new MissingToolsJarException(jhome, lookedIn);
|
||||
}
|
||||
|
||||
protected String getWorkingDirLocation() {
|
||||
|
||||
Reference in New Issue
Block a user