You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/10/07 10:59:38 UTC
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...
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<String> 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