geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r701601 - in /geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main: java/org/apache/geronimo/gshell/commands/vfs/ resources/META-INF/spring/ resources/org/apache/geronimo/gshell/commands/vfs/
Date Sat, 04 Oct 2008 05:50:08 GMT
Author: jdillon
Date: Fri Oct  3 22:50:07 2008
New Revision: 701601

URL: http://svn.apache.org/viewvc?rev=701601&view=rev
Log:
Add basic 'grep' command

Added:
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
  (with props)
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/GrepAction.properties
      - copied, changed from r701596, geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml

Added: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java?rev=701601&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
(added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
Fri Oct  3 22:50:07 2008
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+package org.apache.geronimo.gshell.commands.vfs;
+
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.oro.text.MatchAction;
+import org.apache.oro.text.MatchActionProcessor;
+import org.apache.oro.text.MatchActionInfo;
+import org.apache.oro.text.regex.MalformedPatternException;
+import org.apache.commons.vfs.FileObject;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+
+/**
+ * Displays lines matching a pattern.
+ *
+ * @version $Rev$ $Date$
+ */
+public class GrepAction
+    extends VfsActionSupport
+{
+    @Argument(index=0, required=true)
+    private String pattern;
+
+    @Argument(index=1, required=true)
+    private String path;
+
+    public Object execute(final CommandContext context) throws Exception {
+        assert context != null;
+        final IO io = context.getIo();
+
+        MatchActionProcessor processor = new MatchActionProcessor();
+
+        try {
+            processor.addAction(pattern, new MatchAction() {
+                public void processMatch(final MatchActionInfo info) {
+                    io.info("{}", info.line);
+                }
+            });
+        }
+        catch (MalformedPatternException e) {
+            io.error("Invalid pattern: " + e, e);
+            return Result.FAILURE;
+        }
+
+        FileObject file = resolveFile(context, path);
+        BufferedInputStream input = new BufferedInputStream(file.getContent().getInputStream());
+        try {
+            processor.processMatches(input, io.outputStream);
+        }
+        finally {
+            IOUtil.close(input);
+            closeFile(file);
+        }
+
+        return Result.SUCCESS;
+    }
+}

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/GrepAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml?rev=701601&r1=701600&r2=701601&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/META-INF/spring/components.xml
Fri Oct  3 22:50:07 2008
@@ -111,6 +111,18 @@
                     <null/>
                 </gshell:completers>
             </gshell:command>
+
+            <gshell:command name="grep">
+                <gshell:action class="org.apache.geronimo.gshell.commands.vfs.GrepAction"/>
+                <!--
+                FIXME: This does not work, won't complete the second argument :-(
+                <gshell:completers>
+                    <bean class="jline.NullCompletor"/>
+                    <ref bean="fileObjectNameCompleter"/>
+                    <null/>
+                </gshell:completers>
+                -->
+            </gshell:command>
         </gshell:command-bundle>
 
         <!--

Copied: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/GrepAction.properties
(from r701596, geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/GrepAction.properties?p2=geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/GrepAction.properties&p1=geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties&r1=701596&r2=701601&rev=701601&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/FileInfoAction.properties
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/GrepAction.properties
Fri Oct  3 22:50:07 2008
@@ -21,12 +21,15 @@
 ## $Rev$ $Date$
 ##
 
-command.name=fileinfo
+command.name=grep
 
-command.description=Displays information about a file.
+command.description=Displays lines matching a pattern.
 
-command.argument.path=Path of file to display
+command.argument.pattern=Pattern to match
+command.argument.pattern.token=PATTERN
+
+command.argument.path=Path of file to search
 command.argument.path.token=PATH
 
 command.manual=\
-  TODO: fileinfo manual
\ No newline at end of file
+  TODO: grep manual
\ No newline at end of file



Mime
View raw message