geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r699738 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/shell/ gshell-application/src/main/java/org/apache/geronimo/gshell/application/ gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gs...
Date Sat, 27 Sep 2008 21:09:10 GMT
Author: jdillon
Date: Sat Sep 27 14:09:10 2008
New Revision: 699738

URL: http://svn.apache.org/viewvc?rev=699738&view=rev
Log:
Drop the icky ShellInfo muck, roll up those bits (username, localhost, homedir) into Application

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationImpl.java
      - copied, changed from r699716, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ShellCreatedEvent.java
Removed:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/shell/ShellInfo.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/proxy/RemoteShellInfoProxy.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellInfoImpl.java
Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/shell/Shell.java
    geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/Application.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/proxy/RemoteShellProxy.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/shell/Shell.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/shell/Shell.java?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/shell/Shell.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/shell/Shell.java
Sat Sep 27 14:09:10 2008
@@ -28,8 +28,6 @@
 {
     ShellContext getContext();
 
-    ShellInfo getInfo();
-
     Object execute(String line) throws Exception;
 
     Object execute(String command, Object[] args) throws Exception;

Modified: geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/Application.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/Application.java?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/Application.java
(original)
+++ geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/Application.java
Sat Sep 27 14:09:10 2008
@@ -23,6 +23,9 @@
 import org.apache.geronimo.gshell.model.application.ApplicationModel;
 import org.apache.geronimo.gshell.command.Variables;
 
+import java.io.File;
+import java.net.InetAddress;
+
 /**
  * Encapsulates the context for an application.
  *
@@ -37,4 +40,25 @@
     Variables getVariables();
     
     ApplicationModel getModel();
+
+    /**
+     * Returns the home directory of the shell.
+     *
+     * @return  Shell home directory; never null;
+     */
+    File getHomeDir();
+
+    /**
+     * Returns the local IP address of the shell.
+     *
+     * @return  The local IP address of the shell; never null;
+     */
+    InetAddress getLocalHost();
+
+    /**
+     * Returns the name of the current user.
+     *
+     * @return  The current user name; never null;
+     */
+    String getUserName();
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/proxy/RemoteShellProxy.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/proxy/RemoteShellProxy.java?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/proxy/RemoteShellProxy.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/proxy/RemoteShellProxy.java
Sat Sep 27 14:09:10 2008
@@ -27,7 +27,6 @@
 import org.apache.geronimo.gshell.remote.RemoteShell;
 import org.apache.geronimo.gshell.remote.client.RshClient;
 import org.apache.geronimo.gshell.shell.ShellContext;
-import org.apache.geronimo.gshell.shell.ShellInfo;
 import org.apache.geronimo.gshell.whisper.stream.StreamFeeder;
 import org.apache.geronimo.gshell.command.Variables;
 import org.slf4j.Logger;
@@ -53,8 +52,6 @@
 
     private final ShellContext context;
 
-    private final RemoteShellInfoProxy shellInfo;
-
     private final RemoteHistoryProxy history;
 
     private boolean opened;
@@ -74,7 +71,6 @@
         client.openShell();
 
         // Setup other proxies
-        shellInfo = new RemoteShellInfoProxy(client);
         history = new RemoteHistoryProxy(client);
 
         // Copy the client's input stream to our outputstream so users see command output
@@ -124,12 +120,6 @@
         return context;
     }
 
-    public ShellInfo getInfo() {
-        ensureOpened();
-
-        return shellInfo;
-    }
-
     public Object execute(final String line) throws Exception {
         ensureOpened();
 

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
Sat Sep 27 14:09:10 2008
@@ -22,7 +22,6 @@
 import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
 import org.apache.geronimo.gshell.remote.RemoteShell;
 import org.apache.geronimo.gshell.shell.ShellContext;
-import org.apache.geronimo.gshell.shell.ShellInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,9 +37,6 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     @Autowired
-    private ShellInfo shellInfo;
-
-    @Autowired
     private CommandLineExecutor executor;
 
     private boolean opened = true;
@@ -74,12 +70,6 @@
 
         return context;
     }
