Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 33282 invoked from network); 7 Oct 2008 09:00:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Oct 2008 09:00:29 -0000 Received: (qmail 41845 invoked by uid 500); 7 Oct 2008 09:00:28 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 41810 invoked by uid 500); 7 Oct 2008 09:00:28 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 41801 invoked by uid 99); 7 Oct 2008 09:00:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Oct 2008 02:00:28 -0700 X-ASF-Spam-Status: No, hits=-1999.9 required=10.0 tests=ALL_TRUSTED,DNS_FROM_SECURITYSAGE X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Oct 2008 08:59:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 639DB23888E6; Tue, 7 Oct 2008 01:59:38 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r702398 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main: java/org/apache/geronimo/gshell/wisdom/command/ java/org/apache/geronimo/gshell/wisdom/registry/ resources/org/apache/geronimo/gshell/wisdom/command/ resources/o... Date: Tue, 07 Oct 2008 08:59:38 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081007085938.639DB23888E6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jdillon Date: Tue Oct 7 01:59:37 2008 New Revision: 702398 URL: http://svn.apache.org/viewvc?rev=702398&view=rev Log: Starting to get group commands working Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java (contents, props changed) - copied, changed from r702010, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/AliasCommand.java geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java (contents, props changed) - copied, changed from r702010, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/GroupCommand.java geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/AliasCommand.properties (props changed) - copied unchanged from r702010, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/registry/AliasCommand.properties geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties (with props) Removed: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/AliasCommand.java geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/GroupCommand.java geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/registry/ Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandMetaMapper.java geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java (from r702010, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/AliasCommand.java) URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/AliasCommand.java&r1=702010&r2=702398&rev=702398&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/AliasCommand.java (original) +++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java Tue Oct 7 01:59:37 2008 @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.geronimo.gshell.wisdom.registry; +package org.apache.geronimo.gshell.wisdom.command; import org.apache.geronimo.gshell.clp.Argument; import org.apache.geronimo.gshell.command.CommandAction; @@ -28,10 +28,6 @@ import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource; import org.apache.geronimo.gshell.io.IO; import org.apache.geronimo.gshell.shell.ShellContext; -import org.apache.geronimo.gshell.wisdom.command.CommandSupport; -import org.apache.geronimo.gshell.wisdom.command.HelpSupport; -import org.apache.geronimo.gshell.wisdom.command.MessageSourceCommandDocumenter; -import org.apache.geronimo.gshell.wisdom.command.NullCommandCompleter; import java.util.Iterator; import java.util.List; @@ -132,10 +128,12 @@ private class AliasCommandDocumenter extends MessageSourceCommandDocumenter { + @Override public String getName() { return name; } + @Override public String getDescription() { return getMessages().format(COMMAND_DESCRIPTION, alias); } Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java (from r702010, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/GroupCommand.java) URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/GroupCommand.java&r1=702010&r2=702398&rev=702398&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/GroupCommand.java (original) +++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java Tue Oct 7 01:59:37 2008 @@ -17,11 +17,16 @@ * under the License. */ -package org.apache.geronimo.gshell.wisdom.registry; +package org.apache.geronimo.gshell.wisdom.command; -import org.apache.geronimo.gshell.command.CommandResult; -import org.apache.geronimo.gshell.shell.ShellContext; -import org.apache.geronimo.gshell.wisdom.command.CommandSupport; +import org.apache.commons.vfs.FileName; +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.command.CommandAction; +import org.apache.geronimo.gshell.command.CommandContext; +import org.apache.geronimo.gshell.i18n.MessageSource; +import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource; + +import java.util.List; /** * Group {@link org.apache.geronimo.gshell.command.Command} component. @@ -31,13 +36,69 @@ public class GroupCommand extends CommandSupport { - @Override - public CommandResult execute(final ShellContext context, final Object[] args) { - assert context != null; - assert args != null; - - log.debug("Executing"); - - throw new Error("not implemented"); + private final FileName name; + + public GroupCommand(final FileName name) { + assert name != null; + + this.name = name; + + setAction(new GroupCommandAction()); + setDocumenter(new GroupCommandDocumenter()); + setCompleter(new NullCommandCompleter()); + setMessages(new GroupCommandMessageSource()); + } + + /** + * ??? + */ + private class GroupCommandAction + implements CommandAction + { + @Argument + private List appendArgs = null; + + public Object execute(final CommandContext context) throws Exception { + assert context != null; + + // TODO: + log.debug("Changing to group: {}", name); + + return Result.SUCCESS; + } + } + + /** + * Group command documenter. + */ + private class GroupCommandDocumenter + extends MessageSourceCommandDocumenter + { + @Override + public String getName() { + return name.getBaseName(); + } + + @Override + public String getDescription() { + return getMessages().format(COMMAND_DESCRIPTION, name.getBaseName()); + } + } + + /** + * Group message source. + */ + private class GroupCommandMessageSource + implements MessageSource + { + private final MessageSource messages = new ResourceBundleMessageSource(new Class[] { GroupCommand.class, HelpSupport.class }); + + public String getMessage(final String code) { + return messages.getMessage(code); + } + + public String format(final String code, final Object... args) { + return messages.format(code, args); + } } } \ No newline at end of file Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java ------------------------------------------------------------------------------ svn:executable = * Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandMetaMapper.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandMetaMapper.java?rev=702398&r1=702397&r2=702398&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandMetaMapper.java (original) +++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandMetaMapper.java Tue Oct 7 01:59:37 2008 @@ -60,6 +60,10 @@ if (event instanceof CommandRegisteredEvent) { CommandRegisteredEvent targetEvent = (CommandRegisteredEvent)event; + // + // TODO: Need to allow command instances to be come _aware_ of their mapping (name + path) + // + MetaData data = metaConfig.addFile("/commands/" + targetEvent.getName()); data.addAttribute("COMMAND", targetEvent.getCommand()); } Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java?rev=702398&r1=702397&r2=702398&view=diff ============================================================================== --- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java (original) +++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java Tue Oct 7 01:59:37 2008 @@ -33,6 +33,8 @@ import org.apache.geronimo.gshell.spring.BeanContainerAware; import org.apache.geronimo.gshell.vfs.FileSystemAccess; import org.apache.geronimo.gshell.vfs.FileObjects; +import org.apache.geronimo.gshell.wisdom.command.AliasCommand; +import org.apache.geronimo.gshell.wisdom.command.GroupCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -65,10 +67,13 @@ private FileObject commandsDirectory; + private FileObject aliasesDirectory; + @PostConstruct public void init() throws Exception { assert fileSystemAccess != null; commandsDirectory = fileSystemAccess.resolveFile(null, "meta:/commands"); + aliasesDirectory = fileSystemAccess.resolveFile(null, "meta:/aliases"); } public void setBeanContainer(final BeanContainer container) { @@ -77,6 +82,13 @@ this.container = container; } + // + // TODO: Consider adding an undefined command handler to allow for even more customization of + // execution when no defined command is found? So one can say directly execute a + // *.gsh script, which under the covers will translate into 'source *.gsh' (or really + // should be 'shell *.gsh' once we have a sub-shell command. + // + public Command resolveCommand(final Variables variables, final String path) throws CommandException { assert variables != null; assert path != null; @@ -87,18 +99,19 @@ // FIXME: For now just ask for the named stuff, eventually need a better path parser and lookup thingy // - Command command; + Command command = findAliasCommand(path); - assert aliasRegistry != null; - if (aliasRegistry.containsAlias(path)) { - command = createAliasCommand(path); - } - else { + if (command == null) { try { assert commandsDirectory != null; FileObject file = fileSystemAccess.resolveFile(commandsDirectory, path); if (file.exists()) { command = (Command) file.getContent().getAttribute("COMMAND"); + + // Dynamically create group commands + if (command == null && file.getType().hasChildren()) { + command = createGroupCommand(file); + } } else { throw new NoSuchCommandException(path); @@ -116,6 +129,39 @@ return command; } + private Command findAliasCommand(final String path) throws CommandException { + assert path != null; + + Command command = null; + + try { + assert aliasesDirectory != null; + FileObject file = fileSystemAccess.resolveFile(aliasesDirectory, path); + if (file.exists()) { + command = (Command)file.getContent().getAttribute("COMMAND"); + + if (command == null) { + command = createAliasCommand(file); + file.getContent().setAttribute("COMMAND", command); + } + } + } + catch (FileSystemException e) { + throw new CommandException(e); + } + catch (NoSuchAliasException e) { + // ignore + } + + return command; + } + + private Command createAliasCommand(final FileObject file) throws NoSuchAliasException { + assert file != null; + + return createAliasCommand(file.getName().getBaseName()); + } + private Command createAliasCommand(final String name) throws NoSuchAliasException { assert name != null; @@ -150,11 +196,14 @@ try { for (FileObject file : commandsDirectory.getChildren()) { - // FIXME: For now ignore folders, not yet supported fully - if (!file.getType().hasChildren()) { - Command command = (Command)file.getContent().getAttribute("COMMAND"); - commands.add(command); + Command command = (Command)file.getContent().getAttribute("COMMAND"); + + // Dynamically create group commands + if (command == null && file.getType().hasChildren()) { + command = createGroupCommand(file); } + + commands.add(command); } } catch (FileSystemException e) { @@ -165,4 +214,23 @@ return commands; } + + private Command createGroupCommand(final FileObject file) throws FileSystemException { + assert file != null; + + log.debug("Creating command for group: {}", file); + + GroupCommand command = new GroupCommand(file.getName()); + file.getContent().setAttribute("COMMAND", command); + + // + // FIXME: Have to inject the container because we are not wiring ^^^, and because its support muck needs some crap + // probably need to use a prototype here + // + + assert container != null; + command.setBeanContainer(container); + + return command; + } } Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/AliasCommand.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/AliasCommand.properties ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/AliasCommand.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties?rev=702398&view=auto ============================================================================== --- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties (added) +++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties Tue Oct 7 01:59:37 2008 @@ -0,0 +1,27 @@ +## +## 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. +## + +## +## $Rev$ $Date$ +## + +command.description=Command group: {0} + +command.manual=\ + TODO: general group manual Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/command/GroupCommand.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain