Fixes related config settings now being JsonElement
This commit is contained in:
@@ -30,13 +30,13 @@ public class BoshCliConfig {
|
||||
private Settings settings = new Settings(null);
|
||||
|
||||
public String getCommand() {
|
||||
return (String) settings.getProperty("bosh", "cli", "command");
|
||||
return settings.getString("bosh", "cli", "command");
|
||||
}
|
||||
public String getTarget() {
|
||||
return (String) settings.getProperty("bosh", "cli", "target");
|
||||
return settings.getString("bosh", "cli", "target");
|
||||
}
|
||||
public Duration getTimeout() {
|
||||
Integer seconds = (Integer) settings.getProperty("cli", "timeout");
|
||||
Integer seconds = settings.getInt("cli", "timeout");
|
||||
return seconds == null ? Duration.ofSeconds(3) : Duration.ofSeconds(seconds);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public class BoshCommandStemcellsProviderTest {
|
||||
|
||||
@@ -83,12 +85,12 @@ public class BoshCommandStemcellsProviderTest {
|
||||
// }
|
||||
|
||||
@Test public void obeysCliConfigCommandAndTarget() throws Exception {
|
||||
Map<String, Object> settings = ImmutableMap.of("bosh", ImmutableMap.of("cli",
|
||||
JsonElement settings = settings(ImmutableMap.of("bosh", ImmutableMap.of("cli",
|
||||
ImmutableMap.of(
|
||||
"command", "alternate-command",
|
||||
"target", "some-target"
|
||||
)
|
||||
));
|
||||
)));
|
||||
cliConfig.handleConfigurationChange(new Settings(settings));
|
||||
assertEquals(ImmutableList.of(
|
||||
new StemcellData("bosh-vsphere-esxi-centos-7-go_agent", "3421.11", "centos-7"),
|
||||
@@ -100,12 +102,12 @@ public class BoshCommandStemcellsProviderTest {
|
||||
}
|
||||
|
||||
@Test public void obeysCliConfigTarget() throws Exception {
|
||||
Map<String, Object> settings = ImmutableMap.of("bosh", ImmutableMap.of("cli",
|
||||
JsonElement settings = settings(ImmutableMap.of("bosh", ImmutableMap.of("cli",
|
||||
ImmutableMap.of(
|
||||
"command", "alternate-command",
|
||||
"target", "explicit-target"
|
||||
)
|
||||
));
|
||||
)));
|
||||
cliConfig.handleConfigurationChange(new Settings(settings));
|
||||
assertEquals(ImmutableList.of(
|
||||
new StemcellData("bosh-vsphere-esxi-centos-7-go_agent", "3421.11", "centos-7"),
|
||||
@@ -116,4 +118,8 @@ public class BoshCommandStemcellsProviderTest {
|
||||
verify(provider).executeCommand(eq(new ExternalCommand("alternate-command", "-e", "explicit-target", "stemcells", "--json")));
|
||||
}
|
||||
|
||||
private JsonElement settings(Object configObject) {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJsonTree(configObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,10 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
||||
@@ -10,7 +10,11 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.util;
|
||||
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
* Convenience wrapper around a 'settings' object. Provides some useful accessor methods to
|
||||
@@ -18,31 +22,60 @@ import java.util.Map;
|
||||
*/
|
||||
public class Settings {
|
||||
|
||||
private Object settings;
|
||||
private static final Logger log = LoggerFactory.getLogger(Settings.class);
|
||||
|
||||
public Settings(Object settings) {
|
||||
private JsonElement settings;
|
||||
|
||||
public Settings(JsonElement settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public Integer getInt(String... names) {
|
||||
Object val = getProperty(names);
|
||||
if (val instanceof Number) {
|
||||
return ((Number) val).intValue();
|
||||
try {
|
||||
JsonElement val = getRawProperty(names);
|
||||
if (val != null) {
|
||||
return val.getAsInt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getProperty(String... names) {
|
||||
return getProperty(settings, names, 0);
|
||||
public String getString(String... names) {
|
||||
try {
|
||||
JsonElement val = getRawProperty(names);
|
||||
if (val != null) {
|
||||
return val.getAsString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static Object getProperty(Object settings, String[] names, int i) {
|
||||
public Boolean getBoolean(String... names) {
|
||||
try {
|
||||
JsonElement val = getRawProperty(names);
|
||||
if (val != null) {
|
||||
return val.getAsBoolean();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JsonElement getRawProperty(String... names) {
|
||||
return getRawProperty(settings, names, 0);
|
||||
}
|
||||
|
||||
private static JsonElement getRawProperty(JsonElement settings, String[] names, int i) {
|
||||
if (i >= names.length) {
|
||||
return settings;
|
||||
} else if (settings instanceof Map) {
|
||||
Object sub = ((Map)settings).get(names[i]);
|
||||
return getProperty(sub, names, i+1);
|
||||
} else if (settings instanceof JsonObject) {
|
||||
JsonElement sub = ((JsonObject)settings).get(names[i]);
|
||||
return getRawProperty(sub, names, i+1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -52,4 +85,5 @@ public class Settings {
|
||||
public String toString() {
|
||||
return settings.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -72,7 +73,7 @@ public class SimpleWorkspaceService implements WorkspaceService {
|
||||
|
||||
@Override
|
||||
public void didChangeConfiguration(DidChangeConfigurationParams params) {
|
||||
configurationListeners.fire(new Settings(params.getSettings()));
|
||||
configurationListeners.fire(new Settings((JsonElement) params.getSettings()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -128,7 +128,8 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
|
||||
documents.onHover(hoverEngine);
|
||||
|
||||
workspace.onDidChangeConfiguraton(settings -> {
|
||||
Object cfClientParamsObj = settings.getProperty("cfClientParams");
|
||||
Object cfClientParamsObj = settings.getRawProperty("cfClientParams");
|
||||
//TODO code below is almost certainly broken. LSP4J doesn't return Map here but JsonObject.
|
||||
if (cfClientParamsObj instanceof Map<?,?>) {
|
||||
applyCfLoginParameterSettings((Map<?,?>) cfClientParamsObj);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class BootJavaConfig {
|
||||
private Settings settings = new Settings(null);
|
||||
|
||||
public boolean isBootHintsEnabled() {
|
||||
Boolean enabled = (Boolean) settings.getProperty("boot-java", "boot-hints", "on");
|
||||
Boolean enabled = settings.getBoolean("boot-java", "boot-hints", "on");
|
||||
return enabled == null || enabled.booleanValue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user