You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2018/06/04 18:34:45 UTC

[maven-wagon] branch WAGON-503 created (now d3a11ca)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch WAGON-503
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git.


      at d3a11ca  [WAGON-503] Directory gives out of date error in putDirectory() to a non-empty Subversion repo

This branch includes the following new commits:

     new d3a11ca  [WAGON-503] Directory gives out of date error in putDirectory() to a non-empty Subversion repo

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.

[maven-wagon] 01/01: [WAGON-503] Directory gives out of date error in putDirectory() to a non-empty Subversion repo

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch WAGON-503
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit d3a11ca1c1456e3e0e35970de73a3ea9fa3852e3
Author: Ilya Basin <ba...@gmail.com>
AuthorDate: Thu Mar 1 16:12:42 2018 +0300

    [WAGON-503] Directory gives out of date error in putDirectory() to a non-empty Subversion repo
    
    This closes #47
---
 .../apache/maven/wagon/providers/scm/ScmWagon.java | 60 ++++++++++++++++++----
 .../wagon/providers/scm/AbstractScmWagonTest.java  | 10 ++++
 2 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java b/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
index d6531ee..ecffc45 100644
--- a/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
+++ b/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
@@ -100,6 +100,8 @@ public class ScmWagon
      */
     private String partCOSubdir = "";
 
