Author: jawi
Date: Tue Jan 19 15:43:28 2016
New Revision: 1725549

URL: http://svn.apache.org/viewvc?rev=1725549&view=rev
Log:
FELIX-3494 - suppress printing of motd

- make some of the arguments of Gosh itself available to the shell;
- add an "quiet" option to suppress printing of the motd.


Modified:
    
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
    felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Posix.java
    felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Shell.java
    felix/trunk/gogo/shell/src/main/resources/gosh_profile

Modified: 
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java?rev=1725549&r1=1725548&r2=1725549&view=diff
==============================================================================
--- 
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
 (original)
+++ 
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
 Tue Jan 19 15:43:28 2016
@@ -343,40 +343,46 @@ public class CommandSessionImpl implemen
     {
         boolean found = false;
         Formatter f = new Formatter();
-        f.close();
 
-        Method methods[] = b.getClass().getMethods();
-        for (Method m : methods)
+        try
         {
-            try
+            Method methods[] = b.getClass().getMethods();
+            for (Method m : methods)
             {
-                String name = m.getName();
-                if (!name.equals("getClass") && name.startsWith("get") && 
m.getParameterTypes().length == 0)
+                try
                 {
-                    m.setAccessible(true);
-                    Object value = m.invoke(b);
+                    String name = m.getName();
+                    if (!name.equals("getClass") && name.startsWith("get") && 
m.getParameterTypes().length == 0)
+                    {
+                        m.setAccessible(true);
+                        Object value = m.invoke(b);
 
-                    found = true;
-                    name = name.substring(3);
-                    f.format(COLUMN, name, format(value, Converter.LINE, 
this));
+                        found = true;
+                        name = name.substring(3);
+                        f.format(COLUMN, name, format(value, Converter.LINE, 
this));
+                    }
+                }
+                catch (IllegalAccessException e)
+                {
+                    // Ignore
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
                 }
             }
-            catch (IllegalAccessException e)
+            if (found)
             {
-                // Ignore
+                return (StringBuilder) f.out();
             }
-            catch (Exception e)
+            else
             {
-                e.printStackTrace();
+                return b.toString();
             }
         }
-        if (found)
-        {
-            return (StringBuilder) f.out();
-        }
-        else
+        finally
         {
-            return b.toString();
+            f.close();
         }
     }
 

Modified: 
felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Posix.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Posix.java?rev=1725549&r1=1725548&r2=1725549&view=diff
==============================================================================
--- felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Posix.java 
(original)
+++ felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Posix.java 
Tue Jan 19 15:43:28 2016
@@ -50,7 +50,7 @@ public class Posix
         }
 
         URI cwd = Shell.cwd(session);
-        
+
         for (String arg : args)
         {
             copy(cwd.resolve(arg), System.out);
@@ -141,7 +141,7 @@ public class Posix
             {
                 URI cwd = Shell.cwd(session);
                 in = (arg == null) ? System.in : 
cwd.resolve(arg).toURL().openStream();
-                
+
                 BufferedReader rdr = new BufferedReader(new 
InputStreamReader(in));
                 int line = 0;
                 String s;
@@ -180,21 +180,26 @@ public class Posix
 
         return match && status;
     }
-    
-    public static void copy(URI source, OutputStream out) throws IOException {
+
+    public static void copy(URI source, OutputStream out) throws IOException
+    {
         InputStream in = source.toURL().openStream();
-        try {
+        try
+        {
             copy(in, out);
-        } finally {
+        }
+        finally
+        {
             in.close();
         }
     }
 
-
-    public static void copy(InputStream in, OutputStream out) throws 
IOException {
+    public static void copy(InputStream in, OutputStream out) throws 
IOException
+    {
         byte buf[] = new byte[10240];
         int len;
-        while ((len = in.read(buf)) > 0) {
+        while ((len = in.read(buf)) > 0)
+        {
             out.write(buf, 0, len);
         }
         out.flush();

Modified: 
felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Shell.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Shell.java?rev=1725549&r1=1725548&r2=1725549&view=diff
==============================================================================
--- felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Shell.java 
(original)
+++ felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Shell.java 
Tue Jan 19 15:43:28 2016
@@ -71,6 +71,7 @@ public class Shell
                 "     --nointeractive       don't start interactive session",
                 "     --login               login shell (same session, reads 
etc/gosh_profile)",
                 "  -s --noshutdown          don't shutdown framework when 
script completes",
+                "  -q --quiet               don't display message-of-the-day",
                 "  -x --xtrace              echo commands before execution",
                 "  -? --help                show help",
                 "If no script-file, an interactive shell is started, type $D 
to exit." };
@@ -100,6 +101,10 @@ public class Shell
         }
 
         CommandSession newSession = (login ? session : 
processor.createSession(session.getKeyboard(), session.getConsole(), 
System.err));
+        // Make some of the given arguments available to the shell itself...
+        newSession.put(".gosh_login", login);
+        newSession.put(".gosh_interactive", interactive);
+        newSession.put(".gosh_quiet", opt.isSet("quiet"));
 
         if (opt.isSet("xtrace"))
         {

Modified: felix/trunk/gogo/shell/src/main/resources/gosh_profile
URL: 
http://svn.apache.org/viewvc/felix/trunk/gogo/shell/src/main/resources/gosh_profile?rev=1725549&r1=1725548&r2=1725549&view=diff
==============================================================================
--- felix/trunk/gogo/shell/src/main/resources/gosh_profile (original)
+++ felix/trunk/gogo/shell/src/main/resources/gosh_profile Tue Jan 19 15:43:28 
2016
@@ -30,8 +30,8 @@ try {
   # set prompt
   prompt = 'g! '
 
-  # print welcome message
-  cat ($0 resolve motd)
+  # print welcome message, unless we're explicitly told not to...
+  if {$.gosh_quiet} {} { cat ($0 resolve motd) }
 } {
     echo "$0: ERROR: $exception"
 }


Reply via email to