maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r485738 - in /maven/wagon/trunk/wagon-providers/wagon-ssh-common/src: main/java/org/apache/maven/wagon/providers/ssh/ test/java/org/ test/java/org/apache/ test/java/org/apache/maven/ test/java/org/apache/maven/wagon/ test/java/org/apache/ma...
Date Mon, 11 Dec 2006 16:22:27 GMT
Author: joakime
Date: Mon Dec 11 08:22:26 2006
New Revision: 485738

URL: http://svn.apache.org/viewvc?view=rev&rev=485738
Log:
Refactoring LSParser out to better test parsing logic on multiple platforms/OSs

Added:
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java
  (with props)
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java
  (with props)
Modified:
    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java?view=diff&rev=485738&r1=485737&r2=485738
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
Mon Dec 11 08:22:26 2006
@@ -37,11 +37,8 @@
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
-import java.io.StringReader;
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -353,37 +350,8 @@
         {
             String path = getPath( getRepository().getBasedir(), destinationDirectory );
             Streams streams = executeCommand( "ls -la " + path, false );
-
-            BufferedReader br = new BufferedReader( new StringReader( streams.getOut() )
);
-
-            List ret = new ArrayList();
-            String line = br.readLine();
-
-            while ( line != null )
-            {
-                String[] parts = StringUtils.split( line, " " );
-                /* This should split out the 'ls' command output.
-                 * Example: "-rw-r--r-- 1 joakim wheel    18 2006-12-10 10:00 test-resource.pom"
-                 * 
-                 * 0 : The permissions mask : "-rw-r--r--"
-                 * 1 : Directory Complexity : "1"
-                 * 2 : Owner                : "joakim"
-                 * 3 : Group                : "wheel"
-                 * 4 : Size                 : "18"
-                 * 5 : Date                 : "2006-12-10"
-                 * 6 : Time                 : "10:00"
-                 * 7 : File Name            : "test-resource.pom"
-                 */
-                if ( parts.length >= 7 )
-                {
-                    // This is the filename portion of the 'ls' command output.
-                    ret.add( parts[7] );
-                }
-
-                line = br.readLine();
-            }
-
-            return ret;
+            
+            return new LSParser().parseFiles( streams.getOut() );
         }
         catch ( CommandExecutionException e )
         {
@@ -395,10 +363,6 @@
             {
                 throw new TransferFailedException( "Error performing file listing.", e );
             }
-        }
-        catch ( IOException e )
-        {
-            throw new TransferFailedException( "Error parsing file listing.", e );
         }
     }
 

Added: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java?view=auto&rev=485738
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java
Mon Dec 11 08:22:26 2006
@@ -0,0 +1,76 @@
+package org.apache.maven.wagon.providers.ssh;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.wagon.TransferFailedException;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * LSParser 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class LSParser
+{
+    /**
+     * Parse a raw "ls -la", and obtain the list of files.
+     * 
+     * TODO: Does not handle files with spaces in the name correctly.
+     * 
+     * @param rawLS the raw LS to parse.
+     * @return the list of files found.
+     * @throws TransferFailedException
+     */
+    public List parseFiles( String rawLS )
+        throws TransferFailedException
+    {
+        List ret = new ArrayList();
+        try
+        {
+            BufferedReader br = new BufferedReader( new StringReader( rawLS ) );
+
+            String line = br.readLine();
+
+            while ( line != null )
+            {
+                String[] parts = StringUtils.split( line, " " );
+                if ( parts.length >= 7 )
+                {
+                    ret.add( parts[parts.length - 1] );
+                }
+
+                line = br.readLine();
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "Error parsing file listing.", e );
+        }
+
+        return ret;
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/LSParser.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java?view=auto&rev=485738
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java
Mon Dec 11 08:22:26 2006
@@ -0,0 +1,66 @@
+package org.apache.maven.wagon.providers.ssh;
+
+import org.apache.maven.wagon.TransferFailedException;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class LSParserTest
+    extends TestCase
+{
+    public void testParseLinux()
+        throws TransferFailedException
+    {
+        String rawLS = "total 32\n" + "drwxr-xr-x  5 joakim joakim 4096 2006-12-11 10:30
.\n"
+            + "drwxr-xr-x 14 joakim joakim 4096 2006-12-11 10:30 ..\n"
+            + "-rw-r--r--  1 joakim joakim  320 2006-12-09 18:46 .classpath\n"
+            + "-rw-r--r--  1 joakim joakim 1194 2006-12-11 09:25 pom.xml\n"
+            + "-rw-r--r--  1 joakim joakim  662 2006-12-09 18:46 .project\n"
+            + "drwxr-xr-x  4 joakim joakim 4096 2006-11-21 12:26 src\n"
+            + "drwxr-xr-x  7 joakim joakim 4096 2006-12-11 10:31 .svn\n"
+            + "drwxr-xr-x  3 joakim joakim 4096 2006-12-11 08:39 target\n";
+
+        LSParser parser = new LSParser();
+        List files = parser.parseFiles( rawLS );
+        assertNotNull( files );
+        assertEquals( 8, files.size() );
+        assertTrue( files.contains( "pom.xml" ) );
+    }
+
+    public void testParseOSX() throws TransferFailedException
+    {
+        String rawLS = "total 32\n" + "drwxr-xr-x   5  joakim  joakim   238 Dec 11 10:30
.\n"
+            + "drwxr-xr-x  14  joakim  joakim   518 Dec 11 10:30 ..\n"
+            + "-rw-r--r--   1  joakim  joakim   320 May  9  2006 .classpath\n"
+            + "-rw-r--r--   1  joakim  joakim  1194 Dec 11 09:25 pom.xml\n"
+            + "-rw-r--r--   1  joakim  joakim   662 May  9  2006 .project\n"
+            + "drwxr-xr-x   4  joakim  joakim   204 Dec 11 12:26 src\n"
+            + "drwxr-xr-x   7  joakim  joakim   476 Dec 11 10:31 .svn\n"
+            + "drwxr-xr-x   3  joakim  joakim   238 Dec 11 08:39 target\n";
+
+        LSParser parser = new LSParser();
+        List files = parser.parseFiles( rawLS );
+        assertNotNull( files );
+        assertEquals( 8, files.size() );
+        assertTrue( files.contains( "pom.xml" ) );
+    }
+
+    public void testParseCygwin() throws TransferFailedException
+    {
+        String rawLS = "total 32\n" + "drwxr-xr-x+  5 joakim None    0 Dec 11 10:30 .\n"
+            + "drwxr-xr-x+ 14 joakim None    0 Dec 11 10:30 ..\n"
+            + "-rw-r--r--+  1 joakim None  320 May  9  2006 .classpath\n"
+            + "-rw-r--r--+  1 joakim None 1194 Dec 11 09:25 pom.xml\n"
+            + "-rw-r--r--+  1 joakim None  662 May  9  2006 .project\n"
+            + "drwxr-xr-x+  4 joakim None    0 Dec 11 12:26 src\n"
+            + "drwxr-xr-x+  7 joakim None    0 Dec 11 10:31 .svn\n"
+            + "drwxr-xr-x+  3 joakim None    0 Dec 11 08:39 target\n";
+        
+        LSParser parser = new LSParser();
+        List files = parser.parseFiles( rawLS );
+        assertNotNull( files );
+        assertEquals( 8, files.size() );
+        assertTrue( files.contains( "pom.xml" ) );
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/LSParserTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org


Mime
View raw message