Skip to content

Commit

Permalink
Improve error reporting when MavenParser encounters a MavenDownloadin…
Browse files Browse the repository at this point in the history
…gExceptions which contains only a single MavenDownloadingException.
  • Loading branch information
sambsnyd committed Oct 3, 2024
1 parent 8249104 commit fa7533b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions rewrite-maven/src/main/java/org/openrewrite/maven/MavenParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ public Stream<SourceFile> parseInputs(Iterable<Input> 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))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class MavenResolutionResult implements Marker {

public List<String> getActiveProfiles() {
// for backwards compatibility with ASTs that were serialized before activeProfiles was added
//noinspection ConstantValue
return activeProfiles == null ? emptyList() : activeProfiles;
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fa7533b

Please sign in to comment.