You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2015/07/23 01:06:27 UTC

accumulo git commit: ACCUMULO-3940 Reuse ConsoleReader for printing help

Repository: accumulo
Updated Branches:
  refs/heads/master 430f3c699 -> 466821f5f


ACCUMULO-3940 Reuse ConsoleReader for printing help


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

Branch: refs/heads/master
Commit: 466821f5f529be9203e9f9dddf112c1c66debebd
Parents: 430f3c6
Author: Christopher Tubbs <ct...@apache.org>
Authored: Wed Jul 22 19:05:07 2015 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Jul 22 19:05:07 2015 -0400

----------------------------------------------------------------------
 .../accumulo/monitor/servlets/ShellServlet.java |  6 +---
 .../java/org/apache/accumulo/shell/Shell.java   | 35 +++++++++++++-------
 .../apache/accumulo/shell/ShellConfigTest.java  |  3 +-
 .../accumulo/shell/ShellSetInstanceTest.java    |  3 +-
 .../org/apache/accumulo/shell/ShellTest.java    |  5 +--
 .../shell/commands/HistoryCommandTest.java      |  2 +-
 .../org/apache/accumulo/test/ShellServerIT.java |  6 ++--
 7 files changed, 30 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
index 8268c4f..1f0e137 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
@@ -16,13 +16,9 @@
  */
 package org.apache.accumulo.monitor.servlets;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -266,7 +262,7 @@ public class ShellServlet extends BasicServlet {
       this.readWait = false;
       this.output = new StringBuilderOutputStream();
       ConsoleReader reader = new ConsoleReader(this, output);
-      this.shell = new Shell(reader, new PrintWriter(new OutputStreamWriter(output, UTF_8)));
+      this.shell = new Shell(reader);
       shell.setLogErrorsToConsole();
       if (mock != null) {
         if (shell.config("--fake", "-u", username, "-p", password))

http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/shell/src/main/java/org/apache/accumulo/shell/Shell.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/Shell.java b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
index 90ca08e..4734cb1 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -227,18 +227,30 @@ public class Shell extends ShellOptions implements KeywordExecutable {
   private long authTimeout;
   private long lastUserActivity = System.nanoTime();
   private boolean logErrorsToConsole = false;
-  private PrintWriter writer = null;
   private boolean masking = false;
 
+  {
+    // set the JLine output encoding to some reasonable default if it isn't already set
+    // despite the misleading property name, "input.encoding" is the property jline uses for the encoding of the output stream writer
+    String prop = "input.encoding";
+    if (System.getProperty(prop) == null) {
+      String value = System.getProperty("jline.WindowsTerminal.output.encoding");
+      if (value == null) {
+        value = System.getProperty("file.encoding");
+      }
+      if (value != null) {
+        System.setProperty(prop, value);
+      }
+    }
+  }
+
   public Shell() throws IOException {
-    this(new ConsoleReader(), new PrintWriter(new OutputStreamWriter(System.out, System.getProperty("jline.WindowsTerminal.output.encoding",
-        System.getProperty("file.encoding")))));
+    this(new ConsoleReader());
   }
 
-  public Shell(ConsoleReader reader, PrintWriter writer) {
+  public Shell(ConsoleReader reader) {
     super();
     this.reader = reader;
-    this.writer = writer;
   }
 
   /**
@@ -964,11 +976,11 @@ public class Shell extends ShellOptions implements KeywordExecutable {
 
     // The general version of this method uses the HelpFormatter
     // that comes with the apache Options package to print out the help
-    public final void printHelp(Shell shellState) {
+    public final void printHelp(Shell shellState) throws IOException {
       shellState.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp());
     }
 
-    public final void printHelp(Shell shellState, int width) {
+    public final void printHelp(Shell shellState, int width) throws IOException {
       shellState.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp(), width);
     }
 
@@ -1150,14 +1162,13 @@ public class Shell extends ShellOptions implements KeywordExecutable {
     return Logger.getLogger(Constants.CORE_PACKAGE_NAME).isTraceEnabled();
   }
 
-  private final void printHelp(String usage, String description, Options opts) {
+  private final void printHelp(String usage, String description, Options opts) throws IOException {
     printHelp(usage, description, opts, Integer.MAX_VALUE);
   }
 
-  private final void printHelp(String usage, String description, Options opts, int width) {
-    // 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();
+  private final void printHelp(String usage, String description, Options opts, int width) throws IOException {
+    new HelpFormatter().printHelp(new PrintWriter(reader.getOutput()), width, usage, description, opts, 2, 5, null, true);
+    reader.getOutput().flush();
   }
 
   public int getExitCode() {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
index 64bad82..9bfe992 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
@@ -24,7 +24,6 @@ import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.PrintStream;
-import java.io.PrintWriter;
 import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.Map;
@@ -62,7 +61,7 @@ public class ShellConfigTest {
     System.setOut(new PrintStream(output));
     config = Files.createTempFile(null, null).toFile();
 
-    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output), new PrintWriter(output));
+    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output));
     shell.setLogErrorsToConsole();
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
index 1bf03b8..e592abb 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
@@ -29,7 +29,6 @@ import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -110,7 +109,7 @@ public class ShellSetInstanceTest {
   public void setup() throws IOException {
     Shell.log.setLevel(Level.OFF);
     output = new TestOutputStream();
-    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output), new PrintWriter(output));
+    shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output));
     shell.setLogErrorsToConsole();
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
index 7a4a87e..95fdc5a 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
@@ -23,8 +23,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
 import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -131,8 +129,7 @@ public class ShellTest {
     output = new TestOutputStream();
     input = new StringInputStream();
     config = Files.createTempFile(null, null).toFile();
-    PrintWriter pw = new PrintWriter(new OutputStreamWriter(output));
-    shell = new Shell(new ConsoleReader(input, output), pw);
+    shell = new Shell(new ConsoleReader(input, output));
     shell.setLogErrorsToConsole();
     shell.config("--config-file", config.toString(), "--fake", "-u", "test", "-p", "secret");
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/shell/src/test/java/org/apache/accumulo/shell/commands/HistoryCommandTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/commands/HistoryCommandTest.java b/shell/src/test/java/org/apache/accumulo/shell/commands/HistoryCommandTest.java
index 638af3f..f5c887b 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/commands/HistoryCommandTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/commands/HistoryCommandTest.java
@@ -64,7 +64,7 @@ public class HistoryCommandTest {
     reader = new ConsoleReader(new ByteArrayInputStream(input.getBytes()), baos);
     reader.setHistory(history);
 
-    shell = new Shell(reader, null);
+    shell = new Shell(reader);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/accumulo/blob/466821f5/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
index b51e02b..621620f 100644
--- a/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.test;
 
+import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -28,7 +29,6 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
@@ -87,7 +87,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Iterators;
-import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
 
 public class ShellServerIT extends SharedMiniClusterBase {
   public static class TestOutputStream extends OutputStream {
@@ -155,8 +154,7 @@ public class ShellServerIT extends SharedMiniClusterBase {
       // start the shell
       output = new TestOutputStream();
       input = new StringInputStream();
-      PrintWriter pw = new PrintWriter(new OutputStreamWriter(output));
-      shell = new Shell(new ConsoleReader(input, output), pw);
+      shell = new Shell(new ConsoleReader(input, output));
       shell.setLogErrorsToConsole();
       if (clientConf.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
         // Pull the kerberos principal out when we're using SASL