From fa7533bf48142fde040a6ecd308f6b0cc9d9c179 Mon Sep 17 00:00:00 2001 From: Sam Snyder Date: Wed, 2 Oct 2024 20:14:09 -0700 Subject: [PATCH] Improve error reporting when MavenParser encounters a MavenDownloadingExceptions which contains only a single MavenDownloadingException. --- .../java/org/openrewrite/maven/MavenParser.java | 14 +++++++++++--- .../maven/tree/MavenResolutionResult.java | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenParser.java b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenParser.java index c37f373f0c9..14f3cc6fc67 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/MavenParser.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/MavenParser.java @@ -117,9 +117,17 @@ public Stream parseInputs(Iterable sources, @Nullable Path re } parsed.add(docToPom.getKey().withMarkers(docToPom.getKey().getMarkers().compute(model, (old, n) -> n))); } catch (MavenDownloadingExceptions e) { - String message = e.warn(docToPom.getKey()).printAll(); // Shows any underlying MavenDownloadingException - parsed.add(docToPom.getKey().withMarkers(docToPom.getKey().getMarkers().add(ParseExceptionResult.build(this, e, message)))); - ctx.getOnError().accept(e); + if (e.getExceptions().size() == 1) { + // If there is only a single MavenDownloadingException, report just that as no additional debugging value is gleaned from its wrapper + MavenDownloadingException e2 = e.getExceptions().get(0); + String message = e2.warn(docToPom.getKey()).printAll(); // Shows any underlying MavenDownloadingException + parsed.add(docToPom.getKey().withMarkers(docToPom.getKey().getMarkers().add(ParseExceptionResult.build(this, e2, message)))); + ctx.getOnError().accept(e2); + } else { + String message = e.warn(docToPom.getKey()).printAll(); // Shows any underlying MavenDownloadingException + parsed.add(docToPom.getKey().withMarkers(docToPom.getKey().getMarkers().add(ParseExceptionResult.build(this, e, message)))); + ctx.getOnError().accept(e); + } } catch (MavenDownloadingException e) { String message = e.warn(docToPom.getKey()).printAll(); // Shows any underlying MavenDownloadingException parsed.add(docToPom.getKey().withMarkers(docToPom.getKey().getMarkers().add(ParseExceptionResult.build(this, e, message)))); diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java index 2ba1171e943..d0bef4177b6 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java @@ -68,6 +68,7 @@ public class MavenResolutionResult implements Marker { public List getActiveProfiles() { // for backwards compatibility with ASTs that were serialized before activeProfiles was added + //noinspection ConstantValue return activeProfiles == null ? emptyList() : activeProfiles; } @@ -173,7 +174,8 @@ public MavenResolutionResult resolveDependencies(MavenPomDownloader downloader, dependencies.put(scope, pom.resolveDependencies(scope, downloader, ctx)); } catch (MavenDownloadingExceptions e) { for (MavenDownloadingException exception : e.getExceptions()) { - if (exceptionsInLowerScopes.computeIfAbsent(new GroupArtifact(exception.getRoot().getGroupId(), + if (exceptionsInLowerScopes.computeIfAbsent(new GroupArtifact( + exception.getRoot().getGroupId() == null ? "" : exception.getRoot().getGroupId(), exception.getRoot().getArtifactId()), ga -> new HashSet<>()).add(exception.getFailedOn())) { exceptions = MavenDownloadingExceptions.append(exceptions, exception); }