Index: src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
===================================================================
--- src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (revision 635696)
+++ src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (working copy)
@@ -747,7 +747,7 @@
expectedChecksum = expectedChecksum.substring( 0, spacePos );
}
}
- if ( expectedChecksum.equals( actualChecksum ) )
+ if ( expectedChecksum.equalsIgnoreCase( actualChecksum ) )
{
File checksumFile = new File( destination + checksumFileExtension );
if ( checksumFile.exists() )
Index: src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
===================================================================
--- src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java (revision 635696)
+++ src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java (working copy)
@@ -25,6 +25,7 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange;
@@ -175,6 +176,178 @@
}
}
+ /**
+ * Checks the verification of checksums.
+ */
+ public void testChecksumVerification()
+ throws Exception
+ {
+ ArtifactRepositoryPolicy policy =
+ new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
+ ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
+ ArtifactRepository repo =
+ new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy );
+
+ File tmpFile = File.createTempFile( "mvn-cs-test", ".temp" );
+ File sha1File = new File( tmpFile.getPath() + ".sha1" );
+ File md5File = new File( tmpFile.getPath() + ".md5" );
+
+ try
+ {
+ Artifact artifact =
+ new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion( "1.0" ), "scope",
+ "jar", "classifier", null );
+ artifact.setFile( tmpFile );
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "lower-case-checksum" );
+ Xpp3Dom sha1 = new Xpp3Dom( "path.sha1" );
+ sha1.setValue( "2a25dc564a3b34f68237fc849066cbc7bb7a36a1" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( sha1 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "upper-case-checksum" );
+ Xpp3Dom sha1 = new Xpp3Dom( "path.sha1" );
+ sha1.setValue( "B7BB97D7D0B9244398D9B47296907F73313663E6" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( sha1 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "expected-failure" );
+ Xpp3Dom sha1 = new Xpp3Dom( "path.sha1" );
+ sha1.setValue( "b7bb97d7d0b9244398d9b47296907f73313663e6" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( sha1 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ fail( "Checksum verification did not fail" );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ // expected
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "lower-case-checksum" );
+ Xpp3Dom md5 = new Xpp3Dom( "path.md5" );
+ md5.setValue( "50b2cf50a103a965efac62b983035cac" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( md5 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "upper-case-checksum" );
+ Xpp3Dom md5 = new Xpp3Dom( "path.md5" );
+ md5.setValue( "842F568FCCFEB7E534DC72133D42FFDC" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( md5 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "expected-failure" );
+ Xpp3Dom md5 = new Xpp3Dom( "path.md5" );
+ md5.setValue( "b7bb97d7d0b9244398d9b47296907f73313663e6" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( md5 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ fail( "Checksum verification did not fail" );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ // expected
+ }
+ }
+
+ }
+ finally
+ {
+ tmpFile.delete();
+ sha1File.delete();
+ md5File.delete();
+ }
+ }
+
private void assertWagon( String protocol )
throws Exception
{
Index: src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java
===================================================================
--- src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java (revision 635696)
+++ src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java (working copy)
@@ -40,23 +40,15 @@
public void get( String resourceName, File destination )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
- Resource resource = new Resource( resourceName );
- fireGetInitiated( resource, destination );
- fireGetStarted( resource, destination );
- try
- {
- destination.createNewFile();
- }
- catch ( IOException e )
- {
- // ignored
- }
- fireGetCompleted( resource, destination );
+ getIfNewer( resourceName, destination, 0 );
}
public boolean getIfNewer( String resourceName, File destination, long timestamp )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
+ Resource resource = new Resource( resourceName );
+ fireGetInitiated( resource, destination );
+ fireGetStarted( resource, destination );
try
{
destination.createNewFile();
@@ -65,6 +57,7 @@
{
return false;
}
+ fireGetCompleted( resource, destination );
return true;
}
Index: src/test/java/org/apache/maven/artifact/manager/WagonString.java
===================================================================
--- src/test/java/org/apache/maven/artifact/manager/WagonString.java (revision 0)
+++ src/test/java/org/apache/maven/artifact/manager/WagonString.java (revision 0)
@@ -0,0 +1,107 @@
+package org.apache.maven.artifact.manager;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.maven.wagon.AbstractWagon;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.events.TransferEvent;
+import org.apache.maven.wagon.resource.Resource;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * A wagon stub that can be configured to output strings into some artifacts.
+ */
+public class WagonString
+ extends AbstractWagon
+{
+
+ /**
+ * A mapping from resource names to file contents. Retrievals will throw a {@link ResourceDoesNotExistException} if
+ * a resource is requested which has no entry in this map.
+ *
+ * @component.configuration default="resourceStrings"
+ */
+ private Map resourceStrings;
+
+ public void closeConnection()
+ {
+ // NO-OP
+ }
+
+ public void get( String resourceName, File destination )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ getIfNewer( resourceName, destination, 0 );
+ }
+
+ public boolean getIfNewer( String resourceName, File destination, long timestamp )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ Resource resource = new Resource( resourceName );
+ fireGetInitiated( resource, destination );
+
+ String data = (String) this.resourceStrings.get( resourceName );
+ if ( data == null )
+ {
+ throw new ResourceDoesNotExistException( "Unexistent resource: " + resourceName );
+ }
+
+ fireGetStarted( resource, destination );
+ try
+ {
+ byte[] bytes = data.getBytes( "UTF-8" );
+ FileUtils.fileWrite( destination.getPath(), "UTF-8", data );
+ fireTransferProgress( new TransferEvent( this, resource, TransferEvent.TRANSFER_PROGRESS,
+ TransferEvent.REQUEST_GET ), bytes, bytes.length );
+ }
+ catch ( IOException e )
+ {
+ return false;
+ }
+ fireGetCompleted( resource, destination );
+
+ return true;
+ }
+
+ public void openConnection()
+ {
+ // NO-OP
+ }
+
+ public void put( File source, String destination )
+ throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+ {
+ Resource resource = new Resource( destination );
+ firePutInitiated( resource, source );
+ firePutStarted( resource, source );
+ firePutCompleted( resource, source );
+ }
+
+ public String[] getSupportedProtocols()
+ {
+ return new String[] { "string" };
+ }
+}
Property changes on: src\test\java\org\apache\maven\artifact\manager\WagonString.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Index: src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
===================================================================
--- src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml (revision 635696)
+++ src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml (working copy)
@@ -45,6 +45,11 @@
org.apache.maven.artifact.manager.WagonNoOp
+ org.apache.maven.wagon.Wagon
+ string
+ org.apache.maven.artifact.manager.WagonString
+
+
org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider
org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider