Author: brett
Date: Thu Jul 21 22:58:50 2005
New Revision: 220244

URL: http://svn.apache.org/viewcvs?rev=220244&view=rev
Log:
various straightening up

Modified:
    
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
    
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
    
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java

Modified: 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=220244&r1=220243&r2=220244&view=diff
==============================================================================
--- 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
 (original)
+++ 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
 Thu Jul 21 22:58:50 2005
@@ -26,7 +26,6 @@
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.UnsupportedProtocolException;
 import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.WagonException;
 import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.authorization.AuthorizationException;
@@ -100,10 +99,10 @@
     }
 
     public void putRepositoryMetadata( File source, RepositoryMetadata 
metadata, ArtifactRepository repository )
-    throws TransferFailedException
+        throws TransferFailedException
     {
         getLogger().info( "Uploading " + metadata );
-        
+
         putRemoteFile( repository, source, repository.formatAsFile( 
metadata.getRepositoryPath() ), null );
     }
 
@@ -113,7 +112,7 @@
     {
         String protocol = repository.getProtocol();
 
-        Wagon wagon = null;
+        Wagon wagon;
         try
         {
             wagon = getWagon( protocol );
@@ -251,13 +250,14 @@
         getRemoteFile( remoteRepository, destination, remotePath, null );
     }
 
-    public void getRepositoryMetadata( RepositoryMetadata metadata, 
ArtifactRepository remoteRepository, File destination )
-    throws TransferFailedException, ResourceDoesNotExistException
+    public void getRepositoryMetadata( RepositoryMetadata metadata, 
ArtifactRepository remoteRepository,
+                                       File destination )
+        throws TransferFailedException, ResourceDoesNotExistException
     {
         String remotePath = remoteRepository.formatAsFile( 
metadata.getRepositoryPath() );
-    
+
         getLogger().info( "Retrieving " + metadata );
-        
+
         getRemoteFile( remoteRepository, destination, remotePath, null );
     }
 
@@ -315,7 +315,7 @@
                            getAuthenticationInfo( repository.getId() ), 
getProxy( protocol ) );
 
             boolean firstRun = true;
-            boolean retry = false;
+            boolean retry = true;
 
             // this will run at most twice. The first time, the firstRun flag 
is turned off, and if the retry flag
             // is set on the first run, it will be turned off and not re-set 
on the second try. This is because the
@@ -339,70 +339,60 @@
                 {
                     verifyChecksum( sha1ChecksumObserver, temp, remotePath, 
".sha1", wagon );
                 }
-                catch ( WagonException sha1TryException )
+                catch ( ChecksumFailedException e )
                 {
                     // if we catch a ChecksumFailedException, it means the 
transfer/read succeeded, but the checksum
                     // doesn't match. This could be a problem with the server 
(ibiblio HTTP-200 error page), so we'll
                     // try this up to two times. On the second try, we'll 
handle it as a bona-fide error, based on the
                     // repository's checksum checking policy.
-                    if ( sha1TryException instanceof ChecksumFailedException )
+                    if ( firstRun )
                     {
-                        // if this is the second try, handle the 
problem...otherwise, let it try again.
-                        if ( firstRun )
-                        {
-                            retry = true;
-                        }
-                        else
-                        {
-                            handleChecksumFailure( repository, 
sha1TryException.getMessage(),
-                                                   sha1TryException.getCause() 
);
-                        }
+                        retry = true;
+                    }
+                    else
+                    {
+                        handleChecksumFailure( repository, e.getMessage(), 
e.getCause() );
                     }
+                }
+                catch ( ResourceDoesNotExistException sha1TryException )
+                {
+                    getLogger().debug( "SHA1 not found, trying MD5", 
sha1TryException );
+
                     // if this IS NOT a ChecksumFailedException, it was a 
problem with transfer/read of the checksum
                     // file...we'll try again with the MD5 checksum.
-                    else
+                    try
                     {
-                        try
+                        verifyChecksum( md5ChecksumObserver, temp, remotePath, 
".md5", wagon );
+                    }
+                    catch ( ChecksumFailedException e )
+                    {
+                        // if we also fail to verify based on the MD5 
checksum, and the checksum transfer/read
+                        // succeeded, then we need to determine whether to 
retry or handle it as a failure.
+                        if ( firstRun )
                         {
-                            verifyChecksum( md5ChecksumObserver, temp, 
remotePath, ".md5", wagon );
+                            retry = true;
                         }
-                        catch ( WagonException md5TryException )
+                        else
                         {
-                            // if we also fail to verify based on the MD5 
checksum, and the checksum transfer/read
-                            // succeeded, then we need to determine whether to 
retry or handle it as a failure.
-                            if ( md5TryException instanceof 
ChecksumFailedException )
-                            {
-                                // only retry once.
-                                if ( firstRun )
-                                {
-                                    retry = true;
-                                }
-                                else
-                                {
-                                    handleChecksumFailure( repository, 
md5TryException.getMessage(),
-                                                           
md5TryException.getCause() );
-                                }
-                            }
-                            // otherwise, this was a failed transfer, and we 
don't want to retry.
-                            else
-                            {
-                                handleChecksumFailure( repository, "Error 
retrieving checksum file for " + remotePath,
-                                                       md5TryException );
-                            }
+                            handleChecksumFailure( repository, e.getMessage(), 
e.getCause() );
                         }
                     }
-                }
-                finally
-                {
-                    // reinstate the download monitor...
-                    if ( downloadMonitor != null )
+                    catch ( ResourceDoesNotExistException md5TryException )
                     {
-                        wagon.addTransferListener( downloadMonitor );
+                        // this was a failed transfer, and we don't want to 
retry.
+                        handleChecksumFailure( repository, "Error retrieving 
checksum file for " + remotePath,
+                                               md5TryException );
                     }
+                }
 
