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/03 21:38:18 UTC

[maven-wagon] 03/04: [WAGON-497] ScmWagon#put() strips parent dirs from the target path if they already exist in SCM

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

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

commit 8f91f4cd79550c042af584bbaa10a7b1088380fe
Author: Ilya Basin <ba...@gmail.com>
AuthorDate: Sun Feb 18 12:31:46 2018 +0300

    [WAGON-497] ScmWagon#put() strips parent dirs from the target path if they already exist in SCM
    
    This closes #40
---
 .../java/org/apache/maven/wagon/WagonTestCase.java | 42 ++++++++++++++++------
 .../apache/maven/wagon/providers/scm/ScmWagon.java | 12 +++++--
 .../providers/scm/AbstractScmCvsWagonTest.java     |  2 +-
 3 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
index fb277c7..e89f1e2 100644
--- a/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
+++ b/wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java
@@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -74,6 +75,10 @@ public abstract class WagonTestCase
         }
     }
 
+    protected static final String TEST_CONTENT = "test-resource.txt\n";
+
+    protected static final String TEST_CKSUM = cksum( TEST_CONTENT );
+
     protected static final String POM = "pom.xml";
 
     protected Repository localRepository;
@@ -233,16 +238,13 @@ public abstract class WagonTestCase
     public void testWagon()
         throws Exception
     {
-        if ( supportsGetIfNewer() )
-        {
-            setupRepositories();
+        setupRepositories();
 
-            setupWagonTestingFixtures();
+        setupWagonTestingFixtures();
 
-            fileRoundTripTesting();
+        fileRoundTripTesting();
 
-            tearDownWagonTestingFixtures();
-        }
+        tearDownWagonTestingFixtures();
     }
 
     public void testWagonGetIfNewerIsNewer()
@@ -341,7 +343,7 @@ public abstract class WagonTestCase
 
             assertNotNull( "check checksum is not null", checksumObserver.getActualChecksum() );
 
-            assertEquals( "compare checksums", "6b144b7285ffd6b0bc8300da162120b9",
+            assertEquals( "compare checksums", TEST_CKSUM,
                           checksumObserver.getActualChecksum() );
 
             // Now compare the contents of the artifact that was placed in
@@ -923,7 +925,7 @@ public abstract class WagonTestCase
     protected int putFile()
         throws Exception
     {
-        String content = "test-resource.txt\n";
+        String content = TEST_CONTENT;
         putFile( resource, "test-resource", content );
         return content.length();
     }
@@ -1049,7 +1051,7 @@ public abstract class WagonTestCase
 
         assertNotNull( "check checksum is not null", checksumObserver.getActualChecksum() );
 
-        assertEquals( "compare checksums", "6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum() );
+        assertEquals( "compare checksums", TEST_CKSUM, checksumObserver.getActualChecksum() );
 
         checksumObserver = new ChecksumObserver();
 
@@ -1057,7 +1059,7 @@ public abstract class WagonTestCase
 
         assertNotNull( "check checksum is not null", checksumObserver.getActualChecksum() );
 
-        assertEquals( "compare checksums", "6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum() );
+        assertEquals( "compare checksums", TEST_CKSUM, checksumObserver.getActualChecksum() );
 
         // Now compare the conents of the artifact that was placed in
         // the repository with the contents of the artifact that was
@@ -1087,4 +1089,22 @@ public abstract class WagonTestCase
         return repository;
     }
 
+    protected static String cksum( String content )
+    {
+        String checkSum;
+        try
+        {
+            ChecksumObserver obs = new ChecksumObserver();
+            byte[] buf = content.getBytes( StandardCharsets.ISO_8859_1 );
+            obs.transferProgress( null, buf, buf.length );
+            obs.transferCompleted( null );
+            checkSum = obs.getActualChecksum();
+        }
+        catch ( Exception e )
+        {
+            checkSum = null;
+        }
+        return checkSum;
+    }
+
 }
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 ceca314..09b014d 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
@@ -477,6 +477,7 @@ public class ScmWagon
         // and the configuration is incorrect. We will not try repo.getParent since most scm's don't
         // implement that.
 
+        target = target.replace( '\\', '/' );
         try
         {
             String repoUrl = getRepository().getUrl();
@@ -484,7 +485,11 @@ public class ScmWagon
             {
                 // Subversion is the only SCM that adds path structure to represent tags and branches.
                 // The rest use scmVersion and scmVersionType.
-                repoUrl += "/" + target.replace( '\\', '/' );
+                if ( target.length() > 0 )
+                {
+                    repoUrl += "/" + target;
+                    target = "";
+                }
             }
             scmRepository = getScmRepository( repoUrl );
 
@@ -502,7 +507,7 @@ public class ScmWagon
 
         // now create the subdirs in target, if it's a parent of targetName
 
-        String relPath = "";
+        String relPath = target.concat( target.length() > 0 ? "/" : "" );
 
         while ( !stack.isEmpty() )
         {
@@ -510,7 +515,8 @@ public class ScmWagon
             relPath += p + "/";
 
             File newDir = new File( checkoutDirectory, relPath );
-            if ( !newDir.mkdirs() )
+            newDir.mkdir();
+            if ( !newDir.isDirectory() )
             {
                 throw new TransferFailedException(
                     "Failed to create directory " + newDir.getAbsolutePath() + "; parent should exist: "
diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java
index fc7b7f8..eac4562 100644
--- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java
+++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmCvsWagonTest.java
@@ -41,6 +41,6 @@ public abstract class AbstractScmCvsWagonTest
     {
         String repository = getTestFile( "target/test-classes/test-repo-cvs" ).getAbsolutePath();
 
-        return "scm:cvs|local|" + repository + "|repository/newfolder";
+        return "scm:cvs|local|" + repository + "|repository";
     }
 }

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