felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r792544 - in /felix/trunk/karaf/gshell: gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/ gshell-ssh/src/main/java/org/apache/felix/karaf/gshell/ssh/
Date Thu, 09 Jul 2009 13:15:36 GMT
Author: gnodet
Date: Thu Jul  9 13:15:36 2009
New Revision: 792544

URL: http://svn.apache.org/viewvc?rev=792544&view=rev
Log:
Fix the session input stream which should use the console input stream

Modified:
    felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
    felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/ConsoleFactory.java
    felix/trunk/karaf/gshell/gshell-ssh/src/main/java/org/apache/felix/karaf/gshell/ssh/ShellFactoryImpl.java

Modified: felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java?rev=792544&r1=792543&r2=792544&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
(original)
+++ felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/Console.java
Thu Jul  9 13:15:36 2009
@@ -21,6 +21,7 @@
 import jline.*;
 import org.osgi.service.command.CommandSession;
 import org.osgi.service.command.Converter;
+import org.osgi.service.command.CommandProcessor;
 import org.apache.felix.karaf.gshell.console.ansi.AnsiOutputStream;
 import org.apache.felix.karaf.gshell.console.Completer;
 
@@ -28,6 +29,7 @@
 import java.io.InputStream;
 import java.io.InterruptedIOException;
 import java.io.PrintWriter;
+import java.io.PrintStream;
 import java.lang.reflect.Method;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
@@ -47,26 +49,30 @@
     private boolean running;
     private Runnable closeCallback;
     private Terminal terminal;
-
-    public Console(CommandSession session, Terminal term) throws Exception
-    {
-        this(session, term, null);
-    }
-
-    public Console(CommandSession session, Terminal term, Completer completer) throws Exception
-    {
-        this(session, term, completer, null);
-    }
-
-    public Console(CommandSession session, Terminal term, Completer completer, Runnable closeCallback)
throws Exception
-    {
-        this.session = session;
+    private InputStream consoleInput;
+    private InputStream in;
+    private PrintStream out;
+    private PrintStream err;
+
+    public Console(CommandProcessor processor,
+                   InputStream in,
+                   PrintStream out,
+                   PrintStream err,
+                   Terminal term,
+                   Completer completer,
+                   Runnable closeCallback) throws Exception
+    {
+        this.in = in;
+        this.out = out;
+        this.err = err;
+        this.consoleInput = new ConsoleInputStream();
+        this.session = processor.createSession(this.consoleInput, this.out, this.err);
         this.terminal = term == null ? new UnsupportedTerminal() : term;
         this.closeCallback = closeCallback;
-        reader = new ConsoleReader(new ConsoleInputStream(),
-                                   new PrintWriter(session.getConsole()),
+        reader = new ConsoleReader(this.consoleInput,
+                                   new PrintWriter(this.out),
                                    getClass().getResourceAsStream("keybinding.properties"),
-                                   terminal);
+                                   this.terminal);
         if (completer != null) {
             reader.addCompletor(new CompleterAsCompletor(completer));
         }
@@ -75,6 +81,10 @@
         pipe.setDaemon(true);
     }
 
+    public CommandSession getSession() {
+        return session;
+    }
+
     public void close() {
         //System.err.println("Closing");
         running = false;
@@ -217,7 +227,6 @@
         public void run()
         {
             try {
-                InputStream in = session.getKeyboard();
                 while (running)
                 {
                     try
@@ -226,13 +235,13 @@
                         if (c == -1 || c == 4)
                         {
                             //System.err.println("Received  " + c + " ... closing");
-                            session.getConsole().println("^D");
+                            err.println("^D");
                             queue.put(c);
                             return;
                         }
                         else if (c == 3)
                         {
-                            session.getConsole().println("^C");
+                            err.println("^C");
                             reader.getCursorBuffer().clearBuffer();
                             interrupt();
                             queue.put(c);

Modified: felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/ConsoleFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/ConsoleFactory.java?rev=792544&r1=792543&r2=792544&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/ConsoleFactory.java
(original)
+++ felix/trunk/karaf/gshell/gshell-console/src/main/java/org/apache/felix/karaf/gshell/console/jline/ConsoleFactory.java
Thu Jul  9 13:15:36 2009
@@ -71,10 +71,6 @@
             InputStream in = unwrap(System.in);
             PrintStream out = unwrap(System.out);
             PrintStream err = unwrap(System.err);
-            CommandSession session = this.commandProcessor.createSession(
-                    in, new PrintStream(new AnsiOutputStream(out)), new PrintStream(new AnsiOutputStream(err)));
-            session.put("USER", "karaf");
-            session.put("APPLICATION", System.getProperty("karaf.name", "root"));
             Runnable callback = new Runnable() {
                 public void run() {
                     try {
@@ -84,7 +80,10 @@
                     }
                 }
             };
-            this.console = new Console(session, terminal, new AggregateCompleter(completers),
callback);
+            this.console = new Console(commandProcessor, in, out, err, terminal, new AggregateCompleter(completers),
callback);
+            CommandSession session = console.getSession();
+            session.put("USER", "karaf");
+            session.put("APPLICATION", System.getProperty("karaf.name", "root"));
             new Thread(console, "Karaf Shell Console Thread").start();
         }
     }

Modified: felix/trunk/karaf/gshell/gshell-ssh/src/main/java/org/apache/felix/karaf/gshell/ssh/ShellFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-ssh/src/main/java/org/apache/felix/karaf/gshell/ssh/ShellFactoryImpl.java?rev=792544&r1=792543&r2=792544&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-ssh/src/main/java/org/apache/felix/karaf/gshell/ssh/ShellFactoryImpl.java
(original)
+++ felix/trunk/karaf/gshell/gshell-ssh/src/main/java/org/apache/felix/karaf/gshell/ssh/ShellFactoryImpl.java
Thu Jul  9 13:15:36 2009
@@ -86,12 +86,10 @@
 
         public void start(final Environment env) throws IOException {
             try {
-                CommandSession session = commandProcessor.createSession(in, new PrintStream(out),
new PrintStream(err));
-                session.put("APPLICATION", System.getProperty("karaf.name", "root"));
-                for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
-                    session.put(e.getKey(), e.getValue());
-                }
-                Console console = new Console(session,
+                Console console = new Console(commandProcessor,
+                                              in,
+                                              new PrintStream(out),
+                                              new PrintStream(err),
                                               new SshTerminal(env),
                                               new AggregateCompleter(completers),
                                               new Runnable() {
@@ -99,6 +97,11 @@
                                                       destroy();
                                                   }
                                               });
+                CommandSession session = console.getSession();
+                session.put("APPLICATION", System.getProperty("karaf.name", "root"));
+                for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
+                    session.put(e.getKey(), e.getValue());
+                }
                 new Thread(console).start();
             } catch (Exception e) {
                 throw (IOException) new IOException("Unable to start shell").initCause(e);



Mime
View raw message