Create CloudConfigProvider and wire it up...

... in preparation for implementing various stories that depend on this
infrastructure.
This commit is contained in:
Kris De Volder
2017-07-18 15:52:34 -07:00
parent eb440634b4
commit cecd98f7a5
19 changed files with 279 additions and 31 deletions

View File

@@ -13,6 +13,7 @@ package org.springframework.ide.vscode.commons.util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
/**
* Encapsulates information about an 'external' command that can be run through the OS.
@@ -68,7 +69,7 @@ public class ExternalCommand {
* result of commands are logged to the console and if the command returns non
* 0 exit value an exception is thrown.
*/
public void exec(File workdir) throws IOException, InterruptedException {
public void exec(File workdir) throws IOException, InterruptedException, TimeoutException {
System.out.println(">>> exec: "+this);
ExternalProcess process = new ExternalProcess(workdir, this);
System.out.println(process);

View File

@@ -16,6 +16,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
@@ -113,13 +116,14 @@ public class ExternalProcess {
* Creates an external process and waits for it to terminate. The output and error streams
* will be read and forwarded to System.out and System.err
*/
public ExternalProcess(File workingDir, ExternalCommand cmd) throws IOException, InterruptedException {
this(workingDir, cmd, false);
public ExternalProcess(File workingDir, ExternalCommand cmd) throws IOException, InterruptedException, TimeoutException {
this(workingDir, cmd, false, null);
}
private void init(File workingDir, ExternalCommand cmd,
OutputStream outStream, OutputStream errStream) throws IOException,
InterruptedException {
OutputStream outStream, OutputStream errStream,
Duration timeout) throws IOException,
InterruptedException, TimeoutException {
this.cmd = cmd;
ProcessBuilder processBuilder = new ProcessBuilder(cmd.getProgramAndArgs());
processBuilder.directory(workingDir);
@@ -127,15 +131,33 @@ public class ExternalProcess {
process = processBuilder.start();
err = new StreamGobler(process.getErrorStream(), errStream);
out = new StreamGobler(process.getInputStream(), outStream);
exitValue = process.waitFor();
}
public ExternalProcess(File workingDir, ExternalCommand cmd, boolean captureStreams) throws IOException, InterruptedException {
if (captureStreams) {
init(workingDir, cmd, new ByteArrayOutputStream(), new ByteArrayOutputStream());
if (timeout==null) {
exitValue = process.waitFor();
} else {
init(workingDir, cmd, System.out, System.err);
if (process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
exitValue = process.exitValue();
} else {
process.destroy();
exitValue = 999; //Set some non-0 value as that is what some callers might use to determine 'failure' occurred.
throw new TimeoutException("Command timed out: "+this);
}
}
if (exitValue!=0) {
throw new IOException("Command execution failed:\n"+this);
}
}
public ExternalProcess(File workingDir, ExternalCommand cmd, boolean captureStreams, Duration timeout) throws IOException, InterruptedException, TimeoutException {
if (captureStreams) {
init(workingDir, cmd, new ByteArrayOutputStream(), new ByteArrayOutputStream(), timeout);
} else {
init(workingDir, cmd, System.out, System.err, timeout);
}
}
public ExternalProcess(File workingDir, ExternalCommand cmd, boolean captureStreams) throws IOException, InterruptedException, TimeoutException {
this(workingDir, cmd, captureStreams, null);
}
public String getOut() throws InterruptedException {
@@ -156,13 +178,13 @@ public class ExternalProcess {
result.append("exitValue = "+exitValue+"\n");
String strOut = getOut();
if (strOut!=null) {
result.append("\n------- System.out -------\n");
result.append("------- System.out -------\n");
result.append(strOut);
}
String strErr = getErr();
if (strErr!=null) {
result.append("\n------- System.err -------\n");
result.append(getOut());
result.append("------- System.err -------\n");
result.append(strErr);
}
result.append("<<<< ExternalProcess");
return result.toString();

View File

@@ -21,10 +21,12 @@ public class LanguageId {
public static final LanguageId PLAINTEXT = of("plaintext");
public static final LanguageId CONCOURSE_TASK = of("concourse-task-yaml");
public static final LanguageId CONCOURSE_PIPELINE = of("concourse-pipeline-yaml");
public static final LanguageId BOSH_DEPLOYMENT = of("bosh-deployment-manifest");
public static final LanguageId CF_MANIFEST = of("manifest-yaml");
public static final LanguageId JAVA = of("java");
public static final LanguageId YAML = of("yaml");
public static final LanguageId BOSH_DEPLOYMENT = of("bosh-deployment-manifest");
public static final LanguageId BOSH_CLOUD_CONFIG = of("bosh-cloud-config");
private final String id;