Tweak eclipse ls packaging/launching

Take advantage of Spring boot properties launcher ability
to add tools.jar to classpath via a system property.
This commit is contained in:
Kris De Volder
2018-03-05 11:01:01 -08:00
parent 0220cf41bd
commit 13d4436254
9 changed files with 78 additions and 104 deletions

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.springframework.tooling.boot.java.ls</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -27,6 +27,8 @@ import org.springframework.tooling.ls.eclipse.commons.JRE;
import org.springframework.tooling.ls.eclipse.commons.JRE.MissingJDKException;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
import com.google.common.collect.ImmutableList;
/**
* @author Martin Lippert
*/
@@ -34,27 +36,27 @@ public class SpringBootLanguageServer extends STS4LanguageServerProcessStreamCon
public SpringBootLanguageServer() {
super(SPRING_BOOT_SERVER);
List<String> commands = new ArrayList<>();
JRE jre = getJRE();
commands.add(jre.getJavaExecutable());
List<String> vmargs = new ArrayList<>();
// commands.add("-Xdebug");
// commands.add("-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n");
// vmargs.add("-Xdebug");
// vmargs.add("-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n");
commands.add("-Dlsp.lazy.completions.disable=true");
commands.add("-Dlsp.completions.indentation.enable=true");
commands.add("-Xmx1024m");
commands.add("-cp");
String classpath = getLanguageServerJARLocation();
if (jre.toolsJar!=null) {
classpath = jre.toolsJar + File.pathSeparator + classpath;
}
commands.add(classpath);
commands.add("org.springframework.boot.loader.JarLauncher");
vmargs.add("-Dlsp.lazy.completions.disable=true");
vmargs.add("-Dlsp.completions.indentation.enable=true");
vmargs.add("-Xmx1024m");
String workingDir = getWorkingDirLocation();
setCommands(commands);
setCommands(jre.jarLaunchCommand(getLanguageServerJARLocation(),
ImmutableList.of(
//"-Xdebug",
// "-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n"
"-Dlsp.lazy.completions.disable=true",
"-Dlsp.completions.indentation.enable=true",
"-Xmx1024m"
)
));
setWorkingDirectory(workingDir);
}

View File

@@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
org.eclipse.lsp4j;bundle-version="0.4.0",
org.eclipse.ui.workbench,
org.eclipse.jface,
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0"
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0",
com.google.guava
Import-Package: com.google.gson;version="2.7.0",
org.eclipse.jface.preference,
org.osgi.framework

View File

