Add preference page to enable/disable STS language server debug consoles

This commit is contained in:
Kris De Volder
2018-02-02 11:26:02 -08:00
parent ffdd395538
commit 8fb6d09cb2
13 changed files with 204 additions and 15 deletions

View File

@@ -10,6 +10,8 @@
*******************************************************************************/
package org.springframework.tooling.boot.java.ls;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.BOOT_JAVA_SERVER;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
@@ -23,7 +25,6 @@ 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;
/**
@@ -32,7 +33,7 @@ import org.springframework.tooling.ls.eclipse.commons.STS4LanguageServerProcessS
public class SpringBootJavaLanguageServer extends STS4LanguageServerProcessStreamConnector {
public SpringBootJavaLanguageServer() {
super("Boot Java Language Server");
super(BOOT_JAVA_SERVER);
List<String> commands = new ArrayList<>();
JRE jre = getJRE();
commands.add(jre.getJavaExecutable());

View File

@@ -24,13 +24,15 @@ 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.*;
/**
* @author Martin Lippert
*/
public class BoshLanguageServer extends STS4LanguageServerProcessStreamConnector {
public BoshLanguageServer() {
super("Bosh Language Server");
super(BOSH_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());

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 static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.*;
/**
* @author Martin Lippert
*/
@@ -43,7 +45,7 @@ public class CloudFoundryManifestLanguageServer extends STS4LanguageServerProces
private static List<CloudFoundryManifestLanguageServer> servers = new CopyOnWriteArrayList<>();
public CloudFoundryManifestLanguageServer() {
super("Cloudfoundry Language Server");
super(CLOUDFOUNDRY_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());

View File

@@ -24,13 +24,15 @@ 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.*;
/**
* @author Martin Lippert
*/
public class ConcourseLanguageServer extends STS4LanguageServerProcessStreamConnector {
public ConcourseLanguageServer() {
super("Concourse Language Server");
super(CONCOURSE_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());

View File

@@ -17,4 +17,6 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.8.0",
org.eclipse.ui.console
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.springframework.tooling.ls.eclipse.commons
Export-Package: org.springframework.tooling.ls.eclipse.commons,
org.springframework.tooling.ls.eclipse.commons.console.preferences
Bundle-Activator: org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator

View File

@@ -26,5 +26,18 @@
verticalRulerPreferenceValue="true">
</specification>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
class="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPreferencesPage"
id="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPreferencesPage"
name="Language Servers STS">
</page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPrefsInitializer">
</initializer>
</extension>
</plugin>

View File

@@ -0,0 +1,34 @@
/*******************************************************************************
* 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.ls.eclipse.commons;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class LanguageServerCommonsActivator extends AbstractUIPlugin {
private static LanguageServerCommonsActivator instance;
public LanguageServerCommonsActivator() {
}
@Override
public void start(BundleContext context) throws Exception {
instance = this;
super.start(context);
}
public static LanguageServerCommonsActivator getInstance() {
return instance;
}
}

View File

@@ -26,16 +26,16 @@ import org.springframework.tooling.ls.eclipse.commons.console.LanguageServerCons
import com.google.common.base.Charsets;
import com.google.common.base.Supplier;
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConnectionProvider {
private static LanguageServerProcessReaper processReaper = new LanguageServerProcessReaper();
private Supplier<Console> consoles = null;
public STS4LanguageServerProcessStreamConnector(String consoleLabel) {
if (consoleLabel!=null) {
this.consoles = LanguageServerConsoles.getConsoleFactory(consoleLabel);
}
public STS4LanguageServerProcessStreamConnector(ServerInfo server) {
this.consoles = LanguageServerConsoles.getConsoleFactory(server);
}
@Override
@@ -55,6 +55,7 @@ public class STS4LanguageServerProcessStreamConnector extends ProcessStreamConne
}
ProcessBuilder builder = new ProcessBuilder(getCommands());
builder.directory(new File(getWorkingDirectory()));
//Super does this, but we do not:
//builder.redirectError(ProcessBuilder.Redirect.INHERIT);
return builder;
}

View File

@@ -13,7 +13,9 @@ package org.springframework.tooling.ls.eclipse.commons.console;
import java.util.HashMap;
import java.util.Map;
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
import org.springframework.tooling.ls.eclipse.commons.console.ConsoleUtil.Console;
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
import com.google.common.base.Supplier;
@@ -21,18 +23,21 @@ public class LanguageServerConsoles {
private static Map<String, Supplier<Console>> managers;
public static synchronized Supplier<Console> getConsoleFactory(String languageServerName) {
public static synchronized Supplier<Console> getConsoleFactory(ServerInfo server) {
if (!isConsoleEnabled(server)) {
return null;
}
if (managers==null) {
managers = new HashMap<>();
}
return managers.computeIfAbsent(languageServerName, label -> new Supplier<Console>() {
return managers.computeIfAbsent(server.label, label -> new Supplier<Console>() {
ConsoleUtil consoleMgr = new ConsoleUtil(); //one console manager per language server type. This way each has their
// own history (which limits number of open consoles per type)
int consoleCounter = 0;
@Override
public Console get() {
return consoleMgr.getConsole(languageServerName+" "+consoleCounter());
return consoleMgr.getConsole(server.label+" Language Server "+consoleCounter());
}
private synchronized int consoleCounter() {
@@ -41,4 +46,8 @@ public class LanguageServerConsoles {
});
}
private static boolean isConsoleEnabled(ServerInfo server) {
return LanguageServerCommonsActivator.getInstance().getPreferenceStore().getBoolean(server.preferenceKey);
}
}

View File

@@ -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.ls.eclipse.commons.console.preferences;
public class LanguageServerConsolePreferenceConstants {
public static final boolean ENABLE_BY_DEFAULT = true;
public static final String PREF_BOOT_JAVA_CONSOLE_ENABLED = "boot-java.console.enabled";
public static final String PREF_BOOT_PROPS_CONSOLE_ENABLED = "boot-properties.console.enabled";
public static final String PREF_CONCOURSE_CONSOLE_ENABLED = "concourse.console.enabled";
public static final String PREF_CLOUDFOUNDRY_CONSOLE_ENABLED = "cloudfoundry.console.enabled";
public static final String PREF_BOSH_CONSOLE_ENABLED = "bosh.console.enabled";
public static final ServerInfo BOOT_JAVA_SERVER = new ServerInfo(PREF_BOOT_JAVA_CONSOLE_ENABLED, "Boot Java");
public static final ServerInfo BOOT_PROPS_SERVER = new ServerInfo(PREF_BOOT_PROPS_CONSOLE_ENABLED, "Boot Properties");
public static final ServerInfo CLOUDFOUNDRY_SERVER = new ServerInfo(PREF_CLOUDFOUNDRY_CONSOLE_ENABLED, "Cloudfoundry");
public static final ServerInfo CONCOURSE_SERVER = new ServerInfo(PREF_CONCOURSE_CONSOLE_ENABLED, "Concourse");
public static final ServerInfo BOSH_SERVER = new ServerInfo(PREF_BOSH_CONSOLE_ENABLED, "Bosh");
public static final ServerInfo[] ALL_SERVERS = {
BOOT_JAVA_SERVER,
BOOT_PROPS_SERVER,
CLOUDFOUNDRY_SERVER,
CONCOURSE_SERVER,
BOSH_SERVER
};
public static class ServerInfo {
public final String preferenceKey;
public final String label;
public ServerInfo(String preferenceKey, String label) {
super();
this.preferenceKey = preferenceKey;
this.label = label;
}
@Override
public String toString() {
return "ServerInfo [preferenceKey=" + preferenceKey + ", label=" + label + "]";
}
}
}

View File

@@ -0,0 +1,44 @@
/*******************************************************************************
* 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.ls.eclipse.commons.console.preferences;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ALL_SERVERS;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator;
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
public class LanguageServerConsolesPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
static IPreferenceStore getPrefsStoreFromPlugin() {
return LanguageServerCommonsActivator.getInstance().getPreferenceStore();
}
@Override
public void init(IWorkbench workbench) {
setDescription("Enablement of STS Language Server Debug Consoles. "
+ "Changes only take effect the next time a Language Server is started.");
setPreferenceStore(getPrefsStoreFromPlugin());
}
@Override
protected void createFieldEditors() {
Composite parent = getFieldEditorParent();
for (ServerInfo s : ALL_SERVERS) {
addField(new BooleanFieldEditor(s.preferenceKey, s.label, parent));
}
}
}

View File

@@ -0,0 +1,27 @@
/*******************************************************************************
* 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.ls.eclipse.commons.console.preferences;
import static org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.*;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolePreferenceConstants.ServerInfo;
public class LanguageServerConsolesPrefsInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = LanguageServerConsolesPreferencesPage.getPrefsStoreFromPlugin();
for (ServerInfo s : ALL_SERVERS) {
store.setDefault(s.preferenceKey, ENABLE_BY_DEFAULT);
}
}
}

View File

@@ -24,13 +24,15 @@ 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.*;
/**
* @author Martin Lippert
*/
public class SpringBootPropertiesLanguageServer extends STS4LanguageServerProcessStreamConnector {
public SpringBootPropertiesLanguageServer() {
super("Boot Properties Language Server");
super(BOOT_PROPS_SERVER);
List<String> commands = new ArrayList<>();
commands.add(JRE.currentJRE().getJavaExecutable());