You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2018/05/18 21:40:06 UTC

[maven] 01/01: [MNG-6410] Add groupId to --resume-from suggestion if artifactId is not unique in reactor

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

michaelo pushed a commit to branch MNG-6410
in repository https://gitbox.apache.org/repos/asf/maven.git

commit f405517056f9bb24eee0f028ca1c497e1a1992a6
Author: Ɓukasz Dywicki <lu...@code-house.org>
AuthorDate: Fri May 11 15:46:05 2018 +0200

    [MNG-6410] Add groupId to --resume-from suggestion if artifactId is not unique in reactor
    
    This closes #166
---
 .../main/java/org/apache/maven/cli/MavenCli.java   | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 7b5d97b..da2a594 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -1006,8 +1006,8 @@ public class MavenCli
             {
                 slf4jLogger.error( "" );
                 slf4jLogger.error( "After correcting the problems, you can resume the build with the command" );
-                slf4jLogger.error( buffer().a( "  " ).strong( "mvn <goals> -rf :"
-                                + project.getArtifactId() ).toString() );
+                slf4jLogger.error( buffer().a( "  " ).strong( "mvn <goals> -rf "
+                    + getFailedProject( result.getTopologicallySortedProjects(), project ) ).toString() );
             }
 
             if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( cliRequest.request.getReactorFailureBehavior() ) )
@@ -1027,6 +1027,32 @@ public class MavenCli
         }
     }
 
+    /**
+     * A helper method to determine the value returned for re-execution of the build.
+     *
+     * By default -rf :artifactId will pick up first module which matches, but quite often failed project might be later
+     * in build queue. This means that developer will either have to type group id or wait for build execution of all
+     * modules which were fine, but they are still before one which reported errors.
+     * Since build reactor might contain multiple projects with same artifact id for developer convenience we print
+     * out groupId:artifactId when there is a name clash and :artifactId if there is no conflict.
+     *
+     * @param mavenProjects Maven projects which are part of build execution.
+     * @param failedProject Project which has failed.
+     * @return Value for -rf flag to restart build exactly from place where it failed.
+     */
+    private String getFailedProject( List<MavenProject> mavenProjects, MavenProject failedProject )
+    {
+        for ( MavenProject buildProject : mavenProjects )
+        {
+            if ( failedProject.getArtifactId().equals( buildProject.getArtifactId() ) && !failedProject.equals(
+                    buildProject ) )
+            {
+                return failedProject.getGroupId() + ":" + failedProject.getArtifactId();
+            }
+        }
+        return ":" + failedProject.getArtifactId();
+    }
+
     private void logSummary( ExceptionSummary summary, Map<String, String> references, String indent,
                              boolean showErrors )
     {

-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.