geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r410403 - in /geronimo/sandbox/gshell/trunk: gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ gshell-core/src/main/java/org/apache/geronimo/gshell/console/
Date Tue, 30 May 2006 23:32:44 GMT
Author: jdillon
Date: Tue May 30 16:32:43 2006
New Revision: 410403

URL: http://svn.apache.org/viewvc?rev=410403&view=rev
Log:
Brought the InteractiveInterpreter back to life as a sub-class of InteractiveConsole which
adds the custom Executor and Prompter
Default is now to shutdown on null... this lets you gshell < script.gsh (before this would
loop forever)

Added:
    geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/InteractiveInterpreter.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java

Added: geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/InteractiveInterpreter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/InteractiveInterpreter.java?rev=410403&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/InteractiveInterpreter.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/InteractiveInterpreter.java
Tue May 30 16:32:43 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.commands.scripting;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.HelpFormatter;
+
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.console.IO;
+import org.apache.geronimo.gshell.console.JLineConsole;
+import org.apache.geronimo.gshell.console.InteractiveConsole;
+import org.apache.geronimo.gshell.console.Console;
+
+import org.apache.bsf.BSFManager;
+import org.apache.bsf.BSFEngine;
+
+/**
+ * An interactive console extention that knows how to execute lines of script text with a
{@link BSFEngine}.
+ *
+ * @version $Id: ScriptCommand.java 410204 2006-05-30 07:26:34Z jdillon $
+ */
+public class InteractiveInterpreter
+    extends InteractiveConsole
+{
+    public InteractiveInterpreter(final Console console, final BSFEngine engine, final String
language) {
+        super(console, new EngineExecutor(engine), new EnginePrompter(language));
+    }
+
+    private static class EngineExecutor
+        implements Executor
+    {
+        private BSFEngine engine;
+
+        public EngineExecutor(final BSFEngine engine) {
+            this.engine = engine;
+        }
+
+        public Result execute(final String line) throws Exception {
+            // Execute unless the line is just blank
+            if (!line.trim().equals("")) {
+                engine.exec("<unknown>", 1, 1, line);
+            }
+
+            return Result.CONTINUE;
+        }
+    }
+
+    private static class EnginePrompter
+        implements Prompter
+    {
+        private String language;
+
+        public EnginePrompter(final String language) {
+            this.language = language;
+        }
+
+        public String getPrompt() {
+            return "script(" + language + ")> ";
+        }
+    }
+}
+

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java?rev=410403&r1=410402&r2=410403&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/scripting-commands/src/main/java/org/apache/geronimo/gshell/commands/scripting/ScriptCommand.java
Tue May 30 16:32:43 2006
@@ -147,27 +147,8 @@
         }
 
         if (this.interactive) {
-            InteractiveConsole console = new InteractiveConsole(
-                new JLineConsole(getIO()),
-                new InteractiveConsole.Executor() {
-                    public Result execute(final String line) throws Exception {
-                        // Execute unless the line is just blank
-                        if (!line.trim().equals("")) {
-                            engine.exec("<unknown>", 1, 1, line);
-                        }
-
-                        return Result.CONTINUE;
-                    }
-                },
-                new InteractiveConsole.Prompter() {
-                    public String getPrompt() {
-                        return "script:" + language + "> ";
-                    }
-                });
-
-            // Allow CTRL-D to exit :-)
-            console.setShutdownOnNull(true);
-            console.run();
+            InteractiveInterpreter interp = new InteractiveInterpreter(new JLineConsole(getIO()),
engine, language);
+            interp.run();
         }
 
         return Command.SUCCESS;

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java?rev=410403&r1=410402&r2=410403&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
Tue May 30 16:32:43 2006
@@ -42,7 +42,7 @@
 
     private boolean running = false;
 
-    private boolean shutdownOnNull = false;
+    private boolean shutdownOnNull = true;
 
     public InteractiveConsole(final Console console, final Executor executor, final Prompter
prompter) {
         if (console == null) {
@@ -132,6 +132,9 @@
 
         //
         // TODO: Probably need to expose more configurability for handing/rejecting shutdown
+        //
+        //       Use-case is that GShell might want to disallow and print a "use exit command",
+        //       but Script interp wants this to exit and return control to GShell.
         //
     }
 



Mime
View raw message