You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mt...@apache.org on 2020/07/24 08:08:42 UTC

[maven] branch master updated: Resume from generates misleading hint when multiple projects fail.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5739b12  Resume from generates misleading hint when multiple projects fail.
5739b12 is described below

commit 5739b12aa9fc03bdd9eb6482b7a75f98a3c1ba6e
Author: Martin Kanters <Ma...@infosupport.com>
AuthorDate: Tue Apr 21 14:56:27 2020 +0200

    Resume from generates misleading hint when multiple projects fail.
    
    Log the topologically sorted first failed project instead of the chronologically first failed project.
    Resume from generates misleading hint when multiple projects fail.
    Fixed a checkstyle finding.
    Removed a trailing space in the -r hint
---
 .../main/java/org/apache/maven/cli/MavenCli.java   | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 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 c79dab4..b0d6490 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
@@ -115,6 +115,7 @@ import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static java.util.Comparator.comparing;
 import static org.apache.maven.cli.ResolveFile.resolveFile;
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 
@@ -986,7 +987,7 @@ public class MavenCli
 
             Map<String, String> references = new LinkedHashMap<>();
 
-            MavenProject project = null;
+            List<MavenProject> failedProjects = new ArrayList<>();
 
             for ( Throwable exception : result.getExceptions() )
             {
@@ -994,10 +995,9 @@ public class MavenCli
 
                 logSummary( summary, references, "", cliRequest.showErrors );
 
-                if ( project == null && exception instanceof LifecycleExecutionException )
+                if ( exception instanceof LifecycleExecutionException )
                 {
-                    LifecycleExecutionException lifecycleExecutionException = (LifecycleExecutionException) exception;
-                    project = lifecycleExecutionException.getProject();
+                    failedProjects.add ( ( (LifecycleExecutionException) exception ).getProject() );
                 }
             }
 
@@ -1026,15 +1026,23 @@ public class MavenCli
                 }
             }
 
-            List<MavenProject> sortedProjects = result.getTopologicallySortedProjects();
             if ( result.canResume() )
             {
-                logBuildResumeHint( "mvn <args> -r " );
+                logBuildResumeHint( "mvn <args> -r" );
             }
-            else if ( project != null && !project.equals( sortedProjects.get( 0 ) ) )
+            else if ( !failedProjects.isEmpty() )
             {
-                String resumeFromSelector = getResumeFromSelector( sortedProjects, project );
-                logBuildResumeHint( "mvn <args> -rf " + resumeFromSelector );
+                List<MavenProject> sortedProjects = result.getTopologicallySortedProjects();
+
+                // Sort the failedProjects list in the topologically sorted order.
+                failedProjects.sort( comparing( sortedProjects::indexOf ) );
+
+                MavenProject firstFailedProject = failedProjects.get( 0 );
+                if ( !firstFailedProject.equals( sortedProjects.get( 0 ) ) )
+                {
+                    String resumeFromSelector = getResumeFromSelector( sortedProjects, firstFailedProject );
+                    logBuildResumeHint( "mvn <args> -rf " + resumeFromSelector );
+                }
             }
 
             if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( cliRequest.request.getReactorFailureBehavior() ) )
@@ -1074,22 +1082,22 @@ public class MavenCli
      * This method is made package-private for testing purposes.
      *
      * @param mavenProjects Maven projects which are part of build execution.
-     * @param failedProject Project which has failed.
+     * @param firstFailedProject The first project which has failed.
      * @return Value for -rf flag to resume build exactly from place where it failed ({@code :artifactId} in general
      * and {@code groupId:artifactId} when there is a name clash).
      */
-    String getResumeFromSelector( List<MavenProject> mavenProjects, MavenProject failedProject )
+    String getResumeFromSelector( List<MavenProject> mavenProjects, MavenProject firstFailedProject )
     {
         boolean hasOverlappingArtifactId = mavenProjects.stream()
-                .filter( project -> failedProject.getArtifactId().equals( project.getArtifactId() ) )
+                .filter( project -> firstFailedProject.getArtifactId().equals( project.getArtifactId() ) )
                 .count() > 1;
 
         if ( hasOverlappingArtifactId )
         {
-            return failedProject.getGroupId() + ":" + failedProject.getArtifactId();
+            return firstFailedProject.getGroupId() + ":" + firstFailedProject.getArtifactId();
         }
 
-        return ":" + failedProject.getArtifactId();
+        return ":" + firstFailedProject.getArtifactId();
     }
 
     private void logSummary( ExceptionSummary summary, Map<String, String> references, String indent,