Skip to content

Commit

Permalink
Switch to a list of warnings to have the full details
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Feb 4, 2025
1 parent cce8e3c commit ace19f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;

Expand Down Expand Up @@ -67,8 +69,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}

AtomicReference<@Nullable Throwable> throwable = new AtomicReference<>();
ExecutionContext ctx = executionContext(throwable);
List<Throwable> throwables = new ArrayList<>();
ExecutionContext ctx = executionContext(throwables);

ResultsContainer results = listResults(ctx);

Expand All @@ -77,8 +79,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().error("The recipe produced an error. Please report this to the recipe author.");
throw firstException;
}
if (throwable.get() != null) {
getLog().warn("The recipe produced a warning. Please report this to the recipe author.", throwable.get());
if (!throwables.isEmpty()) {
getLog().warn("The recipe produced " + throwables.size() + " warning(s). Please report this to the recipe author.", throwables.get(0));
}

if (results.isNotEmpty()) {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,8 @@ protected Environment environment(@Nullable ClassLoader recipeClassLoader) throw
return env.build();
}

protected ExecutionContext executionContext(AtomicReference<@Nullable Throwable> throwable) {
return new InMemoryExecutionContext(t -> {
if (throwable.get() == null) {
throwable.set(t);
}
});
protected ExecutionContext executionContext(List<Throwable> throwables) {
return new InMemoryExecutionContext(throwables::add);
}

protected Path getBuildRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -61,8 +62,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}

AtomicReference<@Nullable Throwable> throwable = new AtomicReference<>();
ExecutionContext ctx = executionContext(throwable);
List<Throwable> throwables = new ArrayList<>();
ExecutionContext ctx = executionContext(throwables);

ResultsContainer results = listResults(ctx);

Expand All @@ -71,8 +72,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().error("The recipe produced an error. Please report this to the recipe author.");
throw firstException;
}
if (throwable.get() != null) {
getLog().warn("The recipe produced a warning. Please report this to the recipe author.", throwable.get());
if (!throwables.isEmpty()) {
getLog().warn("The recipe produced " + throwables.size() + " warning(s). Please report this to the recipe author.", throwables.get(0));
}

if (results.isNotEmpty()) {
Expand Down

0 comments on commit ace19f6

Please sign in to comment.