From bc2cd2a268b1215dc6ee4642b7f6882cd67babf3 Mon Sep 17 00:00:00 2001 From: Ilya Basin Date: Sun, 18 Feb 2018 12:31:46 +0300 Subject: [PATCH] [WAGON-497] fix ScmWagon.put() strips existing parent directories [WAGON-497] fix ScmWagon cannot checkout when list() unsupported fix testWagon test case is disabled by mistake for SVN fix hardcoded checksum for test content in WagonTestCase fix CvsWagonTest: the test repo has no subfolders --- .../org/apache/maven/wagon/WagonTestCase.java | 42 ++++++++++++++----- .../maven/wagon/providers/scm/ScmWagon.java | 12 ++++-- .../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 fb277c7f0..e89f1e296 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 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 int getSize() } } + 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 @@ protected void message( String message ) public void testWagon() throws Exception { - if ( supportsGetIfNewer() ) - { - setupRepositories(); + setupRepositories(); - setupWagonTestingFixtures(); + setupWagonTestingFixtures(); - fileRoundTripTesting(); + fileRoundTripTesting(); - tearDownWagonTestingFixtures(); - } + tearDownWagonTestingFixtures(); } public void testWagonGetIfNewerIsNewer() @@ -341,7 +343,7 @@ protected void assertGetIfNewerTest( ProgressAnswer progressAnswer, boolean expe 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 @@ protected TransferEvent createTransferEvent( Wagon wagon, Resource resource, int 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 @@ protected void fileRoundTripTesting() 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 @@ protected void fileRoundTripTesting() 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 @@ protected Repository createFileRepository( String url ) 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 8fbbdeff5..4c604c739 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 @@ -475,6 +475,7 @@ false, makeScmVersion() ).isSuccess() ) // 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(); @@ -482,7 +483,11 @@ false, makeScmVersion() ).isSuccess() ) { // 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 ); CheckOutScmResult ret = @@ -500,7 +505,7 @@ false, makeScmVersion() ).isSuccess() ) // 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() ) { @@ -508,7 +513,8 @@ false, makeScmVersion() ).isSuccess() ) 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 fc7b7f82b..eac45626f 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 @@ protected String getTestRepositoryUrl() { String repository = getTestFile( "target/test-classes/test-repo-cvs" ).getAbsolutePath(); - return "scm:cvs|local|" + repository + "|repository/newfolder"; + return "scm:cvs|local|" + repository + "|repository"; } }