-                    // unset the firstRun flag, so we don't get caught in an 
infinite loop...
-                    firstRun = false;
+                // reinstate the download monitor...
+                if ( downloadMonitor != null )
+                {
+                    wagon.addTransferListener( downloadMonitor );
                 }
+
+                // unset the firstRun flag, so we don't get caught in an 
infinite loop...
+                firstRun = false;
             }
         }
         catch ( ConnectionException e )
@@ -465,7 +455,7 @@
 
     private void verifyChecksum( ChecksumObserver checksumObserver, File 
destination, String remotePath,
                                  String checksumFileExtension, Wagon wagon )
-        throws WagonException
+        throws ResourceDoesNotExistException, TransferFailedException, 
AuthorizationException
     {
         try
         {
@@ -478,12 +468,8 @@
             String expectedChecksum = FileUtils.fileRead( checksumFile );
             if ( !expectedChecksum.equals( actualChecksum ) )
             {
-                //                getLogger().warn(
-                //                    "*** CHECKSUM MISMATCH - currently 
disabled fail due to bad repository checksums ***" );
-
-                throw new ChecksumFailedException(
-                    "Checksum failed on download: local = '" + actualChecksum 
+ "'; remote = '" + expectedChecksum +
-                        "'" );
+                throw new ChecksumFailedException( "Checksum failed on 
download: local = '" + actualChecksum +
+                    "'; remote = '" + expectedChecksum + "'" );
             }
         }
         catch ( IOException e )

Modified: 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java?rev=220244&r1=220243&r2=220244&view=diff
==============================================================================
--- 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
 (original)
+++ 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
 Thu Jul 21 22:58:50 2005
@@ -19,7 +19,6 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
@@ -46,29 +45,28 @@
     void getArtifact( Artifact artifact, List remoteRepositories, File 
destination )
         throws TransferFailedException, ResourceDoesNotExistException;
 
-    public void getArtifact( Artifact artifact, ArtifactRepository repository, 
File destination )
+    void getArtifact( Artifact artifact, ArtifactRepository repository, File 
destination )
         throws TransferFailedException, ResourceDoesNotExistException;
 
     void putArtifact( File source, Artifact artifact, ArtifactRepository 
deploymentRepository )
         throws TransferFailedException;
 
-    public void putArtifactMetadata( File source, ArtifactMetadata 
artifactMetadata, ArtifactRepository repository )
+    void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, 
ArtifactRepository repository )
         throws TransferFailedException;
 
-    public void getArtifactMetadata( ArtifactMetadata metadata, 
ArtifactRepository remoteRepository, File destination )
+    void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository 
remoteRepository, File destination )
         throws TransferFailedException, ResourceDoesNotExistException;
 
-    public void putRepositoryMetadata( File source, RepositoryMetadata 
metadata, ArtifactRepository repository )
+    void putRepositoryMetadata( File source, RepositoryMetadata metadata, 
ArtifactRepository repository )
         throws TransferFailedException;
 
