geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r582194 - in /geronimo/sandbox/gshell/trunk: gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
Date Fri, 05 Oct 2007 10:22:24 GMT
Author: jdillon
Date: Fri Oct  5 03:22:18 2007
New Revision: 582194

URL: http://svn.apache.org/viewvc?rev=582194&view=rev
Log:
Add PromptReader to help commands read input/passwords with a prompt

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
  (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java?rev=582194&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
Fri Oct  5 03:22:18 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.console;
+
+import java.io.PrintWriter;
+import java.io.IOException;
+
+import jline.ConsoleReader;
+import jline.Terminal;
+import org.apache.geronimo.gshell.command.IO;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+
+/**
+ * Helper to prompt a user for information.
+ *
+ * @version $Rev$ $Date$
+ */
+@Component(role= PromptReader.class, instantiationStrategy="per-lookup")
+public class PromptReader
+    implements Initializable
+{
+    @Requirement
+    private Terminal terminal;
+
+    @Requirement
+    private IO io;
+
+    private char mask = '*';
+
+    private ConsoleReader reader;
+
+    public char getMask() {
+        return mask;
+    }
+
+    public void setMask(final char mask) {
+        this.mask = mask;
+    }
+
+    public void initialize() throws InitializationException {
+        try {
+            reader = new ConsoleReader(io.inputStream, new PrintWriter(io.outputStream, true),
/*bindings*/ null, terminal);
+        }
+        catch (IOException e) {
+            throw new InitializationException("Failed to create reader", e);
+        }
+    }
+
+    public String readLine(final String prompt) throws IOException {
+        assert prompt != null;
+
+        return reader.readLine(prompt);
+    }
+
+    public String readLine(final String prompt, final char mask) throws IOException {
+        assert prompt != null;
+
+        return reader.readLine(prompt, mask);
+    }
+
+    public String readPassword(final String prompt) throws IOException {
+        assert prompt != null;
+        
+        return reader.readLine(prompt, mask);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/PromptReader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java?rev=582194&r1=582193&r2=582194&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
Fri Oct  5 03:22:18 2007
@@ -19,12 +19,10 @@
 
 package org.apache.geronimo.gshell.remote.client;
 
-import java.io.PrintWriter;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 
-import jline.ConsoleReader;
 import jline.Terminal;
 import org.apache.geronimo.gshell.ExitNotification;
 import org.apache.geronimo.gshell.clp.Argument;
@@ -32,6 +30,7 @@
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.apache.geronimo.gshell.command.annotation.Requirement;
+import org.apache.geronimo.gshell.console.PromptReader;
 import org.apache.geronimo.gshell.remote.client.proxy.RemoteShellProxy;
 
 /**
@@ -62,6 +61,9 @@
     private Terminal terminal;
 
     @Requirement
+    private PromptReader prompter;
+
+    @Requirement
     private RshClient client;
 
     protected Object doExecute() throws Exception {
@@ -73,14 +75,12 @@
 
         // If the username/password was not configured via cli, then prompt the user for
the values
         if (username == null || password == null) {
-            ConsoleReader reader = new ConsoleReader(io.inputStream, new PrintWriter(io.outputStream,
true), /*bindings*/null, terminal);
-
             if (username == null) {
-                username = reader.readLine("Username: ");
+                username = prompter.readLine("Username: ");
             }
 
             if (password == null) {
-                password = reader.readLine("Password: ", '*');
+                password = prompter.readPassword("Password: ");
             }
 
             //



Mime
View raw message