-    
-    public ShellInfo getInfo() {
-        ensureOpened();
-
-        return shellInfo;
-    }
 
     public Object execute(final String line) throws Exception {
         assert line != null;

Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationImpl.java
(from r699716, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ShellCreatedEvent.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationImpl.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationImpl.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ShellCreatedEvent.java&r1=699716&r2=699738&rev=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ShellCreatedEvent.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationImpl.java
Sat Sep 27 14:09:10 2008
@@ -19,26 +19,97 @@
 
 package org.apache.geronimo.gshell.wisdom.application;
 
-import org.apache.geronimo.gshell.event.Event;
-import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.geronimo.gshell.application.Application;
+import org.apache.geronimo.gshell.application.ApplicationConfiguration;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.model.application.ApplicationModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 /**
  * Event fired once the application has constructed a shell.
- * 
+ *
  * @version $Rev$ $Date$
  */
-public class ShellCreatedEvent
-    implements Event
+public class ApplicationImpl
+    implements Application
 {
-    private final Shell shell;
-    
-    public ShellCreatedEvent(final Shell shell) {
-        assert shell != null;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final ApplicationConfiguration config;
+
+    private InetAddress localHost;
+
+    private File homeDir;
+
+    public ApplicationImpl(final ApplicationConfiguration config) throws Exception {
+        assert config != null;
+
+        this.config = config;
+        this.homeDir = detectHomeDir();
+        this.localHost = InetAddress.getLocalHost();
+    }
+
+    public String getId() {
+        return config.getModel().getId();
+    }
+
+    public IO getIo() {
+        return config.getIo();
+    }
+
+    public Variables getVariables() {
+        return config.getVariables();
+    }
 
-        this.shell = shell;
+    public ApplicationModel getModel() {
+        return config.getModel();
     }
 
-    public Shell getShell() {
-        return shell;
+    public File getHomeDir() {
+        if (homeDir == null) {
+            throw new IllegalStateException();
+        }
+
+        return homeDir;
+    }
+
+    public InetAddress getLocalHost() {
+        if (localHost == null) {
+            throw new IllegalStateException();
+        }
+
+        return localHost;
+    }
+
+    public String getUserName() {
+        return System.getProperty("user.name");
+    }
+
+    private File detectHomeDir() {
+        String homePath = System.getProperty("user.home");
+
+        // And now lets resolve this sucker
+        File dir;
+
+        try {
+            dir = new File(homePath).getCanonicalFile();
+        }
+        catch (IOException e) {
+            throw new RuntimeException("Failed to resolve home directory: " + homePath, e);
+        }
+
+        // And some basic sanity too
+        if (!dir.exists() || !dir.isDirectory()) {
+            throw new RuntimeException("Home directory configured but is not a valid directory:
" + dir);
+        }
+
+        return dir;
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java
Sat Sep 27 14:09:10 2008
@@ -115,23 +115,7 @@
         configure(config.getModel());
 
         // Create a new context
-        application = new Application() {
-            public String getId() {
-                return config.getModel().getId();
-            }
-
-            public IO getIo() {
-                return config.getIo();
-            }
-
-            public Variables getVariables() {
-                return config.getVariables();
-            }
-
-            public ApplicationModel getModel() {
-                return config.getModel();
-            }
-        };
+        application = new ApplicationImpl(config);
 
         log.debug("Application configured");
         

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
Sat Sep 27 14:09:10 2008
@@ -24,6 +24,7 @@
 import org.apache.geronimo.gshell.ansi.Renderer;
 import org.apache.geronimo.gshell.ansi.Code;
 import org.apache.geronimo.gshell.application.Application;
+import org.apache.geronimo.gshell.application.ApplicationManager;
 import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
 import org.apache.geronimo.gshell.console.Console;
@@ -40,7 +41,6 @@
 import org.apache.geronimo.gshell.notification.ExitNotification;
 import org.apache.geronimo.gshell.shell.Shell;
 import org.apache.geronimo.gshell.shell.ShellContext;
-import org.apache.geronimo.gshell.shell.ShellInfo;
 import org.apache.geronimo.gshell.wisdom.application.ApplicationConfiguredEvent;
 import org.codehaus.plexus.util.IOUtil;
 import org.slf4j.Logger;
@@ -65,10 +65,10 @@
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     @Autowired
-    private EventManager eventManager;
+    private ApplicationManager applicationManager;
 
     @Autowired
-    private ShellInfo shellInfo;
+    private EventManager eventManager;
 
     @Autowired
     private CommandLineExecutor executor;
@@ -99,10 +99,6 @@
         return context;
     }
 
-    public ShellInfo getInfo() {
-        return shellInfo;
-    }
-
     public boolean isInteractive() {
         return true;
     }
@@ -253,21 +249,16 @@
             Renderer renderer = new Renderer();
 
             public String prompt() {
-                assert shellInfo != null;
-
-                // FIXME: Need to use some sort of format based on branding, for now hardcode
this
-                String userName = shellInfo.getUserName();
-                String hostName = shellInfo.getLocalHost().getHostName();
-
-                // FIXME: Get this from Branding/Application
-                String appName = "gshell";
-
+                assert applicationManager != null;
+                Application app = applicationManager.getApplication();
+                Branding branding = app.getModel().getBranding();
+                
                 StringBuilder buff = new StringBuilder();
-                buff.append(Renderer.encode(userName, Code.BOLD));
+                buff.append(Renderer.encode(app.getUserName(), Code.BOLD));
                 buff.append("@");
-                buff.append(hostName);
+                buff.append(app.getLocalHost().getHostName());
                 buff.append(":");
-                buff.append(Renderer.encode(appName, Code.BOLD));
+                buff.append(Renderer.encode(branding.getName(), Code.BOLD));
                 buff.append("> ");
 
                 return renderer.render(buff.toString());

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml?rev=699738&r1=699737&r2=699738&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/META-INF/spring/components.xml
Sat Sep 27 14:09:10 2008
@@ -39,8 +39,6 @@
 
     <bean id="history" class="org.apache.geronimo.gshell.wisdom.shell.HistoryImpl"/>
 
-    <bean id="shellInfo" class="org.apache.geronimo.gshell.wisdom.shell.ShellInfoImpl"/>
-
     <bean id="commandNameCompleter" class="org.apache.geronimo.gshell.wisdom.shell.completer.CommandNameCompleter"/>
 
     <bean id="aliasNameCompleter" class="org.apache.geronimo.gshell.wisdom.shell.completer.AliasNameCompleter"/>



Mime
View raw message