You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ch...@apache.org on 2007/12/07 04:37:24 UTC

svn commit: r601973 - in /servicemix/branches/servicemix-4.0/runtime/gshell: gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/ gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ gshell-core/src/main/resources/META-INF/spring/ gshell-...

Author: chirino
Date: Thu Dec  6 19:37:23 2007
New Revision: 601973

URL: http://svn.apache.org/viewvc?rev=601973&view=rev
Log:
Another way of doing subshells.  This time we actually create a whole new DefaultShell for the sub shell.


Added:
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java   (with props)
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java   (with props)
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java   (with props)
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java   (with props)
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java   (with props)
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java   (with props)
Modified:
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/pom.xml
    servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/resources/META-INF/spring/gshell-osgi.xml

Added: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java?rev=601973&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java (added)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java Thu Dec  6 19:37:23 2007
@@ -0,0 +1,10 @@
+package org.apache.geronimo.gshell.osgi;
+
+import org.apache.geronimo.gshell.branding.Branding;
+import org.apache.geronimo.gshell.command.CommandContext;
+
+public interface SubShell {
+	
+	public Object execute(Branding branding, CommandContext context, Object... args) throws Exception;
+	
+}

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/osgi/SubShell.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java?rev=601973&r1=601972&r2=601973&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java (original)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/GShell.java Thu Dec  6 19:37:23 2007
@@ -77,9 +77,7 @@
     }
 
     public void run() {
-        try {        	
-        	waitForFrameworkToStart();
-        	
+        try {        	        	
             IOTargetSource.setIO(io);
             EnvironmentTargetSource.setEnvironment(env);
 	        
@@ -90,7 +88,7 @@
 	        
 	        // If a command was specified on the command line, then just execute that command.
 			if (args != null && args.length > 0) {
-                System.out.println("Executing 1 command: " + Arrays.toString(args));
+	        	waitForFrameworkToStart();
 				Object value = shell.execute((Object[])args);
 	        	if (mainService != null) {
 	        		if( value instanceof Number ) {
@@ -100,7 +98,6 @@
 	        		}
 	        	}
 			} else {
-	        	System.out.println("going int interactive loop:");
 				// Otherwise go into a command shell.
 	            shell.run();
 	        	if( mainService!=null ) {
@@ -116,7 +113,6 @@
         	if( mainService!=null ) {
         		mainService.setExitCode(-1);
         	}
-            e.printStackTrace();
         } finally {
         	try {
 				getBundleContext().getBundle(0).stop();
@@ -133,21 +129,20 @@
      * @throws InterruptedException
      */
 	private void waitForFrameworkToStart() throws InterruptedException {
-		System.out.println("Waiting for system to startup...");
-		getBundleContext().addFrameworkListener(new FrameworkListener(){
-			public void frameworkEvent(FrameworkEvent event) {
-				System.out.println("Got event: "+event.getType());
-				if( event.getType() == FrameworkEvent.STARTED ) {
-					frameworkStarted.countDown();
-				}
-			}
-		});
-		
-		if( frameworkStarted.await(5, TimeUnit.SECONDS) ) {
-			System.out.println("System completed startup.");
-		} else {
-			System.out.println("System took too long startup... continuing");
-		}
+//		getBundleContext().addFrameworkListener(new FrameworkListener(){
+//			public void frameworkEvent(FrameworkEvent event) {
+//				System.out.println("Got event: "+event.getType());
+//				if( event.getType() == FrameworkEvent.STARTED ) {
+//					frameworkStarted.countDown();
+//				}
+//			}
+//		});
+//		
+//		if( frameworkStarted.await(5, TimeUnit.SECONDS) ) {
+//			System.out.println("System completed startup.");
+//		} else {
+//			System.out.println("System took too long startup... continuing");
+//		}
 	}
 
 	public MainService getMainService() {

Added: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java?rev=601973&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java (added)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java Thu Dec  6 19:37:23 2007
@@ -0,0 +1,133 @@
+package org.apache.geronimo.gshell.spring;
+/*
+ * 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.
+ */
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.layout.NotFoundException;
+import org.apache.geronimo.gshell.layout.model.CommandNode;
+import org.apache.geronimo.gshell.layout.model.GroupNode;
+import org.apache.geronimo.gshell.layout.model.Layout;
+import org.apache.geronimo.gshell.layout.model.Node;
+
+/**
+ * The spring implementation of the {@link LayoutManager}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OsgiLayoutManager implements LayoutManager 
+{
+	private final HashMap<String, Layout> layouts = new HashMap<String, Layout>();
+	private String shell = "";
+	
+    public void register(final Command command, Map<String, ?> properties) {
+    	String shellName = (String) properties.get("shell");
+    	if( shellName!=null ) {
+        	Layout layout = getLayoutForShell(shellName);
+    		
+        	String id = command.getId();
+        	String alias = (String) properties.get("alias");
+        	if( alias == null ) {
+	        	alias = id;
+	        	int p;
+	        	if( (p=alias.lastIndexOf(":")) >= 0 ) {
+	        		alias = alias.substring(p+1);
+	        	}
+	        	layout.add(new CommandNode(alias, id));    		
+        	} else {
+        		String[] aliases = alias.split(",");
+        		for (String a : aliases) {
+        			a = a.trim();
+					if( a.length()> 0 ) {
+			        	layout.add(new CommandNode(a, id));    		
+					}
+				}
+        	}
+        	
+    	}
+    }
+
+
+    public void unregister(final Command command, Map<String, ?> properties) {
+    	// TODO: layout does not allow removal of commands at this time.    	
+    }
+    
+	public Node findNode(String path) throws NotFoundException {
+		return findNode(getLayout(), path);
+	}
+
+	public Node findNode(Node start, String path) throws NotFoundException {
+        assert start != null;
+        assert path != null;
+
+        if (!(start instanceof GroupNode)) {
+        	throw new NotFoundException(path);
+        }
+        
+        Node node = ((GroupNode)start).find(path);
+        if (node == null) {
+            throw new NotFoundException(path);
+        }
+        
+        return node;        
+	}
+
+	public Layout getLayout() {
+		return getLayoutForShell(shell);
+	}
+	
+	public Layout getLayoutForShell(String shellName) {
+		Layout layout = layouts.get(shellName);
+		if( layout == null ) {
+			layout = new Layout();
+			layouts.put(shellName, layout);
+		}
+		return layout;
+	}
+	
+	public String getShell() {
+		return shell;
+	}
+
+	public void setShell(String shell) {
+		this.shell = shell;
+	}
+
+	public LayoutManager createLayoutManagerForShell(final String shell) {
+		return new LayoutManager() {
+
+			public Node findNode(String path) throws NotFoundException {
+				return OsgiLayoutManager.this.findNode(getLayoutForShell(shell), path);
+			}
+
+			public Node findNode(Node node, String path) throws NotFoundException {
+				return OsgiLayoutManager.this.findNode(node, path);
+			}
+
+			public Layout getLayout() {
+				return getLayoutForShell(shell);
+			}
+		};
+	}
+
+}
\ No newline at end of file

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiLayoutManager.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java?rev=601973&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java (added)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java Thu Dec  6 19:37:23 2007
@@ -0,0 +1,111 @@
+package org.apache.geronimo.gshell.spring;
+
+import jline.Terminal;
+
+import org.apache.geronimo.gshell.DefaultEnvironment;
+import org.apache.geronimo.gshell.DefaultShell;
+import org.apache.geronimo.gshell.DefaultShellInfo;
+import org.apache.geronimo.gshell.DefaultVariables;
+import org.apache.geronimo.gshell.ExitNotification;
+import org.apache.geronimo.gshell.branding.Branding;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandExecutor;
+import org.apache.geronimo.gshell.osgi.SubShell;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
+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.personality.plexus.lifecycle.phase.InitializationException;
+
+public class OsgiSubShell implements SubShell {
+
+	private CommandRegistry commandRegistry;
+	private OsgiLayoutManager osgiLayoutManager;
+	private Terminal terminal;
+
+	public Object execute(Branding branding, CommandContext context, Object... args) throws Exception {
+		ShellContext oldContext = ShellContext.get();
+		ShellContext ctx = new ShellContext();
+		ShellContext.set(ctx);
+		try {
+			ctx.setIo(context.getIO());
+			ctx.setCommandRegistry(commandRegistry);
+			ctx.setTerminal(terminal);
+			ctx.setBranding(branding);
+			ctx.setLayoutManager(osgiLayoutManager.createLayoutManagerForShell(branding.getName()));
+			
+			// Would be nice to copy the env variables.. but can't cause it has imutable values
+			// that the DefaultEnvironment tries to overwrite.
+			Environment environment = new DefaultEnvironment(ctx.getIo(), new DefaultVariables());
+			ctx.setEnvironment(environment);
+	        IOTargetSource.setIO(ctx.getIo());
+	        EnvironmentTargetSource.setEnvironment(environment);
+			InteractiveShell interactiveShell = createInteractiveShell(ctx);
+			if( args!=null && args.length>0 ) {
+				return interactiveShell.execute(args);
+			} else {
+				try {
+					interactiveShell.run();
+				} catch (ExitNotification e) {
+					return null;
+				}
+			}
+			return null;
+		} finally {
+			ShellContext.set(oldContext);
+		}
+	}
+
+	private InteractiveShell createInteractiveShell(ShellContext ctx) throws InitializationException {
+		CommandExecutor executor = createCommandExecutor(ctx);
+		ctx.setCommandExecutor(executor);
+		ShellInfo shellInfo = createShellInfo(ctx.getBranding());
+		ctx.setShellInfo(shellInfo);
+		return new DefaultShell(ctx.getShellInfo(), ctx.getBranding(), ctx.getCommandExecutor(), terminal, ctx.getEnvironment(), ctx.getIo());
+	}
+
+	private CommandExecutor createCommandExecutor(ShellContext ctx) {
+		SpringCommandExecutor executor = new SpringCommandExecutor();
+		executor.setEnv(ctx.getEnvironment());
+		executor.setLayoutManager(ctx.getLayoutManager());
+		SpringCommandLineBuilder commandLineBuilder = new SpringCommandLineBuilder();
+		commandLineBuilder.setEnvironment(ctx.getEnvironment());
+		commandLineBuilder.setExecutor(executor);
+		executor.setCommandLineBuilder(commandLineBuilder);
+		executor.setCommandRegistry(commandRegistry);
+		executor.init();
+		return executor;
+	}
+
+	private ShellInfo createShellInfo(Branding branding) throws InitializationException {
+		DefaultShellInfo rc = new DefaultShellInfo(branding);
+		rc.initialize();
+		return rc;
+	}
+
+	public Terminal getTerminal() {
+		return terminal;
+	}
+
+	public void setTerminal(Terminal terminal) {
+		this.terminal = terminal;
+	}
+
+	public OsgiLayoutManager getOsgiLayoutManager() {
+		return osgiLayoutManager;
+	}
+
+	public void setOsgiLayoutManager(OsgiLayoutManager osgiLayoutManager) {
+		this.osgiLayoutManager = osgiLayoutManager;
+	}
+
+	public CommandRegistry getCommandRegistry() {
+		return commandRegistry;
+	}
+
+	public void setCommandRegistry(CommandRegistry commandRegistry) {
+		this.commandRegistry = commandRegistry;
+	}
+
+
+}

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/OsgiSubShell.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java?rev=601973&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java (added)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java Thu Dec  6 19:37:23 2007
@@ -0,0 +1,98 @@
+package org.apache.geronimo.gshell.spring;
+
+import jline.Terminal;
+
+import org.apache.geronimo.gshell.branding.Branding;
+import org.apache.geronimo.gshell.command.CommandExecutor;
+import org.apache.geronimo.gshell.command.IO;
+import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
+import org.apache.geronimo.gshell.shell.Environment;
+import org.apache.geronimo.gshell.shell.ShellInfo;
+
+public class ShellContext {
+	
+	static private final ThreadLocal<ShellContext> context = new ThreadLocal<ShellContext>();
+	
+	static public ShellContext get() {
+		return context.get();
+	}
+	
+	static public void set(ShellContext ctx) {
+		context.set(ctx);
+	}
+	
+	private CommandRegistry commandRegistry;
+	private LayoutManager layoutManager;
+	private Branding branding;
+	private IO io;
+	private Environment environment;
+	private CommandExecutor commandExecutor;
+	private Terminal terminal;
+	private ShellInfo shellInfo;
+
+	public CommandRegistry getCommandRegistry() {
+		return commandRegistry;
+	}
+
+	public void setCommandRegistry(CommandRegistry commandRegistry) {
+		this.commandRegistry = commandRegistry;
+	}
+
+	public LayoutManager getLayoutManager() {
+		return layoutManager;
+	}
+
+	public void setLayoutManager(LayoutManager layoutManager) {
+		this.layoutManager = layoutManager;
+	}
+
+	public Branding getBranding() {
+		return branding;
+	}
+
+	public void setBranding(Branding branding) {
+		this.branding = branding;
+	}
+
+	public void setIo(IO io) {
+		this.io = io;
+	}
+
+	public IO getIo() {
+		return io;
+	}
+
+	public void setCommandExecutor(CommandExecutor commandExecutor) {
+		this.commandExecutor = commandExecutor;
+	}
+	public CommandExecutor getCommandExecutor() {
+		return commandExecutor;
+	}
+
+	public void setTerminal(Terminal terminal) {
+		this.terminal = terminal;
+	}
+	public Terminal getTerminal() {
+		return terminal;
+	}
+
+	public void setShellInfo(ShellInfo shellInfo) {
+		this.shellInfo = shellInfo;
+	}
+	public ShellInfo getShellInfo() {
+		return shellInfo;
+	}
+
+	public void setEnvironment(Environment environment) {
+		this.environment=environment;
+	}
+
+	public Environment getEnvironment() {
+		return environment;
+	}
+
+
+	
+	
+}

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/ShellContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java?rev=601973&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java (added)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java Thu Dec  6 19:37:23 2007
@@ -0,0 +1,168 @@
+package org.apache.geronimo.gshell.spring;
+
+/*
+ * 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.
+ */
+
+import org.apache.geronimo.gshell.ansi.Code;
+import org.apache.geronimo.gshell.ansi.Renderer;
+import org.apache.geronimo.gshell.branding.Branding;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.layout.LayoutManager;
+import org.apache.geronimo.gshell.layout.model.AliasNode;
+import org.apache.geronimo.gshell.layout.model.CommandNode;
+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;
+
+/**
+ * Display help
+ *
+ * @version $Rev$ $Date$
+ */
+@CommandComponent(id="osgi-builtins:help", description="Show command help")
+public class SubShellHelpCommand
+    extends CommandSupport
+{
+    @Argument(metaVar="COMMAND", description="Display help for COMMAND")
+    private String command;
+
+    private Renderer renderer = new Renderer();
+
+    public SubShellHelpCommand() {
+    }
+
+    protected Object doExecute() throws Exception {
+        io.out.println();
+
+        if (command == null) {
+            displayAvailableCommands();
+        }
+        else {
+            displayCommandHelp(command);
+        }
+
+        return SUCCESS;
+    }
+
+    private void displayAvailableCommands() throws Exception {
+    	LayoutManager layoutManager=getLayoutManager();
+        Branding branding=getBranding();
+
+        io.out.print(branding.getAbout());
+        io.out.println();
+        io.out.println("Available commands:");
+
+        GroupNode group = layoutManager.getLayout();
+
+        displayGroupCommands(group);
+    }
+
+    private Branding getBranding() {
+		return ShellContext.get().getBranding();
+	}
+
+	private LayoutManager getLayoutManager() {
+		return ShellContext.get().getLayoutManager();
+	}
+
+	private CommandRegistry getCommandRegistry() {
+		return ShellContext.get().getCommandRegistry();
+	}
+
+	private void displayGroupCommands(final GroupNode group) throws Exception {
+        CommandRegistry commandRegistry=getCommandRegistry();
+        int maxNameLen = 20; // FIXME: Figure this out dynamically
+
+        // First display command/aliases nodes
+        for (Node child : group.nodes()) {
+            if (child instanceof CommandNode) {
+                try {
+                    CommandNode node = (CommandNode) child;
+                    String name = StringUtils.rightPad(node.getName(), maxNameLen);
+
+                    Command command = commandRegistry.lookup(node.getId());
+                    String desc = command.getDescription();
+
+                    io.out.print("  ");
+                    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) {
+                AliasNode node = (AliasNode) child;
+                String name = StringUtils.rightPad(node.getName(), maxNameLen);
+
+                io.out.print("  ");
+                io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+                io.out.print("  ");
+
+                io.out.print("Alias to: ");
+                io.out.println(renderer.render(Renderer.encode(node.getCommand(), Code.BOLD)));
+            }
+        }
+
+        io.out.println();
+
+        // Then groups
+        for (Node child : group.nodes()) {
+            if (child instanceof GroupNode) {
+                GroupNode node = (GroupNode) child;
+
+                io.out.print("  ");
+                io.out.println(renderer.render(Renderer.encode(node.getPath(), Code.BOLD)));
+
+                io.out.println();
+                displayGroupCommands(node);
+                io.out.println();
+            }
+        }
+    }
+
+    private void displayCommandHelp(final String path) throws Exception {
+        assert path != null;
+        CommandRegistry commandRegistry=getCommandRegistry();
+
+        Command cmd = commandRegistry.lookup(path);
+
+        if (cmd == null) {
+            io.out.println("Command " + Renderer.encode(path, Code.BOLD) + " not found.");
+            io.out.println("Try " + Renderer.encode("help", Code.BOLD) + " for a list of available commands.");
+        }
+        else {
+            io.out.println("Command " + Renderer.encode(path, Code.BOLD));
+            io.out.println("   " + cmd.getDescription());
+        }
+
+        io.out.println();
+    }
+}

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/java/org/apache/geronimo/gshell/spring/SubShellHelpCommand.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml?rev=601973&r1=601972&r2=601973&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml (original)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml Thu Dec  6 19:37:23 2007
@@ -36,19 +36,45 @@
         <osgi:listener ref="commandRegistry" bind-method="register" unbind-method="unregister" />
     </osgi:list>
 
-    <osgi:service ref="clear" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="help" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="exit" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="set" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="unset" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="source" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="echo" interface="org.apache.geronimo.gshell.command.Command" />
+    <osgi:list id="smxCommands" interface="org.apache.geronimo.gshell.command.Command">
+        <osgi:listener ref="layoutManager" bind-method="register" unbind-method="unregister" />
+    </osgi:list>
+
+    <osgi:service ref="subShell" interface="org.apache.geronimo.gshell.osgi.SubShell"/>
+
+    <osgi:service ref="clear" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="smx"/></osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="help" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+      	<entry key="shell" value="smx"/>
+      	<entry key="alias" value="help,?"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="exit" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="smx"/></osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="set" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="smx"/></osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="unset" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="smx"/></osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="source" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+      	<entry key="shell" value="smx"/>
+      	<entry key="alias" value="source,."/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="echo" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="smx"/></osgi:service-properties>
+    </osgi:service>
 
     <osgi:service ref="rsh" interface="org.apache.geronimo.gshell.command.Command" />
 

Modified: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml?rev=601973&r1=601972&r2=601973&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml (original)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml Thu Dec  6 19:37:23 2007
@@ -62,6 +62,10 @@
         <constructor-arg ref="branding" />
     </bean>
 
+    <bean id="layoutManager" class="org.apache.geronimo.gshell.spring.OsgiLayoutManager">
+      <property name="shell" value="smx" />
+    </bean>
+
     <bean id="commandRegistry" class="org.apache.geronimo.gshell.spring.SpringCommandRegistry">
         <constructor-arg ref="environment" />
         <property name="groupAliases">
@@ -87,6 +91,12 @@
       <property name="targetSource">
           <bean class="org.apache.geronimo.gshell.spring.IOTargetSource" />
       </property>
+    </bean>
+    
+    <bean id="subShell" class="org.apache.geronimo.gshell.spring.OsgiSubShell">
+      <property name="commandRegistry" ref="commandRegistry"/>
+      <property name="osgiLayoutManager" ref="layoutManager"/>
+      <property name="terminal" ref="terminal"/>
     </bean>
 
 </beans>

Modified: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/pom.xml?rev=601973&r1=601972&r2=601973&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/pom.xml (original)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/pom.xml Thu Dec  6 19:37:23 2007
@@ -54,7 +54,13 @@
             <groupId>org.springframework.osgi</groupId>
             <artifactId>spring-osgi-core</artifactId>
             <version>${spring.osgi.version}</version>
-        </dependency>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.servicemix.gshell</groupId>
+            <artifactId>org.apache.servicemix.gshell.core</artifactId>
+            <version>4.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>

Added: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java?rev=601973&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java (added)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java Thu Dec  6 19:37:23 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.osgi;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.geronimo.gshell.ansi.RenderWriter;
+import org.apache.geronimo.gshell.branding.BrandingSupport;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Oct 11, 2007
+ * Time: 10:20:37 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@CommandComponent(id="osgi:osgi", description="The OSGI Shell")
+public class OsgiShell extends OsgiCommandSupport {
+	SubShell subShell;
+
+	@Override
+	public Object execute(CommandContext context, Object... args) throws Exception {
+    	BrandingSupport branding = new BrandingSupport() {
+		    public String getAbout() {
+		        StringWriter writer = new StringWriter();
+		        PrintWriter out = new RenderWriter(writer);
+
+		        out.println("For information about @|cyan ServiceMix OSGI|, visit:");
+		        out.println("    @|bold http://servicemix.apache.org| ");
+		        out.flush();
+
+		        return writer.toString();
+		    }
+			
+			public String getName() {
+				return "osgi";
+			}
+
+			@Override
+			public String getDisplayName() {
+				return "OSGI Shell";
+			}
+			
+			public String getVersion() {
+				// TODO: replace this with a version loader.
+				return "1.0";
+			}
+
+			public String getWelcomeBanner() {
+				return "@|bold OSGI Shell| ("+getVersion()+")";
+			}
+    		
+    	};
+    	try {
+			return subShell.execute(branding, context, args);
+		} catch (Throwable e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+	
+	@Override
+	protected Object doExecute() throws Exception {
+		return null;
+	}
+
+	public SubShell getSubShell() {
+		return subShell;
+	}
+
+	public void setSubShell(SubShell subShell) {
+		this.subShell = subShell;
+	}
+
+}

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/java/org/apache/geronimo/gshell/osgi/OsgiShell.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/resources/META-INF/spring/gshell-osgi.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/resources/META-INF/spring/gshell-osgi.xml?rev=601973&r1=601972&r2=601973&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/resources/META-INF/spring/gshell-osgi.xml (original)
+++ servicemix/branches/servicemix-4.0/runtime/gshell/gshell-osgi/src/main/resources/META-INF/spring/gshell-osgi.xml Thu Dec  6 19:37:23 2007
@@ -29,52 +29,149 @@
   http://www.springframework.org/schema/osgi
   http://www.springframework.org/schema/osgi/spring-osgi.xsd">
 
-    <bean id="bundle-level" class="org.apache.geronimo.gshell.osgi.BundleLevel" />
+    <!-- osgi sub shell -->
+    <osgi:reference id="subShell" interface="org.apache.geronimo.gshell.osgi.SubShell"/>
+    <bean id="osgi" class="org.apache.geronimo.gshell.osgi.OsgiShell">
+      <property name="subShell" ref="subShell"/>
+    </bean>
+    <osgi:service ref="osgi" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="smx"/></osgi:service-properties>
+    </osgi:service>
 
+    <!-- osgi commands -->
+    <bean id="bundle-level" class="org.apache.geronimo.gshell.osgi.BundleLevel" />
     <bean id="headers" class="org.apache.geronimo.gshell.osgi.Headers" />
-
     <bean id="install-bundle" class="org.apache.geronimo.gshell.osgi.InstallBundle" />
-
     <bean id="list-bundles" class="org.apache.geronimo.gshell.osgi.ListBundles" />
-
     <bean id="list-services" class="org.apache.geronimo.gshell.osgi.ListServices" />
-
     <bean id="refresh-bundle" class="org.apache.geronimo.gshell.osgi.RefreshBundle" />
-
     <bean id="resolve-bundle" class="org.apache.geronimo.gshell.osgi.ResolveBundle" />
-
     <bean id="shutdown" class="org.apache.geronimo.gshell.osgi.Shutdown" />
-
-    <bean id="start-bundle" class="org.apache.geronimo.gshell.osgi.StartBundle" />
-
+    <bean id="start-bundle" class="org.apache.geronimo.gshell.osgi.StartBundle"/>
     <bean id="start-level" class="org.apache.geronimo.gshell.osgi.StartLevel" />
-
     <bean id="stop-bundle" class="org.apache.geronimo.gshell.osgi.StopBundle" />
-
     <bean id="uninstall-bundle" class="org.apache.geronimo.gshell.osgi.UninstallBundle" />
-
-    <osgi:service ref="bundle-level" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="headers" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="install-bundle" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="list-bundles" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="list-services" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="refresh-bundle" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="resolve-bundle" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="shutdown" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="start-bundle" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="start-level" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="stop-bundle" interface="org.apache.geronimo.gshell.command.Command" />
-
-    <osgi:service ref="uninstall-bundle" interface="org.apache.geronimo.gshell.command.Command" />
-
+    
+    <!-- general commands -->
+    <bean id="clear" class="org.apache.geronimo.gshell.commands.builtins.ClearCommand" />
+    <bean id="echo" class="org.apache.geronimo.gshell.commands.builtins.EchoCommand" />
+    <bean id="exit" class="org.apache.geronimo.gshell.commands.builtins.ExitCommand" />
+    <bean id="help" class="org.apache.geronimo.gshell.spring.SubShellHelpCommand"/>
+    <bean id="set" class="org.apache.geronimo.gshell.commands.builtins.SetCommand" />
+    <bean id="source" class="org.apache.geronimo.gshell.commands.builtins.SourceCommand" />
+    <bean id="unset" class="org.apache.geronimo.gshell.commands.builtins.UnsetCommand" />
+
+    <osgi:service ref="bundle-level" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="bundle-level"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="headers" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="install-bundle" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="install"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="list-bundles" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="list"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="list-services" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="list-services,ls"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="refresh-bundle" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="refresh"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="resolve-bundle" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="resolve"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="shutdown" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="start-bundle" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="start"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="start-level" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="start-level"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="stop-bundle" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="stop"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="uninstall-bundle" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="osgi"/>
+      	<entry key="alias" value="uninstall"/>
+      </osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="clear" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+    
+    <osgi:service ref="help" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+      	<entry key="shell" value="osgi"/>
+      	<entry key="alias" value="help,?"/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="exit" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="set" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="unset" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="source" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+      	<entry key="shell" value="osgi"/>
+      	<entry key="alias" value="source,."/>
+      </osgi:service-properties>
+    </osgi:service>
+
+    <osgi:service ref="echo" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties><entry key="shell" value="osgi"/></osgi:service-properties>
+    </osgi:service>
+    
+    
 </beans>