[maven-release] branch master updated: [MRELEASE-1031] log info on release goals/phases progress

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[maven-release] branch master updated: [MRELEASE-1031] log info on release goals/phases progress

hboutemy
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-release.git


The following commit(s) were added to refs/heads/master by this push:
     new 733f56d  [MRELEASE-1031] log info on release goals/phases progress
733f56d is described below

commit 733f56dff53f1b00e41c079bdcac96c498529aa4
Author: Hervé Boutemy <[hidden email]>
AuthorDate: Sun Nov 10 15:31:25 2019 +0100

    [MRELEASE-1031] log info on release goals/phases progress
---
 .../release/DefaultReleaseManagerListener.java     | 109 +++++++++++++++++++++
 .../maven/plugins/release/BranchReleaseMojo.java   |   2 +
 .../maven/plugins/release/CleanReleaseMojo.java    |   2 +
 .../maven/plugins/release/PerformReleaseMojo.java  |   2 +
 .../maven/plugins/release/PrepareReleaseMojo.java  |   2 +
 .../maven/plugins/release/RollbackReleaseMojo.java |   2 +
 .../maven/plugins/release/UpdateVersionsMojo.java  |   2 +
 7 files changed, 121 insertions(+)

diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java
new file mode 100644
index 0000000..b8bbb23
--- /dev/null
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java
@@ -0,0 +1,109 @@
+package org.apache.maven.shared.release;
+
+/*
+ * 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.util.List;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.StringUtils;
+
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
+/**
+ * @author Hervé Boutemy
+ */
+public class DefaultReleaseManagerListener
+    implements ReleaseManagerListener
+{
+    private final Log log;
+
+    private final boolean dryRun;
+
+    private String goal;
+
+    private List<String> phases;
+
+    private int currentPhase;
+
+    public DefaultReleaseManagerListener( Log log )
+    {
+        this( log, false );
+    }
+
+    public DefaultReleaseManagerListener( Log log, boolean dryRun )
+    {
+        this.log = log;
+        this.dryRun = dryRun;
+    }
+
+    private void nextPhase( String name )
+    {
+        currentPhase++;
+        if ( !name.equals( phases.get( currentPhase ) ) )
+        {
+            log.warn( "inconsistent phase name: expected '" + phases.get( currentPhase ) + "' but got '" + name + "'" );
+        }
+    }
+
+    public void goalStart( String goal, List<String> phases )
+    {
+        log.info( "starting " + buffer().strong( goal ) + " goal" + ( dryRun ? " in dry-run mode" : "" )
+            + ", composed of " + phases.size() + " phases: " + StringUtils.join( phases.iterator(), ", " ) );
+        currentPhase = -1;
+        this.phases = phases;
+        this.goal = goal;
+    }
+
+    public void phaseStart( String name )
+    {
+        if ( goal == null || ( ( currentPhase + 1 ) >= phases.size() ) )
+        {
+            // out of goal phase
+            log.info( "phase " + buffer().strong( name ) + ( dryRun ? " (dry-run)" : "" ) );
+            return;
+        }
+
+        nextPhase( name );
+        log.info( buffer().strong( "[" + goal + ( dryRun ? " dry-run" : "" ) + "] " ).toString() + ( currentPhase + 1 )
+            + "/" + phases.size() + " " + buffer().strong( name ) );
+    }
+
+    public void phaseEnd()
+    {
+        // NOOP
+    }
+
+    public void phaseSkip( String name )
+    {
+        nextPhase( name );
+    }
+
+    public void goalEnd()
+    {
+        goal = null;
+        phases = null;
+    }
+
+    public void error( String reason )
+    {
+        log.error( "error during phase " + ( currentPhase + 1 ) + "/" + phases.size() + " " + phases.get( currentPhase )
+            + ": " + reason );
+    }
+}
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java
index 2d19880..029f6a0 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java
@@ -25,6 +25,7 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.shared.release.DefaultReleaseManagerListener;
 import org.apache.maven.shared.release.ReleaseBranchRequest;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
@@ -250,6 +251,7 @@ public class BranchReleaseMojo
             branchRequest.setReleaseDescriptorBuilder( config );
             branchRequest.setReleaseEnvironment( getReleaseEnvironment() );
             branchRequest.setReactorProjects( getReactorProjects() );
+            branchRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) );
             branchRequest.setDryRun( dryRun );
             branchRequest.setUserProperties( session.getUserProperties() );
 
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java
index ed23b8a..43e3475 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugins.release;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.shared.release.DefaultReleaseManagerListener;
 import org.apache.maven.shared.release.ReleaseCleanRequest;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
@@ -50,6 +51,7 @@ public class CleanReleaseMojo
         ReleaseCleanRequest cleanRequest = new ReleaseCleanRequest();
         cleanRequest.setReleaseDescriptorBuilder( releaseDescriptor );
         cleanRequest.setReactorProjects( getReactorProjects() );
+        cleanRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog() ) );
         
         try
         {
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java
index 1636106..51636f0 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java
@@ -28,6 +28,7 @@ import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.shared.release.DefaultReleaseManagerListener;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.ReleasePerformRequest;
@@ -194,6 +195,7 @@ public class PerformReleaseMojo
             performRequest.setReleaseDescriptorBuilder( releaseDescriptor );
             performRequest.setReleaseEnvironment( getReleaseEnvironment() );
             performRequest.setReactorProjects( getReactorProjects() );
+            performRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) );
             performRequest.setDryRun( dryRun );
 
             releaseManager.perform( performRequest );
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
index 431ff71..0d9690f 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
@@ -26,6 +26,7 @@ import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.shared.release.DefaultReleaseManagerListener;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.ReleasePrepareRequest;
@@ -293,6 +294,7 @@ public class PrepareReleaseMojo
         prepareRequest.setReleaseDescriptorBuilder( config );
         prepareRequest.setReleaseEnvironment( getReleaseEnvironment() );
         prepareRequest.setReactorProjects( getReactorProjects() );
+        prepareRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) );
         prepareRequest.setResume( resume );
         prepareRequest.setDryRun( dryRun );
         prepareRequest.setUserProperties( session.getUserProperties() );
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java
index 431a1cf..4d2fcf5 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugins.release;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.shared.release.DefaultReleaseManagerListener;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.ReleaseRollbackRequest;
@@ -52,6 +53,7 @@ public class RollbackReleaseMojo
             rollbackRequest.setReleaseDescriptorBuilder( createReleaseDescriptor() );
             rollbackRequest.setReleaseEnvironment( getReleaseEnvironment() );
             rollbackRequest.setReactorProjects( getReactorProjects()  );
+            rollbackRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog() ) );
             
             releaseManager.rollback( rollbackRequest );
         }
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java
index 551fa2e..17c47de 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java
@@ -24,6 +24,7 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.shared.release.DefaultReleaseManagerListener;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.ReleaseUpdateVersionsRequest;
@@ -114,6 +115,7 @@ public class UpdateVersionsMojo
             updateVersionsRequest.setReleaseDescriptorBuilder( config );
             updateVersionsRequest.setReleaseEnvironment( getReleaseEnvironment() );
             updateVersionsRequest.setReactorProjects( getReactorProjects() );
+            updateVersionsRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog() ) );
             updateVersionsRequest.setUserProperties( session.getUserProperties() );
 
             releaseManager.updateVersions( updateVersionsRequest );