+    private boolean haveRecursiveCO;
+
     private File checkoutDirectory;
 
     /**
@@ -246,7 +248,7 @@ public class ScmWagon
 
         try
         {
-            FileUtils.deleteDirectory( checkoutDirectory );
+            deleteCheckoutDirectory();
         }
         catch ( IOException e )
         {
@@ -378,7 +380,20 @@ public class ScmWagon
 
             boolean isDirectory = source.isDirectory();
             String checkoutTargetName = isDirectory ? targetName : getDirname( targetName );
-            String relPath = ensureDirs( scmProvider, scmRepository, checkoutTargetName, target );
+            boolean recursive = false;
+            if ( isDirectory )
+            {
+                for ( File f : source.listFiles() )
+                {
+                    if ( f.isDirectory() )
+                    {
+                        recursive = true;
+                        break;
+                    }
+                }
+            }
+
+            String relPath = ensureDirs( scmProvider, scmRepository, checkoutTargetName, target, recursive );
 
             File newCheckoutDirectory = new File( checkoutDirectory, relPath );
 
@@ -448,7 +463,7 @@ public class ScmWagon
      * @throws IOException
      */
     private String ensureDirs( ScmProvider scmProvider, ScmRepository scmRepository, String targetName,
-                             Resource resource )
+                               Resource resource, boolean recursiveArg )
         throws TransferFailedException, IOException
     {
         if ( checkoutDirectory == null )
@@ -463,11 +478,13 @@ public class ScmWagon
         // Check whether targetName, which is a relative path into the scm, exists.
         // If it doesn't, check the parent, etc.
 
+        boolean recursive = recursiveArg;
+
         for ( ;; )
         {
             try
             {
-                ScmResult res = tryPartialCheckout( target );
+                ScmResult res = tryPartialCheckout( target, recursive );
                 if ( !res.isSuccess() )
                 {
                     throw new ScmException( "command failed: " + res.getCommandOutput().trim() );
@@ -476,6 +493,7 @@ public class ScmWagon
             }
             catch ( ScmException e )
             {
+                recursive = false;
                 if ( partCOSubdir.length() == 0 )
                 {
                     fireTransferError( resource, e, TransferEvent.REQUEST_GET );
@@ -598,14 +616,15 @@ public class ScmWagon
         return addedFiles;
     }
 
-    private CheckOutScmResult checkOut( ScmProvider scmProvider, ScmRepository scmRepository, ScmFileSet fileSet )
+    private CheckOutScmResult checkOut( ScmProvider scmProvider, ScmRepository scmRepository, ScmFileSet fileSet,
+                                        boolean recursive )
         throws ScmException
     {
         ScmVersion ver = makeScmVersion();
         CommandParameters parameters = mkBinaryFlag();
         // TODO: AbstractScmProvider 6f7dd0c ignores checkOut() parameter "version"
         parameters.setScmVersion( CommandParameter.SCM_VERSION, ver );
-        parameters.setString( CommandParameter.RECURSIVE, Boolean.toString( false ) );
+        parameters.setString( CommandParameter.RECURSIVE, Boolean.toString( recursive ) );
         parameters.setString( CommandParameter.SHALLOW, Boolean.toString( true ) );
 
         return scmProvider.checkOut( scmRepository, fileSet, ver, parameters );
@@ -632,6 +651,12 @@ public class ScmWagon
         return ( "svn".equals( scmType ) || "cvs".equals( scmType ) );
     }
 
+    private boolean isAlwaysRecursive( ScmProvider scmProvider )
+    {
+        String scmType = scmProvider.getScmType();
+        return ( "git".equals( scmType ) || "cvs".equals( scmType ) );
+    }
+
     public void putDirectory( File sourceDirectory, String destinationDirectory )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
@@ -691,7 +716,7 @@ public class ScmWagon
         try
         {
             String subdir = getDirname( resourceName );
-            ScmResult res = tryPartialCheckout( subdir );
+            ScmResult res = tryPartialCheckout( subdir, false );
             if ( !res.isSuccess() && ( partCOSubdir.length() == 0 || res instanceof UpdateScmResult ) )
             {
                 // inability to checkout SVN or CVS subdir is not fatal. We just assume it doesn't exist
@@ -737,7 +762,7 @@ public class ScmWagon
         fireGetCompleted( resource, destination );
     }
 
-    private ScmResult tryPartialCheckout( String subdir )
+    private ScmResult tryPartialCheckout( String subdir, boolean recursiveArg )
         throws ScmException, IOException
     {
         String url = getRepository().getUrl();
@@ -755,12 +780,19 @@ public class ScmWagon
             scmRepository = getScmRepository( url );
         }
 
+        boolean recursive = recursiveArg | isAlwaysRecursive( scmProvider );
+
         if ( !desiredPartCOSubdir.equals( partCOSubdir ) )
         {
-            FileUtils.deleteDirectory( checkoutDirectory );
+            deleteCheckoutDirectory();
             partCOSubdir = desiredPartCOSubdir;
         }
 
+        if ( recursive && !haveRecursiveCO )
+        {
+            deleteCheckoutDirectory();
+        }
+
         ScmResult res;
         if ( checkoutDirExists( scmProvider ) )
         {
@@ -768,11 +800,19 @@ public class ScmWagon
         }
         else
         {
-            res = checkOut( scmProvider, scmRepository, new ScmFileSet( checkoutDirectory ) );
+            res = checkOut( scmProvider, scmRepository, new ScmFileSet( checkoutDirectory ), recursive );
+            haveRecursiveCO = recursive && res.isSuccess();
         }
         return res;
     }
 
+    private void deleteCheckoutDirectory()
+        throws IOException
+    {
+        haveRecursiveCO = false;
+        FileUtils.deleteDirectory( checkoutDirectory );
+    }
+
     private boolean checkoutDirExists( ScmProvider scmProvider )
     {
         String reservedScmFile = scmProvider.getScmSpecificFilename();
diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
index 3028997..b34cede 100644
--- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
+++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
@@ -46,6 +46,16 @@ public abstract class AbstractScmWagonTest
     extends WagonTestCase
 {
 
+    @Override
+    public void testWagonPutDirectory() throws Exception
+    {
+        super.testWagonPutDirectory();
+        // repeat the test on a non-empty repo
+        // ScmWagon should checkout all involved subdirs before calling
+        // FileUtils.copyDirectoryStructure()
+        super.testWagonPutDirectory();
+    }
+
     private ScmWagon wagon;
 
     private String providerClassName;

-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.