You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/05/23 10:02:51 UTC

svn commit: r1126367 - in /maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy: AbstractDeployMojo.java DeployFileMojo.java DeployMojo.java

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 )



Re: svn commit: r1126367 - in /maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy: AbstractDeployMojo.java DeployFileMojo.java DeployMojo.java

Posted by Stephen Connolly <st...@gmail.com>.
On 23 May 2011 10:10, Brett Porter <br...@apache.org> wrote:
> Wow, serendipity. I was going to implement that later tonight :)
>

Yeah well the Cassandra guys need retries in gpg:sign-and-deploy-file
so symmetry demands the same in deploy:deploy-file

> Nice one!
>
> Just a couple of comments inline:
>
> On 23/05/2011, at 6:02 PM, stephenc@apache.org wrote:
>
>>
>> [MDEPLOY-133]
>
> I think the log comment could cover more :)
>>
>> +            catch ( ArtifactDeploymentException e )
>> +            {
>
> Are there specific types of exceptions that are "fatal" that can be captured? 502/503 responses make sense to retry, but not sure about 500, 403, 401, etc.
>

you assume that all deployments are over Http(s)... and there may be a
case whereby I realise that I don't have permissions in the middle of
the release and I run to fix them, just missing the first attempt ;-)

>> +                if (count + 1 < retryFailedDeploymentCount) {
>> +                    getLog().warn( "Something went wrong with the deployment, will try again", e );
>
> This may be more verbose than necessary - how about just e.getMessage, with the trace logged at debug level?
>

Done: r1126407/8

>> +                }
>> +                if ( exception == null )
>> +                {
>> +                    exception = e;
>> +                }
>
> A completely new exception that says to refer to the other failures might be more appropriate, if they happen to differ... though that may be too much of an edge case :)
>

well if you want to push that shared exception up to a common module
between m-gpg-p and m-deploy-p fine by me ;-)

> Cheers,
> Brett
>
> --
> Brett Porter
> brett@apache.org
> http://brettporter.wordpress.com/
> http://au.linkedin.com/in/brettporter
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>

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


Re: svn commit: r1126367 - in /maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy: AbstractDeployMojo.java DeployFileMojo.java DeployMojo.java

Posted by Brett Porter <br...@apache.org>.
Wow, serendipity. I was going to implement that later tonight :)

Nice one!

Just a couple of comments inline:

On 23/05/2011, at 6:02 PM, stephenc@apache.org wrote:

> 
> [MDEPLOY-133]

I think the log comment could cover more :)
> 
> +            catch ( ArtifactDeploymentException e )
> +            {

Are there specific types of exceptions that are "fatal" that can be captured? 502/503 responses make sense to retry, but not sure about 500, 403, 401, etc.

> +                if (count + 1 < retryFailedDeploymentCount) {
> +                    getLog().warn( "Something went wrong with the deployment, will try again", e );

This may be more verbose than necessary - how about just e.getMessage, with the trace logged at debug level?

> +                }
> +                if ( exception == null )
> +                {
> +                    exception = e;
> +                }

A completely new exception that says to refer to the other failures might be more appropriate, if they happen to differ... though that may be too much of an edge case :)

Cheers,
Brett

--
Brett Porter
brett@apache.org
http://brettporter.wordpress.com/
http://au.linkedin.com/in/brettporter





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