Author: stephenc
Date: Mon May 23 08:02:50 2011
New Revision: 1126367

URL: http://svn.apache.org/viewvc?rev=1126367&view=rev
Log:
[MDEPLOY-133]

Modified:
    
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
    
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
    
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java

Modified: 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java?rev=1126367&r1=1126366&r2=1126367&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
 Mon May 23 08:02:50 2011
@@ -19,9 +19,12 @@ package org.apache.maven.plugin.deploy;
  * under the License.
  */
 
+import java.io.File;
 import java.util.Map;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.deployer.ArtifactDeployer;
+import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
@@ -84,6 +87,14 @@ public abstract class AbstractDeployMojo
      */
     protected boolean updateReleaseInfo;
 
+    /**
+     * Parameter used to control how many times a failed deployment will be 
retried before giving up and failing.
+     * If a value outside the range 1-10 is specified it will be pulled to the 
nearest value within the range 1-10.
+     *
+     * @parameter expression="${retryFailedDeploymentCount}" default-value="1"
+     */
+    private int retryFailedDeploymentCount;
+
     /* Setters and Getters */
 
     public ArtifactDeployer getDeployer()
@@ -128,4 +139,37 @@ public abstract class AbstractDeployMojo
         return layout;
     }
 
+    protected void deploy( File file1, Artifact attached, ArtifactRepository 
deploymentRepository,
+                           ArtifactRepository localRepository )
+        throws ArtifactDeploymentException
+    {
+        int retryFailedDeploymentCount = Math.max( 1, Math.min( 10, 
this.retryFailedDeploymentCount ) );
+        ArtifactDeploymentException exception = null;
+        for ( int count = 0; count < retryFailedDeploymentCount; count++ )
+        {
+            try
+            {
+                if (count > 0)
+                {
+                    getLog().info( "Retrying deployment attempt " + (count + 
1) + " of " + retryFailedDeploymentCount );
+                }
+                getDeployer().deploy( file1, attached, deploymentRepository, 
localRepository );
+                exception = null;
+            }
+            catch ( ArtifactDeploymentException e )
+            {
+                if (count + 1 < retryFailedDeploymentCount) {
+                    getLog().warn( "Something went wrong with the deployment, 
will try again", e );
+                }
+                if ( exception == null )
+                {
+                    exception = e;
+                }
+            }
+        }
+        if ( exception != null )
+        {
+            throw exception;
+        }
+    }
 }

Modified: 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java?rev=1126367&r1=1126366&r2=1126367&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
 Mon May 23 08:02:50 2011
@@ -277,7 +277,7 @@ public class DeployFileMojo
 
         try
         {
-            getDeployer().deploy( file, artifact, deploymentRepository, 
getLocalRepository() );
+            deploy( file, artifact, deploymentRepository, getLocalRepository() 
);
         }
         catch ( ArtifactDeploymentException e )
         {
@@ -302,7 +302,7 @@ public class DeployFileMojo
 
             try
             {
-                getDeployer().deploy( attached.getFile(), attached, 
deploymentRepository, getLocalRepository() );
+                deploy( attached.getFile(), attached, deploymentRepository, 
getLocalRepository() );
             }
             catch ( ArtifactDeploymentException e )
             {

Modified: 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java?rev=1126367&r1=1126366&r2=1126367&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
 Mon May 23 08:02:50 2011
@@ -145,7 +145,7 @@ public class DeployMojo
         {
             if ( isPomArtifact )
             {
-                getDeployer().deploy( pomFile, artifact, repo, 
getLocalRepository() );
+                deploy( pomFile, artifact, repo, getLocalRepository() );
             }
             else
             {
@@ -153,7 +153,7 @@ public class DeployMojo
 
                 if ( file != null && file.isFile() )
                 {
-                    getDeployer().deploy( file, artifact, repo, 
getLocalRepository() );
+                    deploy( file, artifact, repo, getLocalRepository() );
                 }
                 else if ( !attachedArtifacts.isEmpty() )
                 {
@@ -168,7 +168,7 @@ public class DeployMojo
                         pomArtifact.setRelease( true );
                     }
 
-                    getDeployer().deploy( pomFile, pomArtifact, repo, 
getLocalRepository() );
+                    deploy( pomFile, pomArtifact, repo, getLocalRepository() );
 
                     // propagate the timestamped version to the main artifact 
for the attached artifacts to pick it up
                     artifact.setResolvedVersion( pomArtifact.getVersion() );
@@ -184,7 +184,7 @@ public class DeployMojo
             {
                 Artifact attached = ( Artifact ) i.next();
 
-                getDeployer().deploy( attached.getFile(), attached, repo, 
getLocalRepository() );
+                deploy( attached.getFile(), attached, repo, 
getLocalRepository() );
             }
         }
         catch ( ArtifactDeploymentException e )


Reply via email to