in gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandResolverImpl.java [156:214]
private FileObject resolveCommandFile(final String name, final Variables variables) throws FileSystemException {
assert name != null;
assert variables != null;
log.trace("Resolving command file: {}", name);
FileObject root = getCommandsRoot();
// Special handling for root & group
if (name.equals("/")) {
return root;
}
else if (name.equals(".")) {
return groupDirResolver.getGroupDirectory(variables);
}
Collection<String> searchPath = getSearchPath(variables);
log.trace("Search path: {}", searchPath);
FileObject groupDir = groupDirResolver.getGroupDirectory(variables);
log.trace("Group dir: {}", groupDir);
FileObject file = null;
for (String pathElement : searchPath) {
log.trace("Resolving file; name={}, pathElement={}", name, pathElement);
FileObject dir;
if (pathElement.equals("/")) {
dir = root;
}
else if (pathElement.startsWith("/")) {
dir = fileSystemAccess.resolveFile(root, pathElement.substring(1, pathElement.length()));
}
else {
dir = fileSystemAccess.resolveFile(groupDir, pathElement);
}
log.trace("Dir: {}", dir);
FileObject tmp = fileSystemAccess.resolveFile(dir, name);
log.trace("File: {}", tmp);
if (tmp.exists()) {
file = tmp;
break;
}
}
if (file != null) {
log.trace("Resolved file: {}", file);
}
return file;
}