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/10 09:48:08 UTC
svn commit: r703345 - in /geronimo/gshell/trunk:
gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/config/
gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/
gshell-wisdom/gshell-wisdom-core/s...
Author: jdillon
Date: Fri Oct 10 00:48:07 2008
New Revision: 703345
URL: http://svn.apache.org/viewvc?rev=703345&view=rev
Log:
More search-path/group stuff, seems to all be working now
Modified:
geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/config/ConfigurableFileSystemManager.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.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/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml
Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/config/ConfigurableFileSystemManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/config/ConfigurableFileSystemManager.java?rev=703345&r1=703344&r2=703345&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/config/ConfigurableFileSystemManager.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/config/ConfigurableFileSystemManager.java Fri Oct 10 00:48:07 2008
@@ -20,7 +20,12 @@
package org.apache.geronimo.gshell.vfs.config;
import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.NameScope;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Configurable {@link FileSystemManager}.
@@ -30,5 +35,21 @@
public class ConfigurableFileSystemManager
extends DefaultFileSystemManager
{
- // ???
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ /*
+ @Override
+ public FileName resolveName(final FileName root, final String path) throws FileSystemException {
+ return super.resolveName(root, path);
+ }
+ */
+
+ @Override
+ public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException {
+ if (log.isDebugEnabled()) {
+ log.debug("Resolving name; base={}, name={}, scope={}", new Object[] { base, name, scope });
+ }
+
+ return super.resolveName(base, name, scope);
+ }
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/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?rev=703345&r1=703344&r2=703345&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java Fri Oct 10 00:48:07 2008
@@ -61,6 +61,10 @@
setMessages(new AliasCommandMessageSource());
}
+ public AliasCommand() {
+ this(null, null);
+ }
+
public String getName() {
if (name == null) {
throw new IllegalStateException("Missing property: name");
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=703345&r1=703344&r2=703345&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 Fri Oct 10 00:48:07 2008
@@ -32,6 +32,7 @@
import org.apache.geronimo.gshell.vfs.FileSystemAccess;
import org.apache.geronimo.gshell.vfs.provider.meta.MetaFileName;
import org.apache.geronimo.gshell.wisdom.command.GroupCommand;
+import org.apache.geronimo.gshell.wisdom.command.AliasCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,8 +54,14 @@
@Autowired
private FileSystemAccess fileSystemAccess;
+ //
+ // TODO: Consider using FileSystemManager.createVirtualFileSystem() to chroot for resolving?
+ //
+
private FileObject commandsDirectory;
+ private FileObject aliasesDirectory;
+
private BeanContainer container;
public void setBeanContainer(final BeanContainer container) {
@@ -76,38 +83,80 @@
log.debug("Resolving command name: {}", name);
- Command command = null;
-
- try {
- FileObject file = resolveCommandFile(name, variables);
+ // Always try to resolve aliases before we resolve commands
+ Command command = resolveAliasCommand(name, variables);
+
+ if (command == null) {
+ try {
+ FileObject file = resolveCommandFile(name, variables);
- if (file != null) {
- command = createCommand(file);
+ if (file != null) {
+ command = createCommand(file);
+ }
+ }
+ catch (FileSystemException e) {
+ log.warn("Unable to resolve command for name: " + name, e);
}
- }
- catch (FileSystemException e) {
- log.warn("Unable to resolve command for name: " + name, e);
}
if (command == null) {
throw new NoSuchCommandException(name);
}
-
+
log.debug("Resolved command: {}", command);
return command;
}
+ private AliasCommand resolveAliasCommand(final String name, final Variables variables) {
+ assert name != null;
+ assert variables != null;
+
+ log.debug("Resolving alias for name: {}", name);
+
+ AliasCommand command = null;
+
+ try {
+ FileObject file = fileSystemAccess.resolveFile(getAliasesDirectory(), name);
+
+ if (file != null && file.exists()) {
+ log.debug("Resolved file: {}", file);
+
+ // Make sure whatever file we resolved is actually a meta file
+ if (!isMetaFile(file)) {
+ log.warn("Command name '{}' did not resolve to a meta-file; found: {}", name, file);
+ return null;
+ }
+
+ // Make sure we found a file in the meta:/commands tree
+ if (!file.getName().getPath().startsWith("/aliases")) {
+ log.warn("Command name '{}' did not resolve under " + ALIASES_ROOT + "; found: {}", name, file);
+ return null;
+ }
+
+ command = createAliasCommand(file);
+ }
+ }
+ catch (FileSystemException e) {
+ log.warn("Failed to resolve alias command for name: " + name, e);
+ }
+
+ return command;
+ }
+
private FileObject resolveCommandFile(final String name, final Variables variables) throws FileSystemException {
assert name != null;
assert variables != null;
log.debug("Resolving command file: {}", name);
- // Special handling for root
+ // Special handling for root & group
if (name.equals("/")) {
return getCommandsDirectory();
}
+ else if (name.equals(".")) {
+ return getGroupDirectory(variables);
+ }
String[] searchPath = getSearchPath(variables);
@@ -122,7 +171,17 @@
for (String pathElement : searchPath) {
log.debug("Resolving file; name={}, pathElement={}", name, pathElement);
- FileObject dir = fileSystemAccess.resolveFile(null, groupDir.getName().getURI() + "/" + pathElement);
+ FileObject dir;
+
+ if (pathElement.equals("/")) {
+ dir = getCommandsDirectory();
+ }
+ else if (pathElement.startsWith("/")) {
+ dir = fileSystemAccess.resolveFile(getCommandsDirectory(), pathElement.substring(1, pathElement.length()));
+ }
+ else {
+ dir = fileSystemAccess.resolveFile(groupDir, pathElement);
+ }
log.debug("Dir: {}", dir);
@@ -167,8 +226,8 @@
log.error("Invalid type for variable '" + PATH + "'; expected String; found: " + tmp.getClass());
}
- // Return the default
- return new String[] { "/" };
+ // Return the default search path (group then root)
+ return new String[] { ".", "/" };
}
public Collection<Command> resolveCommands(String name, Variables variables) throws CommandException {
@@ -229,6 +288,14 @@
return commandsDirectory;
}
+ private FileObject getAliasesDirectory() throws FileSystemException {
+ if (aliasesDirectory == null) {
+ aliasesDirectory = fileSystemAccess.resolveFile(null, ALIASES_ROOT);
+ }
+
+ return aliasesDirectory;
+ }
+
private FileObject getGroupDirectory(final Variables vars) throws FileSystemException {
assert vars != null;
@@ -288,8 +355,7 @@
return command;
}
- /*
- private Command createAliasCommand(final FileObject file) throws FileSystemException {
+ private AliasCommand createAliasCommand(final FileObject file) throws FileSystemException {
assert file != null;
String name = file.getName().getBaseName();
@@ -308,9 +374,8 @@
return command;
}
- */
- private Command createGroupCommand(final FileObject file) throws FileSystemException {
+ private GroupCommand createGroupCommand(final FileObject file) throws FileSystemException {
assert file != null;
log.debug("Creating command for group: {}", file);
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java?rev=703345&r1=703344&r2=703345&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImplTest.java Fri Oct 10 00:48:07 2008
@@ -25,7 +25,9 @@
import org.apache.geronimo.gshell.application.plugin.Plugin;
import org.apache.geronimo.gshell.registry.NoSuchCommandException;
import org.apache.geronimo.gshell.registry.CommandResolver;
+import org.apache.geronimo.gshell.registry.AliasRegistry;
import org.apache.geronimo.gshell.wisdom.command.GroupCommand;
+import org.apache.geronimo.gshell.wisdom.command.AliasCommand;
import java.util.Collection;
@@ -129,7 +131,7 @@
public void testResolveCustomPathInGroup() throws Exception {
vars.set(CommandResolver.GROUP, "meta:/commands/group1");
- vars.set(CommandResolver.PATH, "/");
+ vars.set(CommandResolver.PATH, "/:.");
Command command;
@@ -144,18 +146,11 @@
command = resolver.resolveCommand("child2", vars);
assertNotNull(command);
-
- try {
- resolver.resolveCommand("no-such-command", vars);
- fail();
- }
- catch (NoSuchCommandException ignore) {
- // expected
- }
}
public void testResolveInGroup() throws Exception {
vars.set(CommandResolver.GROUP, "meta:/commands/group1");
+ vars.set(CommandResolver.PATH, "/:.");
Command command;
@@ -199,4 +194,15 @@
assertNotNull(commands);
assertEquals(6, commands.size());
}
+
+ public void testResolveAliases() throws Exception {
+ AliasRegistry aliasRegistry = getBean(AliasRegistry.class);
+ aliasRegistry.registerAlias("test", "test1");
+
+ Command command;
+
+ command = resolver.resolveCommand("test", vars);
+ assertNotNull(command);
+ assertTrue(command instanceof AliasCommand);
+ }
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml?rev=703345&r1=703344&r2=703345&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/log4j.xml Fri Oct 10 00:48:07 2008
@@ -50,7 +50,7 @@
<logger name="org.apache.geronimo.gshell.vfs.config">
<level value="INFO"/>
</logger>
-
+
<logger name="org.apache.commons.vfs">
<level value="WARN"/>
</logger>