You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/04/21 15:19:31 UTC

svn commit: r164054 - in /maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact: ChecksumFailedException.java manager/DefaultWagonManager.java

Author: brett
Date: Thu Apr 21 06:19:29 2005
New Revision: 164054

URL: http://svn.apache.org/viewcvs?rev=164054&view=rev
Log:
turn on md5 checksum tests on download

Added:
    maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java   (with props)
Modified:
    maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java

Added: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java?rev=164054&view=auto
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java (added)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java Thu Apr 21 06:19:29 2005
@@ -0,0 +1,33 @@
+package org.apache.maven.artifact;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.wagon.TransferFailedException;
+
+/**
+ * Occurs when a download checksum fails.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class ChecksumFailedException extends TransferFailedException
+{
+    public ChecksumFailedException( String s )
+    {
+        super( s );
+    }
+}

Propchange: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/ChecksumFailedException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=164054&r1=164053&r2=164054&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java Thu Apr 21 06:19:29 2005
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ChecksumFailedException;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -48,7 +49,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.ArrayList;
 
 public class DefaultWagonManager
     extends AbstractLogEnabled
@@ -260,7 +260,7 @@
 
     private void getRemoteFile( ArtifactRepository repository, File destination, String remotePath,
                                 TransferListener downloadMonitor )
-        throws TransferFailedException, ResourceDoesNotExistException
+        throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException
     {
         Wagon wagon;
 
@@ -273,16 +273,6 @@
             throw new TransferFailedException( "Unsupported Protocol: ", e );
         }
 
-        // ----------------------------------------------------------------------
-        // These can certainly be configurable ... registering listeners
-        // ...
-
-        //ChecksumObserver md5SumObserver = new ChecksumObserver();
-
-        // ----------------------------------------------------------------------
-
-        //wagon.addTransferListener( md5SumObserver );
-
         if ( downloadMonitor != null )
         {
             wagon.addTransferListener( downloadMonitor );
@@ -294,6 +284,18 @@
             destination.getParentFile().mkdirs();
         }
 
+        // TODO: configure on repository
+        ChecksumObserver checksumObserver;
+        try
+        {
+            checksumObserver = new ChecksumObserver( "MD5" );
+            wagon.addTransferListener( checksumObserver );
+        }
+        catch ( NoSuchAlgorithmException e )
+        {
+            throw new TransferFailedException( "Unable to add checksum methods", e );
+        }
+
         File temp = new File( destination + ".tmp" );
         temp.deleteOnExit();
 
@@ -302,6 +304,32 @@
             wagon.connect( repository, getProxy( repository.getProtocol() ) );
 
             wagon.get( remotePath, temp );
+
+            try
+            {
+                // grab it first, because it's about to change...
+                String actualChecksum = checksumObserver.getActualChecksum();
+
+                File checksumFile = new File( destination + ".md5" );
+                wagon.get( remotePath + ".md5", checksumFile );
+
+                String expectedChecksum = FileUtils.fileRead( checksumFile );
+                if ( !expectedChecksum.equals( actualChecksum ) )
+                {
+                    // TODO: optionally retry?
+                    throw new ChecksumFailedException(
+                        "Checksum failed on download: local = " + actualChecksum + "; remote = " +
+                        expectedChecksum );
+                }
+            }
+            catch ( ResourceDoesNotExistException e )
+            {
+                getLogger().warn( "No checksum exists - assuming a valid download" );
+            }
+            catch ( IOException e )
+            {
+                getLogger().error( "Unable to read checksum - assuming a valid download", e );
+            }
         }
         catch ( ConnectionException e )
         {
@@ -327,15 +355,11 @@
             throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp );
         }
 
-        // The temporary file is named destination + ".tmp" and is done this
-        // way to ensure
-        // that the temporary file is in the same file system as the
-        // destination because the
+        // The temporary file is named destination + ".tmp" and is done this way to ensure
+        // that the temporary file is in the same file system as the destination because the
         // File.renameTo operation doesn't really work across file systems.
-        // So we will attempt
-        // to do a File.renameTo for efficiency and atomicity, if this fails
-        // then we will use
-        // a brute force copy and delete the temporary file.
+        // So we will attempt to do a File.renameTo for efficiency and atomicity, if this fails
+        // then we will use a brute force copy and delete the temporary file.
 
         if ( !temp.renameTo( destination ) )
         {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org