From 11cd1ab0fd58298f0a902f42306e909e3a4801b5 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Tue, 6 Dec 2016 02:48:45 +0100 Subject: [PATCH] Give commands access to input stream. Some commands may read additional data from a user. In this case, they should have access to the input stream provided by the console for further processing. Signed-off-by: Gunnar Wagenknecht --- .../calculator/internal/CalculatorComponentFactory.java | 4 +++- .../core/pdetest/console/TestConsoleComponentFactory.java | 4 +++- .../codeaffine/console/core/ConsoleComponentFactory.java | 4 +++- .../core/internal/GenericConsoleComponentFactory.java | 5 +++-- .../src/com/codeaffine/console/core/internal/Input.java | 7 ++++++- .../codeaffine/console/core/internal/ProcessorWorker.java | 3 ++- .../gonsole/internal/GitConsoleComponentFactory.java | 4 +++- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/com.codeaffine.console.calculator/src/com/codeaffine/console/calculator/internal/CalculatorComponentFactory.java b/com.codeaffine.console.calculator/src/com/codeaffine/console/calculator/internal/CalculatorComponentFactory.java index 75b1f6f8..0bd68d25 100644 --- a/com.codeaffine.console.calculator/src/com/codeaffine/console/calculator/internal/CalculatorComponentFactory.java +++ b/com.codeaffine.console.calculator/src/com/codeaffine/console/calculator/internal/CalculatorComponentFactory.java @@ -1,5 +1,7 @@ package com.codeaffine.console.calculator.internal; +import java.io.InputStream; + import com.codeaffine.console.core.ConsoleCommandInterpreter; import com.codeaffine.console.core.ConsoleComponentFactory; import com.codeaffine.console.core.ConsoleOutput; @@ -20,7 +22,7 @@ public ConsolePrompt createConsolePrompt( ConsoleOutput consoleOutput ) { } @Override - public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ) { + public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) { return new ConsoleCommandInterpreter[] { new CalculatorConsoleCommandInterpreter( stdOut ) }; } diff --git a/com.codeaffine.console.core.pdetest/src/com/codeaffine/console/core/pdetest/console/TestConsoleComponentFactory.java b/com.codeaffine.console.core.pdetest/src/com/codeaffine/console/core/pdetest/console/TestConsoleComponentFactory.java index 259d2be9..8ed11162 100644 --- a/com.codeaffine.console.core.pdetest/src/com/codeaffine/console/core/pdetest/console/TestConsoleComponentFactory.java +++ b/com.codeaffine.console.core.pdetest/src/com/codeaffine/console/core/pdetest/console/TestConsoleComponentFactory.java @@ -1,5 +1,7 @@ package com.codeaffine.console.core.pdetest.console; +import java.io.InputStream; + import com.codeaffine.console.core.ConsoleCommandInterpreter; import com.codeaffine.console.core.ConsoleComponentFactory; import com.codeaffine.console.core.ConsoleOutput; @@ -15,7 +17,7 @@ public ConsolePrompt createConsolePrompt( final ConsoleOutput consoleOutput ) { } @Override - public ConsoleCommandInterpreter[] createCommandInterpreters( final ConsoleOutput stdOut, ConsoleOutput errorOut ) { + public ConsoleCommandInterpreter[] createCommandInterpreters( final ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) { return new ConsoleCommandInterpreter[] { new TestConsoleCommandInterpreter( stdOut ) }; } diff --git a/com.codeaffine.console.core/src/com/codeaffine/console/core/ConsoleComponentFactory.java b/com.codeaffine.console.core/src/com/codeaffine/console/core/ConsoleComponentFactory.java index f8064c93..91f385be 100644 --- a/com.codeaffine.console.core/src/com/codeaffine/console/core/ConsoleComponentFactory.java +++ b/com.codeaffine.console.core/src/com/codeaffine/console/core/ConsoleComponentFactory.java @@ -1,10 +1,12 @@ package com.codeaffine.console.core; +import java.io.InputStream; + import com.codeaffine.console.core.history.HistoryTracker; public interface ConsoleComponentFactory { - ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ); + ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ); ConsolePrompt createConsolePrompt( ConsoleOutput consoleOutput ); ContentProposalProvider[] createProposalProviders(); HistoryTracker getHistoryTracker(); diff --git a/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/GenericConsoleComponentFactory.java b/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/GenericConsoleComponentFactory.java index 7990a991..9d8986a2 100644 --- a/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/GenericConsoleComponentFactory.java +++ b/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/GenericConsoleComponentFactory.java @@ -1,5 +1,6 @@ package com.codeaffine.console.core.internal; +import java.io.InputStream; import java.util.stream.Stream; import com.codeaffine.console.core.ConsoleCommandInterpreter; @@ -37,8 +38,8 @@ public ConsolePrompt createConsolePrompt( ConsoleOutput consoleOutput ) { } @Override - public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ) { - ConsoleCommandInterpreter[] result = consoleComponentFactory.createCommandInterpreters( stdOut, errorOut ); + public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) { + ConsoleCommandInterpreter[] result = consoleComponentFactory.createCommandInterpreters( stdOut, errorOut, stdIn ); if( getHistoryTracker() != null ) { result = Stream.concat( Stream.of( getHistoryTracker() ), Stream.of( result ) ).toArray( ConsoleCommandInterpreter[]::new ); } diff --git a/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/Input.java b/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/Input.java index 494c35ce..ab6e812a 100644 --- a/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/Input.java +++ b/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/Input.java @@ -2,6 +2,7 @@ import static com.codeaffine.console.core.ConsoleConstants.ENCODING; +import java.io.InputStream; import java.util.NoSuchElementException; import java.util.Scanner; @@ -17,7 +18,7 @@ public Input( ConsoleIoProvider consoleIoProvider ) { @SuppressWarnings("resource") public String readLine() { - Scanner scanner = new Scanner( consoleIOProvider.getInputStream(), ENCODING.name() ); + Scanner scanner = new Scanner( getInputStream(), ENCODING.name() ); String result; try { result = scanner.nextLine(); @@ -26,4 +27,8 @@ public String readLine() { } return result; } + + public InputStream getInputStream() { + return consoleIOProvider.getInputStream(); + } } \ No newline at end of file diff --git a/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/ProcessorWorker.java b/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/ProcessorWorker.java index 97062125..2b29fcda 100644 --- a/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/ProcessorWorker.java +++ b/com.codeaffine.console.core/src/com/codeaffine/console/core/internal/ProcessorWorker.java @@ -67,7 +67,8 @@ public void run() { private ConsoleCommandInterpreter[] createCommandInterpreters() { return consoleComponentFactory.createCommandInterpreters( consoleStandardOutput, - consoleErrorOutput ); + consoleErrorOutput, + consoleInput.getInputStream() ); } private static void printStackTrace( ConsoleOutput consoleOutput, Exception exception ) { diff --git a/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/GitConsoleComponentFactory.java b/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/GitConsoleComponentFactory.java index 9cb5ecfb..413c6bfb 100644 --- a/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/GitConsoleComponentFactory.java +++ b/com.codeaffine.gonsole/src/com/codeaffine/gonsole/internal/GitConsoleComponentFactory.java @@ -2,6 +2,8 @@ import static com.codeaffine.gonsole.internal.activator.IconRegistry.GIT_PROPOSAL; +import java.io.InputStream; + import org.eclipse.jface.resource.ImageDescriptor; import com.codeaffine.console.core.ConsoleCommandInterpreter; @@ -29,7 +31,7 @@ class GitConsoleComponentFactory implements ConsoleComponentFactory { } @Override - public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut ) { + public ConsoleCommandInterpreter[] createCommandInterpreters( ConsoleOutput stdOut, ConsoleOutput errorOut, InputStream stdIn ) { return new ConsoleCommandInterpreter[]{ new ControlCommandInterpreter( this, stdOut, errorOut, repositoryProvider ), new GitCommandInterpreter( stdOut, repositoryProvider )