Skip to content

Commit

Permalink
Fix NPE if any of the transitive resolved artifacts fail
Browse files Browse the repository at this point in the history
(cherry picked from commit 5e1f7a5)
  • Loading branch information
laeubi committed Feb 12, 2025
1 parent c09e624 commit 7013e5c
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public class MavenP2SiteMojo extends AbstractMojo {
@Parameter(defaultValue = "false")
private boolean includeTransitiveDependencies;

@Parameter(defaultValue = "false")
private boolean failOnResolveError;

@Parameter(defaultValue = "300")
private int timeoutInSeconds = 300;

Expand Down Expand Up @@ -464,6 +467,9 @@ protected void resolve(List<Dependency> dependencies, List<File> bundles, List<F
logger.debug(" resolved " + resolvedArtifact.getGroupId() + "::" + resolvedArtifact.getArtifactId()
+ "::" + resolvedArtifact.getVersion() + "::" + resolvedArtifact.getClassifier());
File file = resolvedArtifact.getFile();
if (file == null) {
continue;
}
if (filesAdded.add(file.getAbsolutePath())) {
bundles.add(file);
advices.add(createMavenAdvice(resolvedArtifact));
Expand Down Expand Up @@ -516,14 +522,26 @@ private void addProperty(Properties properties, String name, String value, int i

}

protected Set<Artifact> resolveArtifact(Artifact artifact, boolean resolveTransitively) {
protected Set<Artifact> resolveArtifact(Artifact artifact, boolean resolveTransitively)
throws MojoExecutionException {
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setOffline(session.isOffline());
request.setLocalRepository(session.getLocalRepository());
request.setResolveTransitively(resolveTransitively);
request.setRemoteRepositories(session.getCurrentProject().getRemoteArtifactRepositories());
ArtifactResolutionResult result = repositorySystem.resolve(request);
if (failOnResolveError) {
for (Exception exception : result.getExceptions()) {
throw new MojoExecutionException(exception);
}
for (Exception exception : result.getErrorArtifactExceptions()) {
throw new MojoExecutionException(exception);
}
for (Exception exception : result.getMetadataResolutionExceptions()) {
throw new MojoExecutionException(exception);
}
}
return result.getArtifacts();
}

Expand Down

0 comments on commit 7013e5c

Please sign in to comment.