maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r684601 - in /maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src: main/java/org/apache/maven/scm/provider/git/gitexe/command/update/ test/java/org/apache/maven/scm/provider/git/gitexe/command/update/
Date Sun, 10 Aug 2008 21:49:32 GMT
Author: olamy
Date: Sun Aug 10 14:49:32 2008
New Revision: 684601

URL: http://svn.apache.org/viewvc?rev=684601&view=rev
Log:
[SCM-396] git provider implements scm update 
finish implementation of ScmFileStatus


Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumer.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumerTest.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumer.java?rev=684601&r1=684600&r2=684601&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumer.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumer.java
Sun Aug 10 14:49:32 2008
@@ -2,7 +2,9 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.maven.scm.ScmFile;
 import org.apache.maven.scm.ScmFileStatus;
@@ -39,10 +41,10 @@
 {
     
     private boolean updatingFound;
-    
+
     private boolean summaryFound;
 
-    private List scmFiles = new ArrayList();
+    private Map scmFiles = new HashMap();
 
     public GitUpdateCommandConsumer( ScmLogger logger, File workingDirectory )
     {
@@ -69,17 +71,18 @@
         if ( line.indexOf( "files changed" ) >= 0 )
         {
             summaryFound = true;
-
+            return;
         }
         if ( updatingFound && !summaryFound )
         {
             // test format : pom.xml←[m |    1 ←[32m+←[m
             int index = line.indexOf( "←[" );
-           
+
             if ( index >= 0 )
             {
                 String fileName = StringUtils.trim( line.substring( 0, index ) );
-                scmFiles.add( new ScmFile( fileName, ScmFileStatus.UPDATED ) );
+                scmFiles.put( fileName, new ScmFile( fileName, ScmFileStatus.UPDATED ) );
+                return;
             }
             else
             {
@@ -88,20 +91,45 @@
                 if ( index >= 0 )
                 {
                     String fileName = StringUtils.trim( line.substring( 0, index ) );
-                    scmFiles.add( new ScmFile( fileName, ScmFileStatus.UPDATED ) );
+                    scmFiles.put( fileName, new ScmFile( fileName, ScmFileStatus.UPDATED
) );
+                    return;
                 }
             }
         }
 
-        // here we have status/name of added/remove and we update if create or remove
-        //3 files changed, 1 insertions(+), 3 deletions(-)←[m
-        // delete mode 100644 README
-        //create mode 100644 test.txt
+        if ( updatingFound && summaryFound )
+        {
+            // here we have status/name of added/remove and we update if create or remove
+            // 3 files changed, 1 insertions(+), 3 deletions(-)←[m
+            // delete mode 100644 README
+            // create mode 100644 test.txt
+            String[] changedFileLine = StringUtils.split( line, " " );
+            if ( changedFileLine != null )
+            {
+                if ( changedFileLine.length >= 4 )
+                {
+                    String status = changedFileLine[0];
+                    String fileName = changedFileLine[3];
+                    ScmFile scmFile = (ScmFile) scmFiles.get( fileName );
+                    if ( scmFile != null )
+                    {
+                        if ( StringUtils.equalsIgnoreCase( "delete", status ) )
+                        {
+                            scmFiles.put( fileName, new ScmFile( fileName, ScmFileStatus.DELETED
) );
+                        }
+                        if ( StringUtils.equalsIgnoreCase( "create", status ) )
+                        {
+                            scmFiles.put( fileName, new ScmFile( fileName, ScmFileStatus.ADDED
) );
+                        }
+                    }
+                }
+            }
+        }
     }
 
     public List getUpdatedFiles()
     {
         getLogger().debug( " updatedFiles size " + scmFiles.size() );
-        return scmFiles;
+        return new ArrayList( scmFiles.values() );
     }    
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumerTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumerTest.java?rev=684601&r1=684600&r2=684601&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumerTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/update/GitUpdateCommandConsumerTest.java
Sun Aug 10 14:49:32 2008
@@ -38,6 +38,52 @@
 public class GitUpdateCommandConsumerTest
     extends PlexusTestCase
 {
+    public void testUpToDate()
+        throws Exception
+    {
+
+        GitUpdateCommandConsumer consumer = buildGitUpdateCommandConsumer( "/src/test/resources/git/update/git-update-up-to-date.out"
);
+
+        List changedFiles = consumer.getUpdatedFiles();
+
+        assertEquals( 0, changedFiles.size() );
+
+    }
+    
+    public void testTwoModified()
+        throws Exception
+    {
+
+        GitUpdateCommandConsumer consumer = buildGitUpdateCommandConsumer( "/src/test/resources/git/update/git-update.out"
);
+
+        List changedFiles = consumer.getUpdatedFiles();
+
+        assertEquals( 2, changedFiles.size() );
+        
+        assertScmFile( (ScmFile) changedFiles.get( 0 ), "README", ScmFileStatus.UPDATED );
+        
+        assertScmFile( (ScmFile) changedFiles.get( 1 ), "pom.xml", ScmFileStatus.UPDATED
);
+
+    }    
+    
+    public void testAddDeleteFile()
+        throws Exception
+    {
+
+        GitUpdateCommandConsumer consumer = buildGitUpdateCommandConsumer( "/src/test/resources/git/update/git-update-add-delete.out"
);
+
+        List changedFiles = consumer.getUpdatedFiles();
+
+        assertEquals( 3, changedFiles.size() );
+
+        assertScmFile( (ScmFile) changedFiles.get( 0 ), "README", ScmFileStatus.DELETED );
+        
+        assertScmFile( (ScmFile) changedFiles.get( 1 ), "pom.xml", ScmFileStatus.UPDATED
);
+
+        assertScmFile( (ScmFile) changedFiles.get( 2 ), "test.txt", ScmFileStatus.ADDED );
+
+    }        
+    
     public void testOneUpdate()
         throws Exception
     {
@@ -50,10 +96,24 @@
         assertOneUpdate( "/src/test/resources/git/update/git-update-one-other-format.out"
);
     }
     
+    
+    
+    // utils methods
 
     private void assertOneUpdate( String fileName )
         throws Exception
     {
+        GitUpdateCommandConsumer consumer = buildGitUpdateCommandConsumer( fileName );
+        List changedFiles = consumer.getUpdatedFiles();
+
+        assertEquals( 1, changedFiles.size() );
+
+        assertScmFile( (ScmFile) changedFiles.get( 0 ), "pom.xml", ScmFileStatus.UPDATED
);
+    }
+    
+    private GitUpdateCommandConsumer buildGitUpdateCommandConsumer( String fileName )
+        throws Exception
+    {
         GitUpdateCommandConsumer consumer = new GitUpdateCommandConsumer( new DefaultLog(),
null );
 
         BufferedReader r = getGitLogBufferedReader( fileName );
@@ -65,12 +125,7 @@
             //System.out.println(" line " + line );
             consumer.consumeLine( line );
         }
-
-        List changedFiles = consumer.getUpdatedFiles();
-
-        assertEquals( 1, changedFiles.size() );
-
-        assertScmFile( (ScmFile) changedFiles.get( 0 ), "pom.xml", ScmFileStatus.UPDATED
);
+        return consumer;
     }
 
     private BufferedReader getGitLogBufferedReader( String fileName )



Mime
View raw message