GSHELL-155: When remote logging through SSH, the shell variables are not set correctly (prompt, user, etc...)

git-svn-id: https://svn.apache.org/repos/asf/geronimo/gshell/trunk@731517 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/ShellFactoryImpl.java b/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/ShellFactoryImpl.java
index 9f71b86..3306e42 100644
--- a/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/ShellFactoryImpl.java
+++ b/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/ShellFactoryImpl.java
@@ -32,6 +32,8 @@
 import org.apache.geronimo.gshell.notification.ExitNotification;
 import org.apache.geronimo.gshell.shell.ShellContext;
 import org.apache.geronimo.gshell.shell.ShellContextHolder;
+import org.apache.geronimo.gshell.registry.CommandResolver;
+import org.apache.geronimo.gshell.application.Application;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,6 +53,8 @@
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    private Application application;
+
     private Console.Prompter prompter;
 
     private CommandLineExecutor executor;
@@ -101,6 +105,14 @@
         this.errorHandler = errorHandler;
     }
 
+    public Application getApplication() {
+        return application;
+    }
+
+    public void setApplication(Application application) {
+        this.application = application;
+    }
+
     public Shell createShell() {
         return new ShellImpl();
     }
@@ -140,7 +152,21 @@
 
         public void start(final Map<String,String> env) throws IOException {
             this.io = new IO(in, out, err, false);
-            this.variables = new Variables((Map)env);
+
+            // Create variables, inheriting the application ones
+            this.variables = new Variables(application.getVariables());
+            // Set up additional env
+            if (env != null) {
+                for (Map.Entry<String,String> entry : env.entrySet()) {
+                    this.variables.set(entry.getKey(), entry.getValue());
+                }
+            }
+            this.variables.set("gshell.prompt", application.getModel().getBranding().getPrompt());
+            this.variables.set(CommandResolver.GROUP, "/");
+            this.variables.set("gshell.username", env.get("USER"));
+            this.variables.set("gshell.hostname", application.getLocalHost());
+            // HACK: Add history for the 'history' command, since its not part of the Shell intf it can't really access it
+            this.variables.set("gshell.internal.history", getHistory(), true);
             new Thread(this).start();
         }
 
diff --git a/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml b/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
index c640b6b..79188f4 100644
--- a/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
+++ b/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
@@ -51,6 +51,7 @@
     <bean name="sshServer" class="com.google.code.sshd.SshServer" factory-method="setUpDefaultServer" scope="prototype">
         <property name="shellFactory">
             <bean class="org.apache.geronimo.gshell.commands.ssh.ShellFactoryImpl">
+                <property name="application" ref="application" />
                 <property name="completers">
                     <list>
                         <ref bean="commandsCompleter"/>