geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r700054 - in /geronimo/gshell/trunk: gshell-assembly/src/main/underlay/etc/ gshell-commands/gshell-builtins/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-commands/gshell-builtins/src/mai...
Date Mon, 29 Sep 2008 10:45:50 GMT
Author: jdillon
Date: Mon Sep 29 03:45:46 2008
New Revision: 700054

URL: http://svn.apache.org/viewvc?rev=700054&view=rev
Log:
Added gshell-vfs (support) to the applications classpath
Changed 'source' command to use VFS to access the file to source

Modified:
    geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/pom.xml
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceAction.java
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SourceAction.properties

Modified: geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml?rev=700054&r1=700053&r2=700054&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml (original)
+++ geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml Mon Sep 29
03:45:46 2008
@@ -45,13 +45,21 @@
         -->
     </remoteRepositories>
 
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.geronimo.gshell.wisdom</groupId>
-            <artifactId>gshell-wisdom-core</artifactId>
+    <dependencyGroups>
+        <dependencyGroup>
             <version>1.0-alpha-2-SNAPSHOT</version>
-        </dependency>
-    </dependencies>
+
+            <dependency>
+                <groupId>org.apache.geronimo.gshell.wisdom</groupId>
+                <artifactId>gshell-wisdom-core</artifactId>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.geronimo.gshell.support</groupId>
+                <artifactId>gshell-vfs</artifactId>
+            </dependency>
+        </dependencyGroup>
+    </dependencyGroups>
 
     <pluginGroups>
         <pluginGroup>

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/pom.xml?rev=700054&r1=700053&r2=700054&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/pom.xml (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/pom.xml Mon Sep 29 03:45:46 2008
@@ -44,6 +44,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-vfs</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.geronimo.gshell</groupId>
             <artifactId>gshell-model</artifactId>
         </dependency>

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceAction.java?rev=700054&r1=700053&r2=700054&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SourceAction.java
Mon Sep 29 03:45:46 2008
@@ -19,6 +19,9 @@
 
 package org.apache.geronimo.gshell.commands.builtins;
 
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileType;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.command.CommandAction;
 import org.apache.geronimo.gshell.command.CommandContext;
@@ -26,21 +29,17 @@
 import org.apache.geronimo.gshell.commandline.CommandLineExecutor;
 import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.shell.ShellContext;
+import org.apache.geronimo.gshell.vfs.FileSystemAccess;
 import org.codehaus.plexus.util.IOUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
 import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URL;
 
 /**
- * Read and execute commands from a file/url in the current shell environment.
+ * Read and execute commands from a file in the current shell environment.
  *
  * @version $Rev$ $Date$
  */
@@ -52,22 +51,32 @@
     @Autowired
     private CommandLineExecutor executor;
 
+    @Autowired
+    private FileSystemAccess fileSystemAccess;
+
     @Argument(required=true)
-    private String source;
+    private String path;
 
     public Object execute(final CommandContext context) throws Exception {
         assert context != null;
+        IO io = context.getIo();
 
-        URL url;
-        
-        try {
-            url = new URL(source);
+        FileObject cwd = fileSystemAccess.getCurrentDirectory(context.getVariables());
+        FileObject file = fileSystemAccess.resolveFile(cwd, path);
+
+        if (!file.exists()) {
+            io.error("File not found: {}", file.getName());
+            return Result.FAILURE;
         }
-        catch (MalformedURLException e) {
-            url = new File(source).toURI().toURL();
+        else if (file.getType() == FileType.FOLDER) {
+            io.error("File is a directory: {}", file.getName());
+            return Result.FAILURE;
         }
+
+        log.debug("Sourcing file: {}", file.getName());
+        
+        BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContent().getInputStream()));
         
-        BufferedReader reader = openReader(url);
         try {
             String line;
             while ((line = reader.readLine()) != null) {
@@ -78,6 +87,7 @@
                     continue;
                 }
 
+                // HACK: Need a shell context, but currently that muck is not exposed, so
make a new one
                 ShellContext ctx = new ShellContext() {
                     public IO getIo() {
                         return context.getIo();
@@ -97,41 +107,4 @@
         
         return Result.SUCCESS;
     }
-
-    private BufferedReader openReader(final Object source) throws IOException {
-        BufferedReader reader;
-
-        if (source instanceof File) {
-            File file = (File)source;
-            log.info("Using source file: {}", file);
-
-            reader = new BufferedReader(new FileReader(file));
-        }
-        else if (source instanceof URL) {
-            URL url = (URL)source;
-            log.info("Using source URL: {}", url);
-
-            reader = new BufferedReader(new InputStreamReader(url.openStream()));
-        }
-        else {
-            String tmp = String.valueOf(source);
-
-            // First try a URL
-            try {
-                URL url = new URL(tmp);
-                log.info("Using source URL: {}", url);
-
-                reader = new BufferedReader(new InputStreamReader(url.openStream()));
-            }
-            catch (MalformedURLException ignore) {
-                // They try a file
-                File file = new File(tmp);
-                log.info("Using source file: {}", file);
-                
-                reader = new BufferedReader(new FileReader(tmp));
-            }
-        }
-        
-        return reader;
-    }
 }

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml?rev=700054&r1=700053&r2=700054&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
Mon Sep 29 03:45:46 2008
@@ -67,7 +67,7 @@
             <gshell:command name="source">
                 <gshell:action class="org.apache.geronimo.gshell.commands.builtins.SourceAction"/>
                 <gshell:completers>
-                    <bean class="jline.FileNameCompletor"/>
+                    <ref bean="fileObjectNameCompleter"/>
                     <null/>
                 </gshell:completers>
             </gshell:command>

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SourceAction.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SourceAction.properties?rev=700054&r1=700053&r2=700054&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SourceAction.properties
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SourceAction.properties
Mon Sep 29 03:45:46 2008
@@ -23,9 +23,10 @@
 
 command.name=source
 
-command.description=Read and execute commands from a file/URL in the current shell environment.
+command.description=Read and execute commands from a file in the current shell environment.
 
-command.argument.source=Source file or URL
+command.argument.path=Path to file to be sourced
+command.argument.path.token=PATH
 
 command.manual=\
   TODO: source manual
\ No newline at end of file



Mime
View raw message