Skip to content

Commit

Permalink
Do not wrap non build exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 27, 2024
1 parent dee4667 commit 483818b
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -73,6 +74,7 @@
import org.apache.maven.api.model.Repository;
import org.apache.maven.api.services.BuilderProblem;
import org.apache.maven.api.services.BuilderProblem.Severity;
import org.apache.maven.api.services.MavenException;
import org.apache.maven.api.services.ModelBuilder;
import org.apache.maven.api.services.ModelBuilderException;
import org.apache.maven.api.services.ModelBuilderRequest;
Expand Down Expand Up @@ -739,6 +741,7 @@ private void buildBuildPom() throws ModelBuilderException {
// For the top model and all its children, build the effective model.
// This is done through the phased executor
var allResults = results(result).toList();
List<RuntimeException> exceptions = new CopyOnWriteArrayList<>();
try (PhasingExecutor executor = createExecutor()) {
for (DefaultModelBuilderResult r : allResults) {
executor.execute(() -> {
Expand All @@ -747,15 +750,21 @@ private void buildBuildPom() throws ModelBuilderException {
mbs.buildEffectiveModel(new LinkedHashSet<>());
} catch (ModelBuilderException e) {
// gathered with problem collector
} catch (Exception t) {
mbs.add(Severity.FATAL, ModelProblem.Version.BASE, t.getMessage(), t);
} catch (RuntimeException t) {
exceptions.add(t);
}
});
}
}

// Check for errors again after execution
if (hasErrors()) {
if (exceptions.size() == 1) {
throw exceptions.get(0);
} else if (exceptions.size() > 1) {
MavenException fatalException = new MavenException("Multiple fatal exceptions occurred");
exceptions.forEach(fatalException::addSuppressed);
throw fatalException;
} else if (hasErrors()) {
throw newModelBuilderException();
}
}
Expand Down

0 comments on commit 483818b

Please sign in to comment.