felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r826748 - in /felix/trunk/karaf: assembly/src/main/distribution/text/etc/shell.init.script assembly/src/main/distribution/text/etc/system.properties shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
Date Mon, 19 Oct 2009 18:23:07 GMT
Author: gnodet
Date: Mon Oct 19 18:23:07 2009
New Revision: 826748

URL: http://svn.apache.org/viewvc?rev=826748&view=rev
Log:
FELIX-1755: provide a script that would be loaded when starting a new shell

Added:
    felix/trunk/karaf/assembly/src/main/distribution/text/etc/shell.init.script
Modified:
    felix/trunk/karaf/assembly/src/main/distribution/text/etc/system.properties
    felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java

Added: felix/trunk/karaf/assembly/src/main/distribution/text/etc/shell.init.script
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/distribution/text/etc/shell.init.script?rev=826748&view=auto
==============================================================================
--- felix/trunk/karaf/assembly/src/main/distribution/text/etc/shell.init.script (added)
+++ felix/trunk/karaf/assembly/src/main/distribution/text/etc/shell.init.script Mon Oct 19
18:23:07 2009
@@ -0,0 +1,24 @@
+//
+// 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.
+//
+// This script is run each time a shell is created.
+// You can define here closures or variables that will be available
+// in each session.
+//
+ld = { log:display $args } ;
+lde = { log:display-exception $args } ;

Modified: felix/trunk/karaf/assembly/src/main/distribution/text/etc/system.properties
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/distribution/text/etc/system.properties?rev=826748&r1=826747&r2=826748&view=diff
==============================================================================
--- felix/trunk/karaf/assembly/src/main/distribution/text/etc/system.properties (original)
+++ felix/trunk/karaf/assembly/src/main/distribution/text/etc/system.properties Mon Oct 19
18:23:07 2009
@@ -20,4 +20,5 @@
 org.ops4j.pax.logging.DefaultServiceLog.level=ERROR
 karaf.name=root
 karaf.default.repository=system
+karaf.shell.init.script=${karaf.home}/etc/shell.init.script
 xml.catalog.files=

Modified: felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java?rev=826748&r1=826747&r2=826748&view=diff
==============================================================================
--- felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
(original)
+++ felix/trunk/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/jline/Console.java
Mon Oct 19 18:23:07 2009
@@ -18,38 +18,47 @@
  */
 package org.apache.felix.karaf.shell.console.jline;
 
+import java.io.CharArrayWriter;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.InterruptedIOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.io.Reader;
 import java.util.Arrays;
 import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+import jline.AnsiWindowsTerminal;
 import jline.ConsoleReader;
 import jline.Terminal;
 import jline.UnsupportedTerminal;
-import jline.AnsiWindowsTerminal;
 import org.apache.felix.karaf.shell.console.Completer;
 import org.apache.felix.karaf.shell.console.completer.AggregateCompleter;
 import org.apache.felix.karaf.shell.console.completer.SessionScopeCompleter;
 import org.osgi.service.command.CommandProcessor;
 import org.osgi.service.command.CommandSession;
 import org.osgi.service.command.Converter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Console implements Runnable
 {
 
+    public static final String SHELL_INIT_SCRIPT = "karaf.shell.init.script";
     public static final String PROMPT = "PROMPT";
     public static final String DEFAULT_PROMPT = "\u001B[1m${USER}\u001B[0m@${APPLICATION}>
";
     public static final String PRINT_STACK_TRACES = "karaf.printStackTraces";
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(Console.class);
+
     private CommandSession session;
     private ConsoleReader reader;
     private BlockingQueue<Integer> queue;
@@ -125,6 +134,32 @@
         running = true;
         pipe.start();
         welcome();
+        String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
+        if (scriptFileName != null) {
+            Reader r = null;
+            try {
+                File scriptFile = new File(scriptFileName);
+                r = new InputStreamReader(new FileInputStream(scriptFile));
+                CharArrayWriter w = new CharArrayWriter();
+                int n;
+                char[] buf = new char[8192];
+                while ((n = r.read(buf)) > 0) {
+                    w.write(buf, 0, n);
+                }
+                session.execute(new String(w.toCharArray()));
+            } catch (Exception e) {
+                LOGGER.debug("Error in initialization script", e);
+                System.err.println("Error in initialization script: " + e.getMessage());
+            } finally {
+                if (r != null) {
+                    try {
+                        r.close();
+                    } catch (IOException e) {
+                        // Ignore
+                    }
+                }
+            }
+        }
         while (running) {
             try {
                 String line = reader.readLine(getPrompt());



Mime
View raw message