-    public void getRepositoryMetadata( RepositoryMetadata metadata, 
ArtifactRepository remoteRepository,
-                                      File destination )
+    void getRepositoryMetadata( RepositoryMetadata metadata, 
ArtifactRepository remoteRepository, File destination )
         throws TransferFailedException, ResourceDoesNotExistException;
 
     void addProxy( String protocol, String host, int port, String username, 
String password, String nonProxyHosts );
 
     void addAuthenticationInfo( String repositoryId, String username, String 
password, String privateKey,
-                               String passphrase );
+                                String passphrase );
 
     void addMirror( String id, String mirrorOf, String url );
 

Modified: 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java?rev=220244&r1=220243&r2=220244&view=diff
==============================================================================
--- 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
 (original)
+++ 
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
 Thu Jul 21 22:58:50 2005
@@ -60,68 +60,66 @@
     public void resolve( Artifact artifact, List remoteRepositories, 
ArtifactRepository localRepository )
         throws ArtifactResolutionException
     {
-        if ( artifact == null )
+        if ( artifact != null )
         {
-            return;
-        }
+            // 
----------------------------------------------------------------------
+            // Check for the existence of the artifact in the specified local
+            // ArtifactRepository. If it is present then simply return as the
+            // request for resolution has been satisfied.
+            // 
----------------------------------------------------------------------
 
-        // 
----------------------------------------------------------------------
-        // Check for the existence of the artifact in the specified local
-        // ArtifactRepository. If it is present then simply return as the
-        // request for resolution has been satisfied.
-        // 
----------------------------------------------------------------------
+            String localPath = localRepository.pathOf( artifact );
 
-        String localPath = localRepository.pathOf( artifact );
+            artifact.setFile( new File( localRepository.getBasedir(), 
localPath ) );
 
-        artifact.setFile( new File( localRepository.getBasedir(), localPath ) 
);
-
-        // TODO: better to have a transform manager, or reuse the handler 
manager again so we don't have these requirements duplicated all over?
-        for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
-        {
-            ArtifactTransformation transform = (ArtifactTransformation) 
i.next();
-            try
+            // TODO: better to have a transform manager, or reuse the handler 
manager again so we don't have these requirements duplicated all over?
+            for ( Iterator i = artifactTransformations.iterator(); 
i.hasNext(); )
             {
-                transform.transformForResolve( artifact, remoteRepositories, 
localRepository );
-            }
-            catch ( ArtifactMetadataRetrievalException e )
-            {
-                throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
+                ArtifactTransformation transform = (ArtifactTransformation) 
i.next();
+                try
+                {
+                    transform.transformForResolve( artifact, 
remoteRepositories, localRepository );
+                }
+                catch ( ArtifactMetadataRetrievalException e )
+                {
+                    throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
+                }
             }
-        }
 
-        File destination = artifact.getFile();
-        if ( !destination.exists() )
-        {
-            try
+            File destination = artifact.getFile();
+            if ( !destination.exists() )
             {
-                if ( artifact.getRepository() != null )
+                try
                 {
-                    // the transformations discovered the artifact - so use it 
exclusively
-                    wagonManager.getArtifact( artifact, 
artifact.getRepository(), destination );
+                    if ( artifact.getRepository() != null )
+                    {
+                        // the transformations discovered the artifact - so 
use it exclusively
+                        wagonManager.getArtifact( artifact, 
artifact.getRepository(), destination );
+                    }
+                    else
+                    {
+                        wagonManager.getArtifact( artifact, 
remoteRepositories, destination );
+                    }
+
+                    // must be after the artifact is downloaded
+                    for ( Iterator i = artifact.getMetadataList().iterator(); 
i.hasNext(); )
+                    {
+                        ArtifactMetadata metadata = (ArtifactMetadata) 
i.next();
+                        metadata.storeInLocalRepository( localRepository );
+                    }
                 }
-                else
+                catch ( ResourceDoesNotExistException e )
                 {
-                    wagonManager.getArtifact( artifact, remoteRepositories, 
destination );
+                    throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
                 }
-
-                // must be after the artifact is downloaded
-                for ( Iterator i = artifact.getMetadataList().iterator(); 
i.hasNext(); )
+                catch ( TransferFailedException e )
                 {
-                    ArtifactMetadata metadata = (ArtifactMetadata) i.next();
-                    metadata.storeInLocalRepository( localRepository );
+                    throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
+                }
+                catch ( ArtifactMetadataRetrievalException e )
+                {
+                    throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
                 }
-            }
-            catch ( ResourceDoesNotExistException e )
-            {
-                throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
-            }
-            catch ( TransferFailedException e )
-            {
-                throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
-            }
-            catch ( ArtifactMetadataRetrievalException e )
-            {
-                throw new ArtifactResolutionException( e.getMessage(), 
artifact, remoteRepositories, e );
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to