geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r596570 - in /geronimo/gshell/trunk: gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-core/src/main/java/org/apache/geronimo/gshell/ gshell-core/src/main/java/org/apache/geronimo/gshell/layo...
Date Tue, 20 Nov 2007 08:47:27 GMT
Author: gnodet
Date: Tue Nov 20 00:47:27 2007
New Revision: 596570

URL: http://svn.apache.org/viewvc?rev=596570&view=rev
Log:
Allow use of DOM with xstream if Xpp is not in the classpath
Add missing parameter to DefaultCommandExecutor constructor
Use a single constructor for DefaultLayoutManager and introduce a DummyLayoutLoader instead
Allow use of help command even if all commands are not registered (the opposite would be nice
too, ie: displaying commands not in the layout)

Added:
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/loader/DummyLayoutLoader.java
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java
    geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
    geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/DefaultLayoutManagerTest.java

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=596570&r1=596569&r2=596570&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
Tue Nov 20 00:47:27 2007
@@ -33,6 +33,7 @@
 import org.apache.geronimo.gshell.layout.model.GroupNode;
 import org.apache.geronimo.gshell.layout.model.Node;
 import org.apache.geronimo.gshell.registry.CommandRegistry;
+import org.apache.geronimo.gshell.registry.NotRegisteredException;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -96,21 +97,25 @@
         // First display command/aliases nodes
         for (Node child : group.nodes()) {
             if (child instanceof CommandNode) {
-                CommandNode node = (CommandNode) child;
-                String name = StringUtils.rightPad(node.getName(), maxNameLen);
+                try {
+                    CommandNode node = (CommandNode) child;
+                    String name = StringUtils.rightPad(node.getName(), maxNameLen);
 
-                io.out.print("  ");
-                io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+                    Command command = commandRegistry.lookup(node.getId());
+                    String desc = command.getDescription();
 
-                Command command = commandRegistry.lookup(node.getId());
-                String desc = command.getDescription();
-
-                if (desc != null) {
                     io.out.print("  ");
-                    io.out.println(desc);
-                }
-                else {
-                    io.out.println();
+                    io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+
+                    if (desc != null) {
+                        io.out.print("  ");
+                        io.out.println(desc);
+                    }
+                    else {
+                        io.out.println();
+                    }
+                } catch (NotRegisteredException e) {
+                    // Ignore those exceptions (command will not be displayed)
                 }
             }
             else if (child instanceof AliasNode) {

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java?rev=596570&r1=596569&r2=596570&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/DefaultCommandExecutor.java
Tue Nov 20 00:47:27 2007
@@ -65,8 +65,12 @@
 
     public DefaultCommandExecutor() {}
     
-    public DefaultCommandExecutor(final LayoutManager layoutManager, final CommandLineBuilder
commandLineBuilder, final Environment env) {
+    public DefaultCommandExecutor(final LayoutManager layoutManager,
+                                  final CommandRegistry commandRegistry,
+                                  final CommandLineBuilder commandLineBuilder,
+                                  final Environment env) {
         this.layoutManager = layoutManager;
+        this.commandRegistry = commandRegistry;
         this.commandLineBuilder = commandLineBuilder;
         this.env = env;
     }

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java?rev=596570&r1=596569&r2=596570&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java
Tue Nov 20 00:47:27 2007
@@ -59,11 +59,6 @@
         this.env = env;
     }
 
-    public DefaultLayoutManager(final Layout layout, final Environment env) {
-        this.layout = layout;
-        this.env = env;
-    }
-
     public void initialize() throws InitializationException {
         assert loader != null;
 

Added: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/loader/DummyLayoutLoader.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/loader/DummyLayoutLoader.java?rev=596570&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/loader/DummyLayoutLoader.java
(added)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/loader/DummyLayoutLoader.java
Tue Nov 20 00:47:27 2007
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.layout.loader;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gshell.layout.model.Layout;
+
+/**
+ * A layout loader that simply returns an existing Layout
+ */
+public class DummyLayoutLoader implements LayoutLoader {
+
+    private Layout layout;
+
+    public DummyLayoutLoader(Layout layout) {
+        this.layout = layout;
+    }
+
+    public Layout load() throws IOException {
+        return layout;
+    }
+}

Modified: geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java?rev=596570&r1=596569&r2=596570&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/model/Layout.java
Tue Nov 20 00:47:27 2007
@@ -24,6 +24,9 @@
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.annotations.Annotations;
 import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.core.JVM;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+import com.thoughtworks.xstream.io.xml.XppDriver;
 
 /**
  * The root container for a layout tree.
@@ -43,7 +46,14 @@
     //
     
     private static XStream createXStream() {
-        XStream xs = new XStream();
+        XStream xs;
+
+        try {
+            Class.forName("org.xmlpull.mxp1.MXParser");
+            xs = new XStream(new XppDriver());
+        } catch (ClassNotFoundException e) {
+            xs = new XStream(new DomDriver());
+        }
 
         Annotations.configureAliases(xs, Layout.class, GroupNode.class, CommandNode.class,
AliasNode.class);
 

Modified: geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/DefaultLayoutManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/DefaultLayoutManagerTest.java?rev=596570&r1=596569&r2=596570&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/DefaultLayoutManagerTest.java
(original)
+++ geronimo/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/DefaultLayoutManagerTest.java
Tue Nov 20 00:47:27 2007
@@ -22,6 +22,7 @@
 import junit.framework.TestCase;
 import org.apache.geronimo.gshell.DefaultEnvironment;
 import org.apache.geronimo.gshell.command.IO;
+import org.apache.geronimo.gshell.layout.loader.DummyLayoutLoader;
 import org.apache.geronimo.gshell.layout.model.CommandNode;
 import org.apache.geronimo.gshell.layout.model.GroupNode;
 import org.apache.geronimo.gshell.layout.model.Layout;
@@ -47,8 +48,8 @@
         g.add(new CommandNode("foo", "foo"));
         layout.add(g);
 
-        layoutManager = new DefaultLayoutManager(layout, env);
-        // layoutManager.initialize();
+        layoutManager = new DefaultLayoutManager(new DummyLayoutLoader(layout), env);
+        layoutManager.initialize();
     }
 
     public void testFind() throws Exception {



Mime
View raw message