From 45a502aa1280743e8feb6f828e4e65b6ab12837c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 6 Mar 2024 15:34:40 +0100 Subject: [PATCH] MNG-8069 - add failing projects if a project is banned from reactor Currently if a multimodule build fails (either fast or at the end), the user gets a message in the log that reads: "This project has been banned from the build due to previous failures." this is correct but does not give a hint what has failed and one needs to investigate the build logs to get more details. This now instead shows as part of the message the actual project that make it impossible to build this one and is the reason for this project being banned. --- .../maven/cli/event/ExecutionEventLogger.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java index f7e2b48633e3..9f2169a7fc8f 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/event/ExecutionEventLogger.java @@ -20,6 +20,7 @@ import java.io.File; import java.nio.file.Path; +import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -28,8 +29,10 @@ import org.apache.maven.execution.BuildSuccess; import org.apache.maven.execution.BuildSummary; import org.apache.maven.execution.ExecutionEvent; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenSession; +import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; @@ -243,10 +246,44 @@ public void projectSkipped(ExecutionEvent event) { if (logger.isInfoEnabled()) { logger.info(""); infoLine('-'); + MavenSession session = event.getSession(); + MavenExecutionResult result = session.getResult(); + ProjectDependencyGraph projectDependencyGraph = session.getProjectDependencyGraph(); + List upstreamProjects; + if (MavenExecutionRequest.REACTOR_FAIL_AT_END.equals(session.getReactorFailureBehavior()) + && projectDependencyGraph != null) { + + // the project is blacklisted only so one of its upstreams must have failed here... + upstreamProjects = projectDependencyGraph.getUpstreamProjects(event.getProject(), true); + } else { + // any other failure must have lead to this so any projects is eligible + upstreamProjects = session.getProjects(); + } + // now collect all failing projects order by their ID infoMain("Skipping " + event.getProject().getName()); logger.info("This project has been banned from the build due to previous failures."); - + upstreamProjects.stream() + .map(result::getBuildSummary) + .filter(BuildFailure.class::isInstance) + .map(BuildFailure.class::cast) + .sorted(Comparator.comparing( + BuildFailure::getProject, + Comparator.comparing(MavenProject::getId, String.CASE_INSENSITIVE_ORDER))) + .forEach(buildfailure -> { + String reason; + Throwable cause = buildfailure.getCause(); + if (cause == null) { + reason = "failed!"; + } else { + reason = cause.getClass().getSimpleName(); + String message = cause.getMessage(); + if (message != null) { + message += ": " + message; + } + } + logger.info(" - " + buildfailure.getProject().getId() + ": " + reason); + }); infoLine('-'); } }