KARAF-3045 - simplify console branding
Conflicts:
manual/src/main/webapp/developers-guide/branding-console.conf
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/8e7d5197
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/8e7d5197
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/8e7d5197
Branch: refs/heads/master
Commit: 8e7d51972a20154da2b5c2c84c30eb8b0368cfcd
Parents: 480979f
Author: Jonathan Anstey <[email protected]>
Authored: Fri Jun 13 16:49:52 2014 -0230
Committer: Jonathan Anstey <[email protected]>
Committed: Fri Jun 13 16:55:50 2014 -0230
----------------------------------------------------------------------
.../main/webapp/developers-guide/branding.conf | 27 +++++++++++++++++-
.../shell/console/impl/jline/Branding.java | 30 +++++++++++++++++---
2 files changed, 52 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/8e7d5197/manual/src/main/webapp/developers-guide/branding.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/developers-guide/branding.conf
b/manual/src/main/webapp/developers-guide/branding.conf
index 2ce1a53..5932199 100644
--- a/manual/src/main/webapp/developers-guide/branding.conf
+++ b/manual/src/main/webapp/developers-guide/branding.conf
@@ -9,6 +9,31 @@ By branding, it means that you can define your own:
* the welcome message (motd or Message Of The Day) displayed when you start
the console
* the prompt displayed to the users
+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. Branding bundle
At startup, Apache Karaf is looking for a bundle which exports the
{{org.apache.karaf.branding}} package, containing
@@ -194,4 +219,4 @@ As for console, you can use the following {{pom.xml}} to
create the WebConsole b
{code}
With the {{webconsole}} feature installed, you can install this bundle (using
{{bundle:install}} or by editing the
-{{etc/startup.properties}}), you will see the WebConsole with your branding.
\ No newline at end of file
+{{etc/startup.properties}}), you will see the WebConsole with your branding.
http://git-wip-us.apache.org/repos/asf/karaf/blob/8e7d5197/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/Branding.java
----------------------------------------------------------------------
diff --git
a/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/Branding.java
b/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/Branding.java
index 57a5f5e..55148d6 100644
---
a/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/Branding.java
+++
b/shell/console/src/main/java/org/apache/karaf/shell/console/impl/jline/Branding.java
@@ -18,14 +18,22 @@
*/
package org.apache.karaf.shell.console.impl.jline;
+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 {
}
}
}
-
}