geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r573963 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/
Date Sun, 09 Sep 2007 08:59:43 GMT
Author: jdillon
Date: Sun Sep  9 01:59:42 2007
New Revision: 573963

URL: http://svn.apache.org/viewvc?rev=573963&view=rev
Log:
(GSHELL-5) Add support to load a shared /etc/gshell/gshell.profile (which could be used to
add a motd-like support)

Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/Flavor.java
    geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/VanillaFlavor.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=573963&r1=573962&r2=573963&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  9 01:59:42 2007
@@ -75,6 +75,9 @@
     private Logger log;
 
     // HACK:
+    private Shell shell;
+    
+    // HACK:
     private Flavor flavor;
     
     public Main(final ClassWorld classWorld) {
@@ -173,25 +176,53 @@
         System.setProperty("jline.terminal", type);
     }
 
-    private void loadUserScript(final Shell shell, final String fileName) throws Exception
{
+    //
+    // TODO: Add flags to control how the rc/init/profile muck is loaded, and optionally
skip it
+    //
+    
+    private void loadScript(final File file) throws Exception {
+        assert file != null;
+        
+        //
+        // FIXME: For some reason the non-command-line version pukes up and an ArrayStoreException
in Arguments.shift()
+        //
+
+        // shell.execute("source", file.toURI().toURL());
+
+        shell.execute("source " + file.toURI().toURL());
+
+        //
+        // TODO: Should probably lookup the command by id, since user's might not bind this
in the layout
+        //
+    }
+
+    private void loadUserScript(final String fileName) throws Exception {
         assert fileName != null;
 
-        File file = new File(flavor.getUserStateDirectory(), fileName);
+        File file = new File(flavor.getUserDirectory(), fileName);
 
         if (file.exists()) {
             log.debug("Loading user-script: {}", file);
 
-            //
-            // FIXME: For some reason the non-command-line version pukes up and an ArrayStoreException
in Arguments.shift()
-            //
+            loadScript(file);
+        }
+        else {
+            log.debug("User script is not present: {}", file);
+        }
+    }
 
-            // shell.execute("source", file.toURI().toURL());
+    private void loadSharedScript(final String fileName) throws Exception {
+        assert fileName != null;
 
-            shell.execute("source " + file.toURI().toURL());
+        File file = new File(flavor.getSharedDirectory(), fileName);
 
-            //
-            // TODO: Should probably lookup the command by id, since user's might not bind
this in the layout
-            //
+        if (file.exists()) {
+            log.debug("Loading shared-script: {}", file);
+
+            loadScript(file);
+        }
+        else {
+            log.debug("Shared script is not present: {}", file);
         }
     }
 
@@ -264,7 +295,7 @@
         //
         
         // Load the GShell instance
-        final Shell shell = (Shell) container.lookup(Shell.class);
+        shell = (Shell) container.lookup(Shell.class);
 
         // Log some information about our terminal
         Terminal term = Terminal.getTerminal();
@@ -288,7 +319,9 @@
             // TODO: Load gsh.properties if it exists?
             //
 
-            loadUserScript(shell, flavor.getProfileScriptName());
+            loadSharedScript(flavor.getProfileScriptName());
+
+            loadUserScript(flavor.getProfileScriptName());
 
             //
             // TODO: Pass interactive flags (maybe as property) so gshell knows what modfooe
it is
@@ -302,7 +335,7 @@
             else if (interactive) {
                 log.debug("Starting interactive console");
 
-                loadUserScript(shell, flavor.getInteractiveScriptName());
+                loadUserScript(flavor.getInteractiveScriptName());
 
                 IO io = shell.getIO();
 
@@ -341,14 +374,8 @@
                 });
 
                 runner.setHistory(new History());
-                runner.setHistoryFile(new File(flavor.getUserStateDirectory(), flavor.getHistoryFileName()));
+                runner.setHistoryFile(new File(flavor.getUserDirectory(), flavor.getHistoryFileName()));
                 
-
-                // Check if there are args, and run them and then enter interactive
-                if (args.length != 0) {
-                    shell.execute(args);
-                }
-
                 if (!io.isQuiet()) {
                     io.out.print(flavor.getWelcomeBanner());
                     
@@ -362,6 +389,11 @@
                     io.out.println(StringUtils.repeat("-", width - 1));
                 }
 
+                // Check if there are args, and run them and then enter interactive
+                if (args.length != 0) {
+                    shell.execute(args);
+                }
+                
                 runner.run();
             }
             else {

Modified: geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/Flavor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/Flavor.java?rev=573963&r1=573962&r2=573963&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/Flavor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/Flavor.java
Sun Sep  9 01:59:42 2007
@@ -30,6 +30,10 @@
 {
     String HOME = "home";
 
+    File getUserDirectory();
+
+    File getSharedDirectory();
+    
     String getName();
 
     String getDisplayName();
@@ -39,8 +43,6 @@
     String getVersion();
     
     String getWelcomeBanner();
-
-    File getUserStateDirectory();
 
     String getProfileScriptName();
 

Modified: geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/VanillaFlavor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/VanillaFlavor.java?rev=573963&r1=573962&r2=573963&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/VanillaFlavor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-flavor/src/main/java/org/apache/geronimo/gshell/flavor/VanillaFlavor.java
Sun Sep  9 01:59:42 2007
@@ -46,6 +46,24 @@
         return "GShell";
     }
 
+    public File getUserDirectory() {
+        File userHome = new File(System.getProperty("user.home"));
+
+        File dir = new File(userHome, "." + getName());
+
+        return dir.getAbsoluteFile();
+    }
+
+    public File getSharedDirectory() {
+        //
+        // FIXME: This is not very portable :-(
+        //
+        
+        File dir = new File("/etc", getName());
+
+        return dir.getAbsoluteFile();
+    }
+
     public String getAbout() {
         StringWriter writer = new StringWriter();
         PrintWriter out = new PrintWriter(writer);
@@ -79,14 +97,6 @@
         out.flush();
 
         return writer.toString();
-    }
-
-    public File getUserStateDirectory() {
-        File userHome = new File(System.getProperty("user.home"));
-
-        File dir = new File(userHome, "." + getName());
-        
-        return dir.getAbsoluteFile();
     }
 
     public String getProfileScriptName() {



Mime
View raw message