diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java index 3b52c221..4fc97728 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteDryRunMojo.java @@ -28,6 +28,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.ArrayList; +import java.util.List; import java.util.stream.Stream; /** @@ -66,7 +68,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } - ExecutionContext ctx = executionContext(); + List throwables = new ArrayList<>(); + ExecutionContext ctx = executionContext(throwables); + ResultsContainer results = listResults(ctx); RuntimeException firstException = results.getFirstException(); @@ -74,6 +78,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().error("The recipe produced an error. Please report this to the recipe author."); throw firstException; } + if (!throwables.isEmpty()) { + getLog().warn("The recipe produced " + throwables.size() + " warning(s). Please report this to the recipe author."); + if (!getLog().isDebugEnabled() && !exportDatatables) { + getLog().warn("Run with `--debug` or `-Drewrite.exportDatatables=true` to see all warnings.", throwables.get(0)); + } + } if (results.isNotEmpty()) { Duration estimateTimeSaved = Duration.ZERO; diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java index 165e4910..ea25810c 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java @@ -125,8 +125,11 @@ protected Environment environment(@Nullable ClassLoader recipeClassLoader) throw return env.build(); } - protected ExecutionContext executionContext() { - return new InMemoryExecutionContext(t -> getLog().debug(t)); + protected ExecutionContext executionContext(List throwables) { + return new InMemoryExecutionContext(t -> { + getLog().debug(t); + throwables.add(t); + }); } protected Path getBuildRoot() { diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java index 3fb46c39..61bac599 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java @@ -17,7 +17,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.FileAttributes; import org.openrewrite.PrintOutputCapture; @@ -32,6 +31,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; +import java.util.ArrayList; import java.util.List; /** @@ -60,13 +60,22 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } - ExecutionContext ctx = executionContext(); + List throwables = new ArrayList<>(); + ExecutionContext ctx = executionContext(throwables); + ResultsContainer results = listResults(ctx); - @Nullable RuntimeException firstException = results.getFirstException(); + + RuntimeException firstException = results.getFirstException(); if (firstException != null) { getLog().error("The recipe produced an error. Please report this to the recipe author."); throw firstException; } + if (!throwables.isEmpty()) { + getLog().warn("The recipe produced " + throwables.size() + " warning(s). Please report this to the recipe author."); + if (!getLog().isDebugEnabled() && !exportDatatables) { + getLog().warn("Run with `--debug` or `-Drewrite.exportDatatables=true` to see all warnings.", throwables.get(0)); + } + } if (results.isNotEmpty()) { Duration estimateTimeSaved = Duration.ZERO;