accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1345368 - in /accumulo/trunk/core/src: main/java/org/apache/accumulo/core/client/mock/ main/java/org/apache/accumulo/core/util/shell/ main/java/org/apache/accumulo/core/util/shell/commands/ test/java/org/apache/accumulo/core/util/shell/
Date Fri, 01 Jun 2012 22:04:31 GMT
Author: billie
Date: Fri Jun  1 22:04:30 2012
New Revision: 1345368

URL: http://svn.apache.org/viewvc?rev=1345368&view=rev
Log:
ACCUMULO-196 prep shell for new shell servlet

Modified:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateUserCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DebugCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TraceCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockShell.java
Fri Jun  1 22:04:30 2012
@@ -28,8 +28,7 @@ import org.apache.accumulo.core.util.she
 import org.apache.commons.cli.CommandLine;
 
 /**
- * An Accumulo Shell implementation that allows a developer to attach
- * an InputStream and Writer to the Shell for testing purposes.
+ * An Accumulo Shell implementation that allows a developer to attach an InputStream and
Writer to the Shell for testing purposes.
  */
 public class MockShell extends Shell {
   private static final String NEWLINE = "\n";
@@ -43,14 +42,13 @@ public class MockShell extends Shell {
     this.writer = writer;
   }
   
-  public void config(String... args) {
-    super.config(args);
+  public boolean config(String... args) {
+    configError = super.config(args);
     
     // Update the ConsoleReader with the input and output "redirected"
     try {
       this.reader = new ConsoleReader(in, writer);
-    }
-    catch (Exception e) {
+    } catch (Exception e) {
       printException(e);
       configError = true;
     }
@@ -61,8 +59,9 @@ public class MockShell extends Shell {
     
     // Make the parsing from the client easier;
     this.verbose = false;
+    return configError;
   }
-
+  
   @Override
   protected void setInstance(CommandLine cl) {
     // We always want a MockInstance for this test
@@ -89,7 +88,7 @@ public class MockShell extends Shell {
     }
     
     while (true) {
-      if (exit)
+      if (hasExited())
         return exitCode;
       
       reader.setDefaultPrompt(getDefaultPrompt());
@@ -104,14 +103,16 @@ public class MockShell extends Shell {
   }
   
   /**
-   * @param in the in to set
+   * @param in
+   *          the in to set
    */
   public void setConsoleInputStream(InputStream in) {
     this.in = in;
   }
-
+  
   /**
-   * @param writer the writer to set
+   * @param writer
+   *          the writer to set
    */
   public void setConsoleWriter(Writer writer) {
     this.writer = writer;
@@ -119,7 +120,8 @@ public class MockShell extends Shell {
   
   /**
    * Convenience method to create the byte-array to hand to the console
-   * @param commands 
+   * 
+   * @param commands
    *          An array of commands to run
    * @return A byte[] input stream which can be handed to the console.
    */

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java Fri Jun
 1 22:04:30 2012
@@ -170,7 +170,7 @@ public class Shell extends ShellOptions 
   protected boolean configError = false;
   
   // exit if true
-  protected boolean exit = false;
+  private boolean exit = false;
   
   // file to execute commands from
   protected String execFile = null;
@@ -182,10 +182,12 @@ public class Shell extends ShellOptions 
   private boolean disableAuthTimeout;
   private long authTimeout;
   private long lastUserActivity = System.currentTimeMillis();
+  private boolean logErrorsToConsole = false;
+  private PrintWriter writer = null;
+  private boolean masking = false;
   
   public Shell() throws IOException {
-    super();
-    this.reader = new ConsoleReader();
+    this(new ConsoleReader());
   }
   
   public Shell(ConsoleReader reader) {
@@ -193,8 +195,13 @@ public class Shell extends ShellOptions 
     this.reader = reader;
   }
   
+  public Shell(ConsoleReader reader, PrintWriter writer) {
+    this(reader);
+    this.writer = writer;
+  }
+  
   // Not for client use
-  public void config(String... args) {
+  public boolean config(String... args) {
     
     CommandLine cl;
     try {
@@ -205,7 +212,7 @@ public class Shell extends ShellOptions 
       if (cl.hasOption(helpOpt.getOpt())) {
         configError = true;
         printHelp("shell", SHELL_DESCRIPTION, opts);
-        return;
+        return true;
       }
       
       setDebugging(cl.hasOption(debugOption.getLongOpt()));
@@ -219,7 +226,7 @@ public class Shell extends ShellOptions 
       configError = true;
       printException(e);
       printHelp("shell", SHELL_DESCRIPTION, opts);
-      return;
+      return true;
     }
     
     // get the options that were parsed
@@ -249,11 +256,11 @@ public class Shell extends ShellOptions 
       });
       
       if (passw == null)
-        passw = reader.readLine("Enter current password for '" + user + "'@'" + instance.getInstanceName()
+ "': ", '*');
+        passw = readMaskedLine("Enter current password for '" + user + "'@'" + instance.getInstanceName()
+ "': ", '*');
       if (passw == null) {
         reader.printNewline();
         configError = true;
-        return;
+        return true;
       } // user canceled
       
       pass = passw.getBytes();
@@ -317,6 +324,7 @@ public class Shell extends ShellOptions 
     for (Command cmd : otherCommands) {
       commandFactory.put(cmd.getName(), cmd);
     }
+    return configError;
   }
   
   @SuppressWarnings("deprecation")
@@ -390,7 +398,7 @@ public class Shell extends ShellOptions 
     }
     
     while (true) {
-      if (exit)
+      if (hasExited())
         return exitCode;
       
       // If tab completion is true we need to reset
@@ -417,6 +425,7 @@ public class Shell extends ShellOptions 
     reader.printString("\n" + SHELL_DESCRIPTION + "\n" + "- \n" + "- version: " + Constants.VERSION
+ "\n" + "- instance name: "
         + connector.getInstance().getInstanceName() + "\n" + "- instance id: " + connector.getInstance().getInstanceID()
+ "\n" + "- \n"
         + "- type 'help' for a list of available commands\n" + "- \n");
+    reader.flushConsole();
   }
   
   public void printVerboseInfo() throws IOException {
@@ -446,7 +455,7 @@ public class Shell extends ShellOptions 
     reader.printString(sb.toString());
   }
   
-  protected String getDefaultPrompt() {
+  public String getDefaultPrompt() {
     return connector.whoami() + "@" + connector.getInstance().getInstanceName() + (getTableName().isEmpty()
? "" : " ") + getTableName() + "> ";
   }
   
@@ -479,6 +488,7 @@ public class Shell extends ShellOptions 
         sc = commandFactory.get(command);
         if (sc == null) {
           reader.printString(String.format("Unknown command \"%s\".  Enter \"help\" for a
list possible commands.\n", command));
+          reader.flushConsole();
           return;
         }
         
@@ -486,7 +496,7 @@ public class Shell extends ShellOptions 
           reader.printString("Shell has been idle for too long. Please re-authenticate.\n");
           boolean authFailed = true;
           do {
-            String pwd = reader.readLine("Enter current password for '" + connector.whoami()
+ "': ", '*');
+            String pwd = readMaskedLine("Enter current password for '" + connector.whoami()
+ "': ", '*');
             if (pwd == null) {
               reader.printNewline();
               return;
@@ -515,7 +525,7 @@ public class Shell extends ShellOptions 
         int expectedArgLen = sc.numArgs();
         if (cl.hasOption(helpOption)) {
           // Display help if asked to; otherwise execute the command
-          sc.printHelp();
+          sc.printHelp(this);
         } else if (expectedArgLen != NO_FIXED_ARG_LENGTH_CHECK && actualArgLen !=
expectedArgLen) {
           ++exitCode;
           // Check for valid number of fixed arguments (if not
@@ -523,7 +533,7 @@ public class Shell extends ShellOptions 
           // vararg-like commands)
           printException(new IllegalArgumentException(String.format("Expected %d argument%s.
There %s %d.", expectedArgLen, expectedArgLen == 1 ? "" : "s",
               actualArgLen == 1 ? "was" : "were", actualArgLen)));
-          sc.printHelp();
+          sc.printHelp(this);
         } else {
           int tmpCode = sc.execute(input, cl, this);
           exitCode += tmpCode;
@@ -546,7 +556,7 @@ public class Shell extends ShellOptions 
           printException(e);
         }
         if (sc != null)
-          sc.printHelp();
+          sc.printHelp(this);
       } catch (Exception e) {
         ++exitCode;
         printException(e);
@@ -555,6 +565,7 @@ public class Shell extends ShellOptions 
       ++exitCode;
       printException(new BadArgumentException("Unrecognized empty command", command, -1));
     }
+    reader.flushConsole();
   }
   
   /**
@@ -683,12 +694,12 @@ public class Shell extends ShellOptions 
     
     // 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.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp());
+    public final void printHelp(Shell shellState) {
+      shellState.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp());
     }
     
-    public final void printHelp(int width) {
-      Shell.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp(),
width);
+    public final void printHelp(Shell shellState, int width) {
+      shellState.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp(),
width);
     }
     
     // Get options with help
@@ -829,20 +840,20 @@ public class Shell extends ShellOptions 
     printException(cve, "");
     int COL1 = 50, COL2 = 14;
     int col3 = Math.max(1, Math.min(Integer.MAX_VALUE, reader.getTermwidth() - COL1 - COL2
- 6));
-    log.error(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s\n", repeat("-",
COL1), repeat("-", COL2), repeat("-", col3)));
-    log.error(String.format("%-" + COL1 + "s | %" + COL2 + "s | %-" + col3 + "s\n", "Constraint
class", "Violation code", "Violation Description"));
-    log.error(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s\n", repeat("-",
COL1), repeat("-", COL2), repeat("-", col3)));
+    logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s\n", repeat("-",
COL1), repeat("-", COL2), repeat("-", col3)));
+    logError(String.format("%-" + COL1 + "s | %" + COL2 + "s | %-" + col3 + "s\n", "Constraint
class", "Violation code", "Violation Description"));
+    logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s\n", repeat("-",
COL1), repeat("-", COL2), repeat("-", col3)));
     for (TConstraintViolationSummary cvs : cve.violationSummaries)
-      log.error(String.format("%-" + COL1 + "s | %" + COL2 + "d | %-" + col3 + "s\n", cvs.constrainClass,
cvs.violationCode, cvs.violationDescription));
-    log.error(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s\n", repeat("-",
COL1), repeat("-", COL2), repeat("-", col3)));
+      logError(String.format("%-" + COL1 + "s | %" + COL2 + "d | %-" + col3 + "s\n", cvs.constrainClass,
cvs.violationCode, cvs.violationDescription));
+    logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s\n", repeat("-",
COL1), repeat("-", COL2), repeat("-", col3)));
   }
   
-  public static final void printException(Exception e) {
+  public final void printException(Exception e) {
     printException(e, e.getMessage());
   }
   
-  private static final void printException(Exception e, String msg) {
-    log.error(e.getClass().getName() + (msg != null ? ": " + msg : ""));
+  private final void printException(Exception e, String msg) {
+    logError(e.getClass().getName() + (msg != null ? ": " + msg : ""));
     log.debug(e.getClass().getName() + (msg != null ? ": " + msg : ""), e);
   }
   
@@ -854,14 +865,18 @@ public class Shell extends ShellOptions 
     return Logger.getLogger(Constants.CORE_PACKAGE_NAME).isTraceEnabled();
   }
   
-  private static final void printHelp(String usage, String description, Options opts) {
+  private final void printHelp(String usage, String description, Options opts) {
     printHelp(usage, description, opts, Integer.MAX_VALUE);
   }
   
-  private static final void printHelp(String usage, String description, Options opts, int
width) {
+  private final void printHelp(String usage, String description, Options opts, int width)
{
     PrintWriter pw = new PrintWriter(System.err);
     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();
+    }
   }
   
   public int getExitCode() {
@@ -921,10 +936,39 @@ public class Shell extends ShellOptions 
     Class<? extends Formatter> formatter = FormatterCommand.getCurrentFormatter(tableName,
this);
     
     if (null == formatter) {
-      log.error("Could not load the specified formatter. Using the DefaultFormatter");
+      logError("Could not load the specified formatter. Using the DefaultFormatter");
       return this.defaultFormatterClass;
     } else {
       return formatter;
     }
   }
+  
+  public void setLogErrorsToConsole() {
+    this.logErrorsToConsole = true;
+  }
+  
+  private void logError(String s) {
+    log.error(s);
+    if (logErrorsToConsole) {
+      try {
+        reader.printString("ERROR: " + s + "\n");
+        reader.flushConsole();
+      } catch (IOException e) {}
+    }
+  }
+  
+  public String readMaskedLine(String prompt, Character mask) throws IOException {
+    this.masking = true;
+    String s = reader.readLine(prompt, mask);
+    this.masking = false;
+    return s;
+  }
+  
+  public boolean isMasking() {
+    return masking;
+  }
+  
+  public boolean hasExited() {
+    return exit;
+  }
 }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
Fri Jun  1 22:04:30 2012
@@ -31,7 +31,7 @@ public class AuthenticateCommand extends
   @Override
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException,
AccumuloSecurityException, IOException {
     String user = cl.getArgs()[0];
-    String p = shellState.getReader().readLine("Enter current password for '" + user + "':
", '*');
+    String p = shellState.readMaskedLine("Enter current password for '" + user + "': ", '*');
     if (p == null) {
       shellState.getReader().printNewline();
       return 0;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateUserCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateUserCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateUserCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateUserCommand.java
Fri Jun  1 22:04:30 2012
@@ -46,12 +46,12 @@ public class CreateUserCommand extends C
     String password = null;
     String passwordConfirm = null;
     
-    password = shellState.getReader().readLine("Enter new password for '" + user + "': ",
'*');
+    password = shellState.readMaskedLine("Enter new password for '" + user + "': ", '*');
     if (password == null) {
       shellState.getReader().printNewline();
       return 0;
     } // user canceled
-    passwordConfirm = shellState.getReader().readLine("Please confirm new password for '"
+ user + "': ", '*');
+    passwordConfirm = shellState.readMaskedLine("Please confirm new password for '" + user
+ "': ", '*');
     if (passwordConfirm == null) {
       shellState.getReader().printNewline();
       return 0;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DebugCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DebugCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DebugCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DebugCommand.java
Fri Jun  1 22:04:30 2012
@@ -39,8 +39,8 @@ public class DebugCommand extends Comman
     } else if (cl.getArgs().length == 0) {
       shellState.getReader().printString(Shell.isDebuggingEnabled() ? "on\n" : "off\n");
     } else {
-      Shell.printException(new IllegalArgumentException("Expected 0 or 1 argument. There
were " + cl.getArgs().length + "."));
-      printHelp();
+      shellState.printException(new IllegalArgumentException("Expected 0 or 1 argument. There
were " + cl.getArgs().length + "."));
+      printHelp(shellState);
       return 1;
     }
     return 0;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
Fri Jun  1 22:04:30 2012
@@ -89,7 +89,7 @@ public class HelpCommand extends Command
       if (c == null)
         shellState.getReader().printString(String.format("Unknown command \"%s\".  Enter
\"help\" for a list possible commands.\n", cmd));
       else
-        c.printHelp(numColumns);
+        c.printHelp(shellState, numColumns);
     }
     return 0;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
Fri Jun  1 22:04:30 2012
@@ -41,7 +41,7 @@ public class PasswdCommand extends Comma
     String passwordConfirm = null;
     String oldPassword = null;
     
-    oldPassword = shellState.getReader().readLine("Enter current password for '" + currentUser
+ "': ", '*');
+    oldPassword = shellState.readMaskedLine("Enter current password for '" + currentUser
+ "': ", '*');
     if (oldPassword == null) {
       shellState.getReader().printNewline();
       return 0;
@@ -50,12 +50,12 @@ public class PasswdCommand extends Comma
     if (!shellState.getConnector().securityOperations().authenticateUser(currentUser, oldPassword.getBytes()))
       throw new AccumuloSecurityException(user, SecurityErrorCode.BAD_CREDENTIALS);
     
-    password = shellState.getReader().readLine("Enter new password for '" + user + "': ",
'*');
+    password = shellState.readMaskedLine("Enter new password for '" + user + "': ", '*');
     if (password == null) {
       shellState.getReader().printNewline();
       return 0;
     } // user canceled
-    passwordConfirm = shellState.getReader().readLine("Please confirm new password for '"
+ user + "': ", '*');
+    passwordConfirm = shellState.readMaskedLine("Please confirm new password for '" + user
+ "': ", '*');
     if (passwordConfirm == null) {
       shellState.getReader().printNewline();
       return 0;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
Fri Jun  1 22:04:30 2012
@@ -152,11 +152,13 @@ public class SetIterCommand extends Comm
       if (itopts.getNamedOptions() != null) {
         for (Entry<String,String> e : itopts.getNamedOptions().entrySet()) {
           prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " parameter " +
e.getKey() + ", " + e.getValue() + ": ";
-          
+          reader.flushConsole();
           input = reader.readLine(prompt);
           if (input == null) {
             reader.printNewline();
             throw new IOException("Input stream closed");
+          } else {
+            input = new String(input);
           }
           // Places all Parameters and Values into the LocalOptions, even if the value is
"".
           // This allows us to check for "" values when setting the iterators and allows
us to remove
@@ -172,10 +174,13 @@ public class SetIterCommand extends Comm
           while (true) {
             prompt = Shell.repeat("-", 10) + "> set " + shortClassName + " option (<name>
<value>, hit enter to skip): ";
             
+            reader.flushConsole();
             input = reader.readLine(prompt);
             if (input == null) {
               reader.printNewline();
               throw new IOException("Input stream closed");
+            } else {
+              input = new String(input);
             }
             
             if (input.length() == 0)

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TraceCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TraceCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TraceCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TraceCommand.java
Fri Jun  1 22:04:30 2012
@@ -32,7 +32,6 @@ import org.apache.accumulo.core.util.she
 import org.apache.commons.cli.CommandLine;
 import org.apache.hadoop.io.Text;
 
-
 public class TraceCommand extends DebugCommand {
   
   public int execute(String fullCommand, CommandLine cl, final Shell shellState) throws IOException
{
@@ -66,7 +65,7 @@ public class TraceCommand extends DebugC
                 break;
               }
             } catch (Exception ex) {
-              Shell.printException(ex);
+              shellState.printException(ex);
             }
             shellState.getReader().printString("Waiting for trace information\n");
             shellState.getReader().flushConsole();
@@ -80,8 +79,8 @@ public class TraceCommand extends DebugC
     } else if (cl.getArgs().length == 0) {
       shellState.getReader().printString(Trace.isTracing() ? "on\n" : "off\n");
     } else {
-      Shell.printException(new IllegalArgumentException("Expected 0 or 1 argument. There
were " + cl.getArgs().length + "."));
-      printHelp();
+      shellState.printException(new IllegalArgumentException("Expected 0 or 1 argument. There
were " + cl.getArgs().length + "."));
+      printHelp(shellState);
       return 1;
     }
     return 0;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
Fri Jun  1 22:04:30 2012
@@ -38,7 +38,7 @@ public class UserCommand extends Command
     // We can't let the wrapping try around the execute method deal
     // with the exceptions because we have to do something if one
     // of these methods fails
-    String p = shellState.getReader().readLine("Enter password for user " + user + ": ",
'*');
+    String p = shellState.readMaskedLine("Enter password for user " + user + ": ", '*');
     if (p == null) {
       shellState.getReader().printNewline();
       return 0;

Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java?rev=1345368&r1=1345367&r2=1345368&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java (original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java Fri
Jun  1 22:04:30 2012
@@ -32,7 +32,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class ShellTest {
-  class TestOutputStream extends OutputStream {
+  static class TestOutputStream extends OutputStream {
     StringBuilder sb = new StringBuilder();
     
     @Override
@@ -62,7 +62,7 @@ public class ShellTest {
     if (expectGoodExit)
       assertGoodExit("", true);
     else
-      assertBadExit();
+      assertBadExit("", true);
   }
   
   void exec(String cmd, boolean expectGoodExit, String expectString) throws IOException {
@@ -74,7 +74,7 @@ public class ShellTest {
     if (expectGoodExit)
       assertGoodExit(expectString, stringPresent);
     else
-      assertBadExit();
+      assertBadExit(expectString, stringPresent);
   }
   
   @Before
@@ -82,6 +82,7 @@ public class ShellTest {
     Shell.log.setLevel(Level.OFF);
     output = new TestOutputStream();
     shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)));
+    shell.setLogErrorsToConsole();
     shell.config("--fake", "-p", "pass");
   }
   
@@ -92,9 +93,11 @@ public class ShellTest {
       assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent,
output.get().contains(s));
   }
   
-  void assertBadExit() {
+  void assertBadExit(String s, boolean stringPresent) {
     Shell.log.debug(output.get());
     assertTrue(shell.getExitCode() > 0);
+    if (s.length() > 0)
+      assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent,
output.get().contains(s));
     shell.resetExitCode();
   }
   
@@ -103,13 +106,13 @@ public class ShellTest {
     Shell.log.debug("Starting about test -----------------------------------");
     exec("about", true, "Shell - Apache Accumulo Interactive Shell");
     exec("about -v", true, "Current user:");
-    exec("about arg", false);
+    exec("about arg", false, "java.lang.IllegalArgumentException: Expected 0 arguments");
   }
   
   @Test
   public void addGetSplitsTest() throws IOException {
     Shell.log.debug("Starting addGetSplits test ----------------------------");
-    exec("addsplits arg", false);
+    exec("addsplits arg", false, "java.lang.IllegalStateException: Not in a table context");
     exec("createtable test", true);
     exec("addsplits 1 \\x80", true);
     exec("getsplits", true, "1\n\\x80");
@@ -119,8 +122,8 @@ public class ShellTest {
   @Test
   public void insertDeleteScanTest() throws IOException {
     Shell.log.debug("Starting insertDeleteScan test ------------------------");
-    exec("insert r f q v", false);
-    exec("delete r f q", false);
+    exec("insert r f q v", false, "java.lang.IllegalStateException: Not in a table context");
+    exec("delete r f q", false, "java.lang.IllegalStateException: Not in a table context");
     exec("createtable test", true);
     exec("insert r f q v", true);
     exec("scan", true, "r f:q []    v");



Mime
View raw message