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 16:37:29 UTC
svn commit: r702494 - in /geronimo/gshell/trunk:
gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/
gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/
gshell-wisdom/gshell-wisdom-core/src/main...
Author: jdillon
Date: Tue Oct 7 07:37:26 2008
New Revision: 702494
URL: http://svn.apache.org/viewvc?rev=702494&view=rev
Log:
More work on groups, based on the content of the 'gshell.group' variable
Changed 'prompt' to 'gshell.prompt'
Modified:
geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java?rev=702494&r1=702493&r2=702494&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java Tue Oct 7 07:37:26 2008
@@ -64,7 +64,7 @@
cwd = (FileObject)var;
}
else if (var != null) {
- throw new RuntimeException("Invalid variable type for '" + CWD + "'; expected String or FileObject; found: " + var.getClass().getName());
+ throw new RuntimeException("Invalid variable type for '" + CWD + "'; expected String or FileObject; found: " + var.getClass());
}
if (cwd == null) {
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/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?rev=702494&r1=702493&r2=702494&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/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 07:37:26 2008
@@ -19,7 +19,7 @@
package org.apache.geronimo.gshell.wisdom.command;
-import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
import org.apache.geronimo.gshell.clp.Argument;
import org.apache.geronimo.gshell.command.CommandAction;
import org.apache.geronimo.gshell.command.CommandContext;
@@ -36,12 +36,12 @@
public class GroupCommand
extends CommandSupport
{
- private final FileName name;
+ private final FileObject file;
- public GroupCommand(final FileName name) {
- assert name != null;
+ public GroupCommand(final FileObject file) {
+ assert file != null;
- this.name = name;
+ this.file = file;
setAction(new GroupCommandAction());
setDocumenter(new GroupCommandDocumenter());
@@ -50,7 +50,7 @@
}
/**
- * ???
+ * Action to set the gshell group.
*/
private class GroupCommandAction
implements CommandAction
@@ -61,8 +61,9 @@
public Object execute(final CommandContext context) throws Exception {
assert context != null;
- // TODO:
- log.debug("Changing to group: {}", name);
+ log.debug("Changing to group: {}", file);
+
+ context.getVariables().parent().set("gshell.group", file);
return Result.SUCCESS;
}
@@ -76,12 +77,12 @@
{
@Override
public String getName() {
- return name.getBaseName();
+ return file.getName().getBaseName();
}
@Override
public String getDescription() {
- return getMessages().format(COMMAND_DESCRIPTION, name.getBaseName());
+ return getMessages().format(COMMAND_DESCRIPTION, file.getName().getBaseName());
}
}
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=702494&r1=702493&r2=702494&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 07:37:26 2008
@@ -89,8 +89,8 @@
// 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;
+ public Command resolveCommand(final Variables vars, final String path) throws CommandException {
+ assert vars != null;
assert path != null;
log.debug("Resolving command for path: {}", path);
@@ -99,18 +99,24 @@
// FIXME: For now just ask for the named stuff, eventually need a better path parser and lookup thingy
//
+ //
+ // FIXME: Handle "/" to get to commandsDirectory. Handle avoiding ../ leading to group dir set to meta:/ (should never go up past meta:/commands)
+ //
+
Command command = findAliasCommand(path);
if (command == null) {
try {
- assert commandsDirectory != null;
- FileObject file = fileSystemAccess.resolveFile(commandsDirectory, path);
+ FileObject dir = getGroupDirectory(vars);
+ FileObject file = fileSystemAccess.resolveFile(dir, path);
+
if (file.exists()) {
command = (Command) file.getContent().getAttribute("COMMAND");
-
+
// Dynamically create group commands
if (command == null && file.getType().hasChildren()) {
command = createGroupCommand(file);
+ file.getContent().setAttribute("COMMAND", command);
}
}
else {
@@ -129,6 +135,36 @@
return command;
}
+ private FileObject getGroupDirectory(final Variables vars) throws FileSystemException {
+ assert vars != null;
+
+ FileObject dir;
+
+ Object tmp = vars.get("gshell.group");
+
+ if (tmp == null) {
+ assert commandsDirectory != null;
+ dir = commandsDirectory;
+ }
+ else if (tmp instanceof String) {
+ log.trace("Resolving group directory from string: {}", tmp);
+ dir = fileSystemAccess.resolveFile(null, (String)tmp);
+ }
+ else if (tmp instanceof FileObject) {
+ dir = (FileObject)tmp;
+ }
+ else {
+ // Complain, then use the default so commands still work
+ log.error("Invalid type for variable 'gshell.group'; expected String or FileObject; found: " + tmp.getClass());
+ assert commandsDirectory != null;
+ dir = commandsDirectory;
+ }
+
+ assert dir != null;
+ return dir;
+ }
+
+
private Command findAliasCommand(final String path) throws CommandException {
assert path != null;
@@ -140,6 +176,7 @@
if (file.exists()) {
command = (Command)file.getContent().getAttribute("COMMAND");
+ // Dynamically create alias commands
if (command == null) {
command = createAliasCommand(file);
file.getContent().setAttribute("COMMAND", command);
@@ -156,15 +193,10 @@
return command;
}
- private Command createAliasCommand(final FileObject file) throws NoSuchAliasException {
+ private Command createAliasCommand(final FileObject file) throws FileSystemException, NoSuchAliasException {
assert file != null;
- return createAliasCommand(file.getName().getBaseName());
- }
-
- private Command createAliasCommand(final String name) throws NoSuchAliasException {
- assert name != null;
-
+ String name = file.getName().getBaseName();
log.debug("Creating command for alias: {}", name);
assert aliasRegistry != null;
@@ -220,8 +252,7 @@
log.debug("Creating command for group: {}", file);
- GroupCommand command = new GroupCommand(file.getName());
- file.getContent().setAttribute("COMMAND", command);
+ GroupCommand command = new GroupCommand(file);
//
// FIXME: Have to inject the container because we are not wiring ^^^, and because its support muck needs some crap
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java?rev=702494&r1=702493&r2=702494&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java Tue Oct 7 07:37:26 2008
@@ -66,7 +66,7 @@
assert application != null;
Variables vars = application.getVariables();
- String pattern = (String) vars.get("prompt");
+ String pattern = (String) vars.get("gshell.prompt");
if (pattern != null) {
assert variablesValueSource != null;
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java?rev=702494&r1=702493&r2=702494&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java Tue Oct 7 07:37:26 2008
@@ -124,7 +124,7 @@
vars.set("SHELL.HISTORY", getHistory(), true);
// HACK: Set the default prompt here for now, probably want to get this from branding
- vars.set("prompt", "@|bold %{application.userName}|@%{application.localHost.hostName}:@|bold %{branding.name}|> ");
+ vars.set("gshell.prompt", "@|bold %{application.userName}|@%{application.localHost.hostName}:@|bold %{branding.name}|> ");
branding = application.getModel().getBranding();