Repository: karaf
Updated Branches:
  refs/heads/karaf-2.x c538a08ef -> f992b0565
  refs/heads/karaf-3.0.x 2f4928f94 -> a8a3a2219
  refs/heads/master 480979f17 -> 8e7d51972


KARAF-3045 - simplify console branding


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/f992b056
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/f992b056
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/f992b056

Branch: refs/heads/karaf-2.x
Commit: f992b05657d8388b818a7b64e235289795f78cb9
Parents: c538a08
Author: Jonathan Anstey <[email protected]>
Authored: Fri Jun 13 16:49:52 2014 -0230
Committer: Jonathan Anstey <[email protected]>
Committed: Fri Jun 13 16:49:52 2014 -0230

----------------------------------------------------------------------
 .../developers-guide/branding-console.conf      | 32 ++++++++++++++++++--
 .../karaf/shell/console/util/Branding.java      | 30 +++++++++++++++---
 2 files changed, 55 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f992b056/manual/src/main/webapp/developers-guide/branding-console.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/developers-guide/branding-console.conf 
b/manual/src/main/webapp/developers-guide/branding-console.conf
index 68b29d3..96eef21 100644
--- a/manual/src/main/webapp/developers-guide/branding-console.conf
+++ b/manual/src/main/webapp/developers-guide/branding-console.conf
@@ -5,7 +5,32 @@ h1. Branding the Console
 This chapter will show you how to customize the user interface of the Karaf 
console, making  
 changes such as a new welcome message and console prompt.  This is what we 
refer to as "branding" Karaf.
 
-h2. Create your branding bundle
+There are 2 ways of branding the Karaf console: (1) adding a 
branding.properties file to etc, and (2) creating a branding bundle.
+
+h2. Adding a branding.properties file to etc
+
+Create a {{etc/branding.properties}} file similar to:
+
+{{code}}
+welcome = \
+\u001B[36m        __ __                  ____      \u001B[0m\r\n\
+\u001B[36m       / //_/____ __________ _/ __/      \u001B[0m\r\n\
+\u001B[36m      / ,<  / __ `/ ___/ __ `/ /_        \u001B[0m\r\n\
+\u001B[36m     / /| |/ /_/ / /  / /_/ / __/        \u001B[0m\r\n\
+\u001B[36m    /_/ |_|\\__,_/_/   \\__,_/_/         \u001B[0m\r\n\
+\r\n\
+\u001B[1m  Apache Karaf\u001B[0m (${project.version})\r\n\
+\r\n\
+Hit '\u001B[1m<tab>\u001B[0m' for a list of available commands\r\n\
+   and '\u001B[1m[cmd] --help\u001B[0m' for help on a specific command.\r\n\
+Hit '\u001B[1m<ctrl-d>\u001B[0m' or '\u001B[1mosgi:shutdown\u001B[0m' to 
shutdown Karaf.\r\n
+
+prompt = \u001B[1m${USER}@${APPLICATION}\u001B[0m>
+{{code}}
+
+Start Karaf and you will see your branded Karaf console.
+
+h2. Creating and deploying a branding bundle
 
 At startup, Karaf is looking for a bundle which exports the 
{{org.apache.karaf.branding}} package containing a {{branding.properties}}
 file.
@@ -92,7 +117,7 @@ prompt = 
\u001B[36mmy-karaf-user\u001B[0m\u001B[1m@\u001B[0m\u001B[34m${APPLICAT
 prompt = my-user@my-karaf>
 {code}
 
-h2. Configuring Karaf to use the branding bundle
+h3. Configuring Karaf to use the branding bundle
 
 In order for Karaf to pick up the branding jar please edit the 
 $KARAF_HOME/etc/custom.properties file to include the following: 
@@ -101,7 +126,7 @@ $KARAF_HOME/etc/custom.properties file to include the 
following:
     org.apache.karaf.branding
 
 
-h2. Installing the branding bundle
+h4. Installing the branding bundle
 
 Build your branding bundle:
 
@@ -112,3 +137,4 @@ mvn install
 and simply drop the generated jar file into the Karaf lib directory.
 
 Start Karaf and you will see your branded Karaf console.
+

http://git-wip-us.apache.org/repos/asf/karaf/blob/f992b056/shell/console/src/main/java/org/apache/karaf/shell/console/util/Branding.java
----------------------------------------------------------------------
diff --git 
a/shell/console/src/main/java/org/apache/karaf/shell/console/util/Branding.java 
b/shell/console/src/main/java/org/apache/karaf/shell/console/util/Branding.java
index 3e87448..4218656 100644
--- 
a/shell/console/src/main/java/org/apache/karaf/shell/console/util/Branding.java
+++ 
b/shell/console/src/main/java/org/apache/karaf/shell/console/util/Branding.java
@@ -18,14 +18,22 @@
  */
 package org.apache.karaf.shell.console.util;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import jline.Terminal;
 
 public final class Branding {
     
+    static final Logger LOGGER = LoggerFactory.getLogger(Branding.class);
+    
     private Branding() { }
 
     public static Properties loadBrandingProperties() {
@@ -38,20 +46,35 @@ public final class Branding {
     public static Properties loadBrandingProperties(Terminal terminal) {
         Properties props = new Properties();
         if (terminal != null && 
terminal.getClass().getName().endsWith("SshTerminal")) {
-            //it's a ssh client, so load branding seperately
+            //it's a ssh client, so load branding separately
             loadProps(props, 
"org/apache/karaf/shell/console/branding-ssh.properties");
         } else {
             loadProps(props, 
"org/apache/karaf/shell/console/branding.properties");
         }
 
         loadProps(props, "org/apache/karaf/branding/branding.properties");
+        
+        // load branding from etc/branding.properties
+        File etcBranding = new File(System.getProperty("karaf.etc"), 
"branding.properties");
+        if (etcBranding.exists()) {
+            FileInputStream etcBrandingIs = null;
+            try {
+                etcBrandingIs = new FileInputStream(etcBranding);
+            } catch (FileNotFoundException e) {
+                LOGGER.trace("Could not load branding.", e);
+            }
+            loadProps(props, etcBrandingIs);
+        }
         return props;
     }
     
     protected static void loadProps(Properties props, String resource) {
-        InputStream is = null;
+        InputStream is = 
Branding.class.getClassLoader().getResourceAsStream(resource);
+        loadProps(props, is);
+    }
+
+    protected static void loadProps(Properties props, InputStream is) {
         try {
-            is = Branding.class.getClassLoader().getResourceAsStream(resource);
             if (is != null) {
                 props.load(is);
             }
@@ -67,5 +90,4 @@ public final class Branding {
             }
         }
     }
-
 }

Reply via email to