Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2015-06-08 20:13:48 -0400
committerJeff Johnston2015-06-08 21:31:09 -0400
commitf7a10b4ee5ca1f9abc540a6db7d81201e4fb421c (patch)
tree2c1818da06753c182c5f5f87eab19b02a4796e04
parentfa6698377c7b9e8eeea4ba0fd4e7d57c423ce1e9 (diff)
downloadorg.eclipse.linuxtools-f7a10b4ee5ca1f9abc540a6db7d81201e4fb421c.tar.gz
org.eclipse.linuxtools-f7a10b4ee5ca1f9abc540a6db7d81201e4fb421c.tar.xz
org.eclipse.linuxtools-f7a10b4ee5ca1f9abc540a6db7d81201e4fb421c.zip
Fix Run Image not showing output for simple echo commands
- fix RunImageCommandHandler to use same console logic used in StartContainersCommandHandler - fix ImageRun Wizard to parse the command string entered for quotes and then use the cmd() interface that accepts a List<String> Change-Id: Ib515869864c26ca2eede3670e4fdffaee38fcd0f Reviewed-on: https://git.eclipse.org/r/49712 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit c65dbca1f74b863c6084ea14779659e07ad53598) Reviewed-on: https://git.eclipse.org/r/49715
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java27
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRun.java60
2 files changed, 67 insertions, 20 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
index a17e7ac069..df19eb7587 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/RunImageCommandHandler.java
@@ -11,7 +11,7 @@
package org.eclipse.linuxtools.internal.docker.ui.commands;
-import java.io.OutputStream;
+import static org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getRunConsole;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@@ -118,10 +118,14 @@ public class RunImageCommandHandler extends AbstractHandler {
final SubProgressMonitor startContainerMonitor = new SubProgressMonitor(
monitor, 1);
startContainerMonitor.beginTask("Starting container...", 1);
- final OutputStream consoleOutputStream = getConsoleOutputStream(
- connection, container, containerConfig);
+ final RunConsole console = getRunConsole(connection,
+ container);
+ if (console != null) {
+ // if we are auto-logging, show the console
+ console.showConsole();
+ }
((DockerConnection) connection).startContainer(containerId,
- hostConfig, consoleOutputStream);
+ hostConfig, console.getOutputStream());
startContainerMonitor.done();
} catch (final DockerException | InterruptedException e) {
Display.getDefault().syncExec(new Runnable() {
@@ -148,21 +152,6 @@ public class RunImageCommandHandler extends AbstractHandler {
}
- private OutputStream getConsoleOutputStream(
- final IDockerConnection connection,
- final IDockerContainer container,
- final IDockerContainerConfig containerConfig) {
- if (containerConfig.tty()) {
- final RunConsole rc = RunConsole.findConsole(container);
- if (rc != null) {
- rc.attachToConsole(connection);
- final OutputStream consoleOutputStream = rc.getOutputStream();
- return consoleOutputStream;
- }
- }
- return null;
- }
-
/**
* @param activePart
* the active {@link IWorkbenchPart}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRun.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRun.java
index d82fef8308..ddff2a2a1a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRun.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRun.java
@@ -173,7 +173,7 @@ public class ImageRun extends Wizard {
.getModel();
final Builder config = new DockerContainerConfig.Builder()
- .cmd(selectionModel.getCommand())
+ .cmd(getCmdList(selectionModel.getCommand()))
.entryPoint(selectionModel.getEntrypoint())
.image(selectionModel.getSelectedImageName())
.tty(selectionModel.isAllocatePseudoTTY())
@@ -227,4 +227,62 @@ public class ImageRun extends Wizard {
return config.build();
}
+ // Create a proper command list after handling quotation.
+ private List<String> getCmdList(String s) {
+ ArrayList<String> list = new ArrayList<>();
+ int length = s.length();
+ boolean insideQuote1 = false; // single-quote
+ boolean insideQuote2 = false; // double-quote
+ boolean escaped = false;
+ StringBuffer buffer = new StringBuffer();
+ // Parse the string and break it up into chunks that are
+ // separated by white-space or are quoted. Ignore characters
+ // that have been escaped, including the escape character.
+ for (int i = 0; i < length; ++i) {
+ char c = s.charAt(i);
+ if (escaped) {
+ buffer.append(c);
+ escaped = false;
+ }
+ switch (c) {
+ case '\'':
+ if (!insideQuote2)
+ insideQuote1 = insideQuote1 ^ true;
+ else
+ buffer.append(c);
+ break;
+ case '\"':
+ if (!insideQuote1)
+ insideQuote2 = insideQuote2 ^ true;
+ else
+ buffer.append(c);
+ break;
+ case '\\':
+ escaped = true;
+ break;
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ if (insideQuote1 || insideQuote2)
+ buffer.append(c);
+ else {
+ String item = buffer.toString();
+ buffer.setLength(0);
+ if (item.length() > 0)
+ list.add(item);
+ }
+ break;
+ default:
+ buffer.append(c);
+ break;
+ }
+ }
+ // add last item of string that will be in the buffer
+ String item = buffer.toString();
+ if (item.length() > 0)
+ list.add(item);
+ return list;
+ }
+
}

Back to the top