maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r383955 - in /maven/sandbox/wagon-scm/src: main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
Date Tue, 07 Mar 2006 18:20:01 GMT
Author: carlos
Date: Tue Mar  7 10:19:58 2006
New Revision: 383955

URL: http://svn.apache.org/viewcvs?rev=383955&view=rev
Log:
Fixed problem when directory already was in scm but some of the files weren't

Modified:
    maven/sandbox/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
    maven/sandbox/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java

Modified: maven/sandbox/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java?rev=383955&r1=383954&r2=383955&view=diff
==============================================================================
--- maven/sandbox/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
(original)
+++ maven/sandbox/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
Tue Mar  7 10:19:58 2006
@@ -19,6 +19,7 @@
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.add.AddScmResult;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.manager.ScmManager;
 import org.apache.maven.scm.provider.ScmProvider;
@@ -42,6 +43,7 @@
 /**
  * @author <a href="brett@apache.org">Brett Porter</a>
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
+ * @author <a href="carlos@apache.org">Carlos Sanchez</a>
  * @version $Id$
  */
 public class ScmWagon
@@ -157,6 +159,12 @@
         putInternal( source, resourceName );
     }
 
+    /**
+     * Puts both files and directories
+     * @param source
+     * @param resourceName
+     * @throws TransferFailedException
+     */
     private void putInternal( File source, String resourceName )
         throws TransferFailedException
     {
@@ -218,9 +226,14 @@
                 }
             }
 
-            if ( !fileAlreadyInScm )
+            if ( !fileAlreadyInScm || scmFile.isDirectory() )
             {
-                addFiles( scmProvider, scmRepository, basedir, scmFile );
+                int addedFiles = addFiles( scmProvider, scmRepository, basedir, scmFile );
+                if ( addedFiles == 0 )
+                {
+                    //TODO improve error message with the returned message from SCM
+                    throw new TransferFailedException( "Unable to add file to SCM: " + scmFile
);
+                }
             }
 
             result = scmProvider.checkIn( scmRepository, new ScmFileSet( basedir, scmFile.getName(),
null ), null, msg );
@@ -245,12 +258,23 @@
         firePutCompleted( resource, source );
     }
 
-    private void addFiles( ScmProvider scmProvider, ScmRepository scmRepository, File basedir,
File scmFile )
-        throws TransferFailedException, ScmException
+    /**
+     * Add a file or directory to a SCM repository.
+     * If it's a directory all its contents are added recursively.
+     * 
+     * @param scmProvider SCM provider
+     * @param scmRepository SCM repository
+     * @param basedir local directory corresponding to scmRepository
+     * @param scmFile file or directory to add
+     * @throws ScmException
+     * @return the number of files added.
+     */
+    private int addFiles( ScmProvider scmProvider, ScmRepository scmRepository, File basedir,
File scmFile )
+        throws ScmException
     {
-        ScmResult result = scmProvider.add( scmRepository, new ScmFileSet( basedir, scmFile
) );
+        AddScmResult result = scmProvider.add( scmRepository, new ScmFileSet( basedir, scmFile
) );
 
-        checkScmResult( result );
+        int addedFiles = result.getAddedFiles().size();
 
         String reservedScmFile = scmProvider.getScmSpecificFilename();
 
@@ -262,12 +286,17 @@
             {
                 if ( reservedScmFile != null && !reservedScmFile.equals( files[i].getName()
) )
                 {
-                    addFiles( scmProvider, scmRepository, basedir, files[i] );
+                    addedFiles += addFiles( scmProvider, scmRepository, basedir, files[i]
);
                 }
             }
         }
+
+        return addedFiles;
     }
 
+    /**
+     * @return true 
+     */
     public boolean supportsDirectoryCopy()
     {
         return true;
@@ -284,6 +313,11 @@
         putInternal( sourceDirectory, destinationDirectory );
     }
 
+    /**
+     * Check that the ScmResult was a successful operation
+     * @param result
+     * @throws TransferFailedException if result was not a successful operation
+     */
     private void checkScmResult( ScmResult result )
         throws TransferFailedException
     {

Modified: maven/sandbox/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java?rev=383955&r1=383954&r2=383955&view=diff
==============================================================================
--- maven/sandbox/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
(original)
+++ maven/sandbox/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
Tue Mar  7 10:19:58 2006
@@ -17,10 +17,15 @@
  */
 
 import java.io.File;
+import java.io.IOException;
+import java.util.List;
 
 import org.apache.maven.wagon.FileTestUtils;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.Wagon;
 import org.apache.maven.wagon.WagonTestCase;
+import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -59,6 +64,20 @@
     protected String getProtocol()
     {
         return "scm";
+    }
+
+    protected void createDirectory( Wagon wagon, String resourceToCreate, String[] resourcesNotPresent,
String dirName )
+        throws Exception
+    {
+        super.createDirectory( wagon, resourceToCreate, resourcesNotPresent, dirName );
+        FileUtils.deleteDirectory( getCheckoutDirectory() );
+    }
+
+    protected void assertResourcesAreInRemoteSide( Wagon wagon, List resourceNames )
+        throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+    {
+        FileUtils.deleteDirectory( getCheckoutDirectory() );
+        super.assertResourcesAreInRemoteSide( wagon, resourceNames );
     }
 
 }



Mime
View raw message