@@ -10,12 +10,12 @@
*******************************************************************************/
package org.springframework.tooling.bosh.ls;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.BOSH_SERVER;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
@@ -24,7 +24,7 @@ import org.osgi.framework.Bundle;
import org.springframework.tooling.ls.eclipse.commons.JRE;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.*;
import com.google.common.collect.ImmutableList;
/**
* @author Martin Lippert
@@ -33,22 +33,13 @@ public class BoshLanguageServer extends STS4LanguageServerProcessStreamConnector
public BoshLanguageServer() {
super(BOSH_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());
// commands.add("-Xdebug");
// commands.add("-agentlib:jdwp=transport=dt_socket,address=8899,server=y,suspend=n");
commands.add("-Dlsp.lazy.completions.disable=true");
commands.add("-Dlsp.completions.indentation.enable=true");
commands.add("-jar");
commands.add(getLanguageServerJARLocation());
String workingDir = getWorkingDirLocation();
setCommands(commands);
setWorkingDirectory(workingDir);
setCommands(JRE.currentJRE().jarLaunchCommand(getLanguageServerJARLocation(), ImmutableList.of(
//"-Xdebug",
//"-agentlib:jdwp=transport=dt_socket,address=8899,server=y,suspend=n",
"-Dlsp.lazy.completions.disable=true",
"-Dlsp.completions.indentation.enable=true"
)));
setWorkingDirectory(getWorkingDirLocation());
}
protected String getLanguageServerJARLocation() {

View File

@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.8.0",
org.eclipse.lsp4e;bundle-version="0.5.0",
org.eclipse.lsp4j;bundle-version="0.4.0",
org.eclipse.lsp4j.jsonrpc;bundle-version="0.4.0",
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0"
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0",
com.google.guava
Import-Package: org.eclipse.jface.preference,
org.osgi.framework
Export-Package: org.springframework.tooling.cloudfoundry.manifest.ls

View File

@@ -31,6 +31,8 @@ import org.osgi.framework.Bundle;
import org.springframework.tooling.ls.eclipse.commons.JRE;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
import com.google.common.collect.ImmutableList;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.*;
/**
@@ -46,23 +48,13 @@ public class CloudFoundryManifestLanguageServer extends STS4LanguageServerProces
public CloudFoundryManifestLanguageServer() {
super(CLOUDFOUNDRY_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());
// commands.add("-Xdebug");
// commands.add("-agentlib:jdwp=transport=dt_socket,address=8899,server=y,suspend=n");
// commands.add("-Dlsp.lazy.completions.disable=true");
commands.add("-Dlsp.completions.indentation.enable=true");
commands.add("-jar");
commands.add(getLanguageServerJARLocation());
String workingDir = getWorkingDirLocation();
setCommands(commands);
setWorkingDirectory(workingDir);
setCommands(JRE.currentJRE().jarLaunchCommand(getLanguageServerJARLocation(), ImmutableList.of(
//"-Xdebug",
//"-agentlib:jdwp=transport=dt_socket,address=8899,server=y,suspend=n",
"-Dlsp.lazy.completions.disable=true",
"-Dlsp.completions.indentation.enable=true"
)));
setWorkingDirectory(getWorkingDirLocation());
}
@Override

View File

@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
org.eclipse.tm4e.ui;bundle-version="0.1.0",
org.eclipse.ui.workbench,
org.eclipse.jface,
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0"
org.springframework.tooling.ls.eclipse.commons;bundle-version="4.0.0",
com.google.guava
Import-Package: com.google.gson;version="2.7.0",
org.eclipse.jface.preference,
org.osgi.framework

View File

@@ -10,12 +10,12 @@
*******************************************************************************/
package org.springframework.tooling.concourse.ls;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.CONCOURSE_SERVER;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
@@ -24,7 +24,7 @@ import org.osgi.framework.Bundle;
import org.springframework.tooling.ls.eclipse.commons.JRE;
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessStreamConnector;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.*;
import com.google.common.collect.ImmutableList;
/**
* @author Martin Lippert
@@ -33,22 +33,13 @@ public class ConcourseLanguageServer extends STS4LanguageServerProcessStreamConn
public ConcourseLanguageServer() {
super(CONCOURSE_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());
// commands.add("-Xdebug");
// commands.add("-agentlib:jdwp=transport=dt_socket,address=8899,server=y,suspend=n");
commands.add("-Dlsp.lazy.completions.disable=true");
commands.add("-Dlsp.completions.indentation.enable=true");
commands.add("-jar");
commands.add(getLanguageServerJARLocation());
String workingDir = getWorkingDirLocation();
setCommands(commands);
setWorkingDirectory(workingDir);
setCommands(JRE.currentJRE().jarLaunchCommand(getLanguageServerJARLocation(), ImmutableList.of(
//"-Xdebug",
//"-agentlib:jdwp=transport=dt_socket,address=8899,server=y,suspend=n",
"-Dlsp.lazy.completions.disable=true",
"-Dlsp.completions.indentation.enable=true"
)));
setWorkingDirectory(getWorkingDirLocation());
}
protected String getLanguageServerJARLocation() {

View File

@@ -18,6 +18,10 @@ import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.ui.internal.commands.CommandService;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
@SuppressWarnings("restriction")
public class JRE {
@@ -53,11 +57,11 @@ public class JRE {
* Get a JRE, with a paired tools jar if it is needed based on current JRE version
* and whether the caller wants it.
*
* @return The tools.jar, or null if none is needed.
* @return The JRE.
* @throws MissingToolsJarException If tools jar is needed but could not be found.
* @throws MissingJava9JDKException
* @throws MissingJDKException
*/
public static JRE findJRE(boolean needJdk) throws MissingJDKException {
public static JRE findJRE(boolean needJdk) throws MissingJDKException, MissingToolsJarException {
File mainHome = new File(System.getProperty("java.home"));
if (!needJdk) {
return new JRE(mainHome, null);
@@ -151,4 +155,23 @@ public class JRE {
}
public final File javaHome;
}
/**
* Creates a 'command' that can be used to launch a executable jar
* with this jre. The tools.jar, if available, is added automatically to the classpath
* via a "-Dloader.path" argument. For this to work properly, the executable
* jar should be packaged with Spring Boot Properties loader (i.e. specify `ZIP` layout
* in the spring-boot-maven plugin configuration)
*/
public List<String> jarLaunchCommand(String jarLocation, List<String> vmargs) {
ImmutableList.Builder<String> command = ImmutableList.builder();
command.add(getJavaExecutable());
if (toolsJar!=null) {
command.add("-Dloader.path="+toolsJar);
}
command.addAll(vmargs);
command.add("-jar");
command.add(jarLocation);
return command.build();
}
}