geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r576846 - in /geronimo/sandbox/gshell/trunk/gshell-core/src: main/java/org/apache/geronimo/gshell/ main/java/org/apache/geronimo/gshell/layout/model/ test/java/org/apache/geronimo/gshell/
Date Tue, 18 Sep 2007 11:20:49 GMT
Author: jdillon
Date: Tue Sep 18 04:20:47 2007
New Revision: 576846

URL: http://svn.apache.org/viewvc?rev=576846&view=rev
Log:
Add toString(), renamed VariablesImpl to DefaultVariables, Adding DefaultEnvironment

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java
  (contents, props changed)
      - copied, changed from r576639, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java
  (contents, props changed)
      - copied, changed from r576639, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/VariablesImpl.java
Removed:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/VariablesImpl.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/VariablesImplTest.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java?rev=576846&r1=576845&r2=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
Tue Sep 18 04:20:47 2007
@@ -120,7 +120,7 @@
         // Setup the command context and pass it to the command instance
         CommandContext context = new CommandContext() {
             // Command instances get their own namespace with defaults from the current
-            final Variables vars = new VariablesImpl(env.getVariables());
+            final Variables vars = new DefaultVariables(env.getVariables());
 
             public IO getIO() {
                 return env.getIO();

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java
(from r576639, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java&r1=576639&r2=576846&rev=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java
Tue Sep 18 04:20:47 2007
@@ -19,158 +19,47 @@
 
 package org.apache.geronimo.gshell;
 
-import java.util.Map;
-
-import org.apache.geronimo.gshell.command.IO;
-import org.apache.geronimo.gshell.command.Variables;
-import org.apache.geronimo.gshell.common.StopWatch;
-import org.apache.geronimo.gshell.lookup.EnvironmentLookup;
-import org.apache.geronimo.gshell.lookup.IOLookup;
 import org.apache.geronimo.gshell.shell.Environment;
-import org.apache.geronimo.gshell.shell.InteractiveShell;
-import org.apache.geronimo.gshell.shell.ShellInfo;
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.classworlds.ClassWorld;
-import org.codehaus.plexus.component.factory.ComponentFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.command.IO;
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 
 /**
- * A simple facade over GShell, sets up the container for you... you just run commands :-)
+ * Default {@link Environment} implementation.
  *
  * @version $Rev$ $Date$
  */
-public class GShell
-    implements InteractiveShell
+public class DefaultEnvironment
+    implements Environment
 {
-    private Logger log = LoggerFactory.getLogger(getClass());
-
-    private final ClassWorld classWorld;
-
     private final IO io;
-    
-    private final PlexusContainer container;
 
-    private final SecurityManager sm;
+    private final Variables vars;
 
-    private final InteractiveShell shell;
-
-    public GShell(final IO io) throws Exception {
-        this(new ClassWorld("gshell", Thread.currentThread().getContextClassLoader()), io);
-    }
-
-    public GShell(final ClassWorld classWorld, final IO io) throws Exception {
-        assert classWorld != null;
+    public DefaultEnvironment(final IO io, final Variables vars) {
         assert io != null;
+        assert vars != null;
 
-        this.classWorld = classWorld;
         this.io = io;
+        this.vars = vars;
 
-        // Lets time how long init takes
-        StopWatch watch = new StopWatch(true);
-
-        log.debug("Initializing");
-
-        sm = new ShellSecurityManager();
-
-        SecurityManager psm = System.getSecurityManager();
-        System.setSecurityManager(sm);
-
-        try {
-            ContainerConfiguration config = new DefaultContainerConfiguration();
-            config.setName("gshell.core");
-            config.setClassWorld(classWorld);
-            container = new DefaultPlexusContainer(config);
-
-            // We first need to stuff in the IO context for the new shell instance
-            IOLookup ioLookup = (IOLookup) container.lookup(ComponentFactory.class, IOLookup.class.getSimpleName());
-            ioLookup.set(io);
-
-            // And then lets stuff in the environment too
-            Environment env = new Environment() {
-                final Variables vars = new VariablesImpl();
-
-                public IO getIO() {
-                    return io;
-                }
-
-                public Variables getVariables() {
-                    return vars;
-                }
-            };
-
-            EnvironmentLookup envLookup = (EnvironmentLookup) container.lookup(ComponentFactory.class,
EnvironmentLookup.class.getSimpleName());
-            envLookup.set(env);
-
-            // And then do some setup some default variables
-            env.getVariables().set("env", System.getenv());
-
-            // Then look up the shell we are gonna delegate to
-            shell = (InteractiveShell) container.lookup(InteractiveShell.class);
-        }
-        finally {
-            System.setSecurityManager(psm);
-        }
-
-        log.debug("Initialized in {}", watch);
+        // And then do some setup some default variables
+        vars.set("env", System.getenv());
     }
 
-    public ShellInfo getShellInfo() {
-        return shell.getShellInfo();
+    public DefaultEnvironment(final IO io) {
+        this(io, new DefaultVariables());
     }
 
-    public Environment getEnvironment() {
-        return shell.getEnvironment();
+    public IO getIO() {
+        return io;
     }
 
-    public Object execute(final String line) throws Exception {
-        SecurityManager psm = System.getSecurityManager();
-        System.setSecurityManager(sm);
-
-        try {
-            return shell.execute(line);
-        }
-        finally {
-            System.setSecurityManager(psm);
-        }
+    public Variables getVariables() {
+        return vars;
     }
 
-    public Object execute(final Object... args) throws Exception {
-        SecurityManager psm = System.getSecurityManager();
-        System.setSecurityManager(sm);
-
-        try {
-            return shell.execute((Object[])args);
-        }
-        finally {
-            System.setSecurityManager(psm);
-        }
-    }
-
-    public Object execute(final String path, final Object[] args) throws Exception {
-        SecurityManager psm = System.getSecurityManager();
-        System.setSecurityManager(sm);
-
-        try {
-            return shell.execute(path, args);
-        }
-        finally {
-            System.setSecurityManager(psm);
-        }
-    }
-    
-    public void run(final Object... args) throws Exception {
-        SecurityManager psm = System.getSecurityManager();
-        System.setSecurityManager(sm);
-
-        try {
-            shell.run(args);
-        }
-        finally {
-            System.setSecurityManager(psm);
-        }
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this);
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultEnvironment.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java?rev=576846&r1=576845&r2=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultShell.java
Tue Sep 18 04:20:47 2007
@@ -124,7 +124,7 @@
     public void run(final Object... args) throws Exception {
         assert args != null;
 
-        log.debug("Starting interactive console");
+        log.debug("Starting interactive console; args: {}", args);
 
         loadUserScript(branding.getInteractiveScriptName());
 

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java
(from r576639, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/VariablesImpl.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/VariablesImpl.java&r1=576639&r2=576846&rev=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/VariablesImpl.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java
Tue Sep 18 04:20:47 2007
@@ -26,13 +26,14 @@
 import java.util.Set;
 
 import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 
 /**
- * Variables backed up by a map.
+ * Default {@link Variables} implementation.
  *
  * @version $Rev$ $Date$
  */
-public class VariablesImpl
+public class DefaultVariables
     implements Variables
 {
     private final Map<String,Object> map;
@@ -41,7 +42,7 @@
 
     private final Set<String> immutables = new HashSet<String>();
 
-    public VariablesImpl(final Map<String,Object> map, final Variables parent) {
+    public DefaultVariables(final Map<String,Object> map, final Variables parent) {
         assert map != null;
         assert parent != null;
 
@@ -49,24 +50,28 @@
         this.parent = parent;
     }
 
-    public VariablesImpl(final Variables parent) {
+    public DefaultVariables(final Variables parent) {
         assert parent != null;
 
         this.map = new HashMap<String,Object>();
         this.parent = parent;
     }
 
-    public VariablesImpl(final Map<String,Object> map) {
+    public DefaultVariables(final Map<String,Object> map) {
         assert map != null;
 
         this.map = map;
         this.parent = null;
     }
 
-    public VariablesImpl() {
+    public DefaultVariables() {
         this(new HashMap<String,Object>());
     }
 
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this);
+    }
+    
     public void set(final String name, final Object value) {
         set(name, value, true);
     }

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultVariables.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java?rev=576846&r1=576845&r2=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
Tue Sep 18 04:20:47 2007
@@ -19,10 +19,7 @@
 
 package org.apache.geronimo.gshell;
 
-import java.util.Map;
-
 import org.apache.geronimo.gshell.command.IO;
-import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.common.StopWatch;
 import org.apache.geronimo.gshell.lookup.EnvironmentLookup;
 import org.apache.geronimo.gshell.lookup.IOLookup;
@@ -90,23 +87,9 @@
             ioLookup.set(io);
 
             // And then lets stuff in the environment too
-            Environment env = new Environment() {
-                final Variables vars = new VariablesImpl();
-
-                public IO getIO() {
-                    return io;
-                }
-
-                public Variables getVariables() {
-                    return vars;
-                }
-            };
-
+            Environment env = new DefaultEnvironment(io);
             EnvironmentLookup envLookup = (EnvironmentLookup) container.lookup(ComponentFactory.class,
EnvironmentLookup.class.getSimpleName());
             envLookup.set(env);
-
-            // And then do some setup some default variables
-            env.getVariables().set("env", System.getenv());
 
             // Then look up the shell we are gonna delegate to
             shell = (InteractiveShell) container.lookup(InteractiveShell.class);

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java?rev=576846&r1=576845&r2=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
Tue Sep 18 04:20:47 2007
@@ -27,6 +27,7 @@
 import com.thoughtworks.xstream.annotations.Annotations;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 import com.thoughtworks.xstream.io.xml.DomDriver;
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 
 /**
  * The root container for a layout tree.
@@ -54,6 +55,10 @@
         return name;
     }
 
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this);
+    }
+    
     //
     // XML Conversion
     //

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java?rev=576846&r1=576845&r2=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Node.java
Tue Sep 18 04:20:47 2007
@@ -19,6 +19,8 @@
 
 package org.apache.geronimo.gshell.layout.model;
 
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+
 /**
  * The rudimentary elemnet of a layout.
  *
@@ -36,5 +38,9 @@
 
     public String getName() {
         return name;
+    }
+
+    public String toString() {
+        return ReflectionToStringBuilder.toString(this);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/VariablesImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/VariablesImplTest.java?rev=576846&r1=576845&r2=576846&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/VariablesImplTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/VariablesImplTest.java
Tue Sep 18 04:20:47 2007
@@ -25,7 +25,7 @@
 import org.apache.geronimo.gshell.command.Variables;
 
 /**
- * Unit tests for the {@link VariablesImpl} class.
+ * Unit tests for the {@link DefaultVariables} class.
  *
  * @version $Rev$ $Date$
  */
@@ -33,7 +33,7 @@
     extends TestCase
 {
     public void testSet() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         String name = "a";
         Object value = new Object();
 
@@ -49,7 +49,7 @@
     }
 
     public void testSetAsImmutable() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         String name = "a";
         Object value = new Object();
 
@@ -67,8 +67,8 @@
     }
 
     public void testSetAsImmutableInParent() throws Exception {
-        Variables parent = new VariablesImpl();
-        VariablesImpl vars = new VariablesImpl(parent);
+        Variables parent = new DefaultVariables();
+        DefaultVariables vars = new DefaultVariables(parent);
         String name = "a";
         Object value = new Object();
 
@@ -86,8 +86,8 @@
     }
 
     public void testSetParentFromChild() throws Exception {
-        Variables parent = new VariablesImpl();
-        VariablesImpl vars = new VariablesImpl(parent);
+        Variables parent = new DefaultVariables();
+        DefaultVariables vars = new DefaultVariables(parent);
         String name = "a";
         Object value = new Object();
 
@@ -100,7 +100,7 @@
     }
 
     public void testGet() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         String name = "a";
         Object value = new Object();
 
@@ -113,7 +113,7 @@
     }
 
     public void testGetUsingDefault() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         String name = "a";
         Object value = new Object();
 
@@ -125,8 +125,8 @@
     }
 
     public void testGetCloaked() throws Exception {
-        Variables parent = new VariablesImpl();
-        VariablesImpl vars = new VariablesImpl(parent);
+        Variables parent = new DefaultVariables();
+        DefaultVariables vars = new DefaultVariables(parent);
         String name = "a";
         Object value = new Object();
 
@@ -143,7 +143,7 @@
     }
 
     public void testUnsetAsImmutable() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         String name = "a";
         Object value = new Object();
 
@@ -161,8 +161,8 @@
     }
 
     public void testUnsetAsImmutableInParent() throws Exception {
-        Variables parent = new VariablesImpl();
-        VariablesImpl vars = new VariablesImpl(parent);
+        Variables parent = new DefaultVariables();
+        DefaultVariables vars = new DefaultVariables(parent);
         String name = "a";
         Object value = new Object();
 
@@ -180,8 +180,8 @@
     }
 
     public void testCloaking() throws Exception {
-        Variables parent = new VariablesImpl();
-        VariablesImpl vars = new VariablesImpl(parent);
+        Variables parent = new DefaultVariables();
+        DefaultVariables vars = new DefaultVariables(parent);
         String name = "a";
         Object value = new Object();
 
@@ -194,24 +194,24 @@
     }
 
     public void testParent() throws Exception {
-        Variables parent = new VariablesImpl();
+        Variables parent = new DefaultVariables();
         assertNull(parent.parent());
 
-        VariablesImpl vars = new VariablesImpl(parent);
+        DefaultVariables vars = new DefaultVariables(parent);
         assertNotNull(vars.parent());
 
         assertEquals(parent, vars.parent());
     }
 
     public void testNames() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         Iterator<String> iter = vars.names();
         assertNotNull(iter);
         assertFalse(iter.hasNext());
     }
 
     public void testNamesImmutable() throws Exception {
-        VariablesImpl vars = new VariablesImpl();
+        DefaultVariables vars = new DefaultVariables();
         vars.set("a", "b");
 
         Iterator<String> iter = vars.names();



Mime
View raw message