Fix issues with how bosh cli config is passed from vscode to server
This commit is contained in:
@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.bosh;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
/**
|
||||
* Provides access to configuration options that allow user to
|
||||
@@ -29,17 +30,18 @@ public class BoshCliConfig {
|
||||
private Settings settings = new Settings(null);
|
||||
|
||||
public String getCommand() {
|
||||
return (String) settings.getProperty("cli.command");
|
||||
return (String) settings.getProperty("bosh", "cli", "command");
|
||||
}
|
||||
public String getTarget() {
|
||||
return (String) settings.getProperty("cli.target");
|
||||
return (String) settings.getProperty("bosh", "cli", "target");
|
||||
}
|
||||
public Duration getTimeout() {
|
||||
Integer seconds = (Integer) settings.getProperty("cli.timeout");
|
||||
Integer seconds = (Integer) settings.getProperty("cli", "timeout");
|
||||
return seconds == null ? Duration.ofSeconds(3) : Duration.ofSeconds(seconds);
|
||||
}
|
||||
|
||||
public void handleConfigurationChange(Settings newConfig) {
|
||||
Log.info("BoshCliConfig changed: "+newConfig);
|
||||
this.settings = newConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package org.springframework.ide.vscode.bosh.models;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -73,17 +74,21 @@ public abstract class BoshCommandBasedModelProvider<T> implements DynamicModelPr
|
||||
}
|
||||
|
||||
protected final ExternalCommand getCommand() {
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add(config.getCommand());
|
||||
List<String> commandAndArgs = new ArrayList<>();
|
||||
String command = config.getCommand();
|
||||
if (command==null) {
|
||||
return null;
|
||||
}
|
||||
commandAndArgs.add(command);
|
||||
String target = config.getTarget();
|
||||
if (target!=null) {
|
||||
command.add("-e");
|
||||
command.add(target);
|
||||
commandAndArgs.add("-e");
|
||||
commandAndArgs.add(target);
|
||||
}
|
||||
for (String s : getBoshCommand()) {
|
||||
command.add(s);
|
||||
commandAndArgs.add(s);
|
||||
}
|
||||
return new ExternalCommand(command.toArray(new String[command.size()]));
|
||||
return new ExternalCommand(commandAndArgs.toArray(new String[commandAndArgs.size()]));
|
||||
}
|
||||
|
||||
protected JsonNode getJsonTree() throws Exception {
|
||||
@@ -93,6 +98,9 @@ public abstract class BoshCommandBasedModelProvider<T> implements DynamicModelPr
|
||||
|
||||
protected String executeCommand(ExternalCommand command) throws Exception {
|
||||
Log.info("executing cmd: "+command);
|
||||
if (command==null) {
|
||||
throw new IOException("bosh cli based editor features are disabled");
|
||||
}
|
||||
try {
|
||||
ExternalProcess process = new ExternalProcess(getWorkingDir(), command, true, config.getTimeout());
|
||||
Log.info("executing cmd SUCCESS: "+process);
|
||||
|
||||
@@ -71,10 +71,23 @@ public class BoshCommandStemcellsProviderTest {
|
||||
provider.getModel(mock(DynamicSchemaContext.class)).getVersions());
|
||||
}
|
||||
|
||||
// @Test public void defaultCliConfig() throws Exception {
|
||||
// assertEquals(ImmutableList.of(
|
||||
// new StemcellData("bosh-vsphere-esxi-centos-7-go_agent", "3421.11", "centos-7"),
|
||||
// new StemcellData("bosh-vsphere-esxi-ubuntu-trusty-go_agent", "3421.11", "ubuntu-trusty")
|
||||
// ),
|
||||
// provider.getModel(mock(DynamicSchemaContext.class)).getStemcells()
|
||||
// );
|
||||
// verify(provider).executeCommand(eq(new ExternalCommand("bosh", "stemcells", "--json")));
|
||||
// }
|
||||
|
||||
@Test public void obeysCliConfigCommand() throws Exception {
|
||||
Map<String, String> settings = ImmutableMap.of(
|
||||
"cli.command", "alternate-command"
|
||||
);
|
||||
Map<String, Object> settings = ImmutableMap.of("bosh", ImmutableMap.of("cli",
|
||||
ImmutableMap.of(
|
||||
"command", "alternate-command"
|
||||
)
|
||||
));
|
||||
|
||||
cliConfig.handleConfigurationChange(new Settings(settings));
|
||||
assertEquals(ImmutableList.of(
|
||||
new StemcellData("bosh-vsphere-esxi-centos-7-go_agent", "3421.11", "centos-7"),
|
||||
@@ -86,10 +99,12 @@ public class BoshCommandStemcellsProviderTest {
|
||||
}
|
||||
|
||||
@Test public void obeysCliConfigTarget() throws Exception {
|
||||
Map<String, String> settings = ImmutableMap.of(
|
||||
"cli.command", "alternate-command",
|
||||
"cli.target", "explicit-target"
|
||||
);
|
||||
Map<String, Object> 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"),
|
||||
|
||||
Reference in New Issue
Block a user