You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/03 00:22:04 UTC

svn commit: r572178 - in /geronimo/sandbox/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/console/ gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-commands/ gshell-core/src/main/java/org/apache/geronimo/gshell/ gshell...

Author: jdillon
Date: Sun Sep  2 15:22:00 2007
New Revision: 572178

URL: http://svn.apache.org/viewvc?rev=572178&view=rev
Log:
Weed out the old console crapo, replace with something a little better, pending more massaging 

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/JLineShellRunner.java   (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/console/Console.java
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/console/ConsoleFactory.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/InteractiveShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/
Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-commands/pom.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellRunner.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=572178&r1=572177&r2=572178&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java Sun Sep  2 15:22:00 2007
@@ -23,16 +23,16 @@
 import java.util.List;
 
 import jline.Terminal;
-import org.apache.geronimo.gshell.InteractiveShell;
+import org.apache.geronimo.gshell.ExitNotification;
+import org.apache.geronimo.gshell.JLineShellRunner;
 import org.apache.geronimo.gshell.Shell;
+import org.apache.geronimo.gshell.ShellRunner;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.clp.CommandLineProcessor;
 import org.apache.geronimo.gshell.clp.Option;
 import org.apache.geronimo.gshell.clp.Printer;
 import org.apache.geronimo.gshell.common.StopWatch;
-import org.apache.geronimo.gshell.console.Console;
 import org.apache.geronimo.gshell.console.IO;
-import org.apache.geronimo.gshell.console.JLineConsole;
 import org.apache.geronimo.gshell.util.Banner;
 import org.apache.geronimo.gshell.util.Version;
 import org.codehaus.plexus.ContainerConfiguration;
@@ -182,7 +182,7 @@
 
     private int execute(final String[] args) throws Exception {
         // Its okay to use logging now
-        Logger log = LoggerFactory.getLogger(Main.class);
+        final Logger log = LoggerFactory.getLogger(Main.class);
 
         // Boot up the container
         ContainerConfiguration config = new DefaultContainerConfiguration();
@@ -196,7 +196,7 @@
         //
         
         // Load the GShell instance
-        final Shell gshell = (Shell) container.lookup(Shell.class);
+        final Shell shell = (Shell) container.lookup(Shell.class);
 
         //
         // TEMP: Log some info about the terminal
@@ -219,31 +219,43 @@
         //
 
         if (commands != null) {
-            gshell.execute(commands);
+            shell.execute(commands);
         }
         else if (interactive) {
             log.debug("Starting interactive console");
 
-            //
-            // HACK: This is JLine specific... refactor
-            //
-
-            //
-            // TODO: Explicitly pass in the terminal
-            //
+            JLineShellRunner runner = new JLineShellRunner(shell);
 
-            Console console = new JLineConsole(io);
-            InteractiveShell interp = new InteractiveShell(console, gshell);
+            runner.setExecutor(new ShellRunner.Executor() {
+                public Result execute(Shell shell, String line) throws Exception {
+                    try {
+                        Object result = shell.execute(line);
+                    }
+                    catch (ExitNotification n) {
+                        return Result.STOP;
+                    }
+
+                    return Result.CONTINUE;
+                }
+            });
+
+            runner.setErrorHandler(new ShellRunner.ErrorHandler() {
+                public Result handleError(Throwable error) {
+                    log.error("Execution failed: " + error, error);
+                    
+                    return Result.CONTINUE;
+                }
+            });
 
             // Check if there are args, and run them and then enter interactive
             if (args.length != 0) {
-                gshell.execute(args);
+                shell.execute(args);
             }
 
-            interp.run();
+            runner.run();
         }
         else {
-            result = gshell.execute(args);
+            result = shell.execute(args);
         }
 
         log.debug("Ran for {}", watch);

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/pom.xml?rev=572178&r1=572177&r2=572178&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/pom.xml Sun Sep  2 15:22:00 2007
@@ -50,7 +50,9 @@
     <modules>
         <module>gshell-builtins</module>
         <module>gshell-optional</module>
+        <!--
         <module>gshell-bsf</module>
+        -->
         <module>gshell-vfs</module>
     </modules>
     

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/JLineShellRunner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/JLineShellRunner.java?rev=572178&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/JLineShellRunner.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/JLineShellRunner.java Sun Sep  2 15:22:00 2007
@@ -0,0 +1,95 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import jline.ConsoleReader;
+import jline.History;
+
+import org.apache.geronimo.gshell.console.IO;
+
+/**
+ * Support for running a {@link Shell} using the <a href="http://jline.sf.net">JLine</a> library.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JLineShellRunner
+    extends ShellRunner
+{
+    private final ConsoleReader reader;
+
+    // final CommandsMultiCompletor completor
+
+    //
+    // TODO: Pass in the terminal instance to be used
+    //
+    
+    public JLineShellRunner(final Shell shell) throws IOException {
+        super(shell);
+
+        IO io = shell.getIO();
+        this.reader = new ConsoleReader(io.inputStream, new PrintWriter(io.outputStream, true));
+
+        // this.completor = new CommandsMultiCompletor()
+
+        // reader.addCompletor(completor)
+    }
+
+    public void run() {
+        /*
+        for (command in shell.registry) {
+            completor << command
+        }
+
+        // Force things to become clean
+        completor.refresh()
+        */
+
+        // And then actually run
+        super.run();
+    }
+
+    public void setHistory(final History history) {
+        reader.setHistory(history);
+    }
+
+    public void setHistoryFile(final File file) throws IOException {
+        assert file != null;
+
+        File dir = file.getParentFile();
+
+        if (!dir.exists()) {
+            dir.mkdirs();
+
+            log.debug("Created base directory for history file: {}", dir);
+        }
+
+        log.debug("Using history file: {}", file);
+
+        reader.getHistory().setHistoryFile(file);
+    }
+
+    protected String readLine(final String prompt) throws IOException {
+        return reader.readLine(prompt);
+    }
+}
\ No newline at end of file

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

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

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

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellRunner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellRunner.java?rev=572178&r1=572177&r2=572178&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellRunner.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellRunner.java Sun Sep  2 15:22:00 2007
@@ -53,9 +53,6 @@
     protected Executor executor = new Executor() {
         public Result execute(final Shell shell, final String line) throws Exception {
             Object result = shell.execute(line);
-
-            log.debug("Result: {}", result);
-
             return Result.CONTINUE;
         }
     };