You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/03/10 23:16:00 UTC

[03/16] git commit: ACCUMULO-2447 Always set PrintWriter on Shell and don't print to stderr.

ACCUMULO-2447 Always set PrintWriter on Shell and don't print to stderr.

While we don't have access to the printwriter/outputstream from the jline
ConsoleReader, we can force the user to pass in one (or just make one for
stdout). This will allow unit tests to correctly squash all output into
a bytearray (or similar) instead of having to redirect stderr too (which
would have other repercussions).


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/e13c2733
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/e13c2733
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/e13c2733

Branch: refs/heads/1.6.0-SNAPSHOT
Commit: e13c27331a42d55408427f18d97b285372f92a47
Parents: bc9cee0
Author: Josh Elser <el...@apache.org>
Authored: Mon Mar 10 14:18:23 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Mon Mar 10 14:27:54 2014 -0400

----------------------------------------------------------------------
 .../apache/accumulo/core/util/shell/Shell.java  | 20 +++++++-------------
 .../accumulo/core/util/shell/ShellTest.java     |  4 +++-
 .../apache/accumulo/test/ShellServerTest.java   |  3 ++-
 3 files changed, 12 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/e13c2733/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index 656f2ae..6943b37 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@ -202,16 +202,14 @@ public class Shell extends ShellOptions {
   private boolean masking = false;
   
   public Shell() throws IOException {
-    this(new ConsoleReader());
+    this(new ConsoleReader(), new PrintWriter(
+        new OutputStreamWriter(System.out,
+        System.getProperty("jline.WindowsTerminal.output.encoding", System.getProperty("file.encoding")))));
   }
   
-  public Shell(ConsoleReader reader) {
+  public Shell(ConsoleReader reader, PrintWriter writer) {
     super();
     this.reader = reader;
-  }
-  
-  public Shell(ConsoleReader reader, PrintWriter writer) {
-    this(reader);
     this.writer = writer;
   }
   
@@ -943,13 +941,9 @@ public class Shell extends ShellOptions {
   }
   
   private final void printHelp(String usage, String description, Options opts, int width) {
-    PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err, Constants.UTF8));
-    new HelpFormatter().printHelp(pw, width, usage, description, opts, 2, 5, null, true);
-    pw.flush();
-    if (logErrorsToConsole && writer != null) {
-      new HelpFormatter().printHelp(writer, width, usage, description, opts, 2, 5, null, true);
-      writer.flush();
-    }
+    // TODO Use the OutputStream from the JLine ConsoleReader if we can ever get access to it
+    new HelpFormatter().printHelp(writer, width, usage, description, opts, 2, 5, null, true);
+    writer.flush();
   }
   
   public int getExitCode() {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/e13c2733/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
index 02e9543..8505370 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
@@ -24,6 +24,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 
 import jline.ConsoleReader;
 
@@ -81,7 +82,8 @@ public class ShellTest {
   public void setup() throws IOException {
     Shell.log.setLevel(Level.OFF);
     output = new TestOutputStream();
-    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)));
+    PrintWriter pw = new PrintWriter( new OutputStreamWriter(output));
+    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)), pw);
     shell.setLogErrorsToConsole();
     shell.config("--fake", "-u", "test", "-p", "secret");
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/e13c2733/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java b/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java
index 28a4dd2..e2ebbcf 100644
--- a/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/ShellServerTest.java
@@ -163,7 +163,8 @@ public class ShellServerTest {
   public void setupShell() throws Exception {
     // start the shell
     output = new TestOutputStream();
-    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)));
+    PrintWriter pw = new PrintWriter(new OutputStreamWriter(output));
+    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)), pw);
     shell.setLogErrorsToConsole();
     shell.config("-u", "root", "-p", secret, "-z", cluster.getInstanceName(), cluster.getZooKeepers());
     exec("quit", true);