Skip to content

Commit

Permalink
[MNG-7758] Report dependency problems for all repository (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Jun 12, 2024
1 parent db33754 commit 768ebbc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,9 @@
*/
package org.apache.maven.plugin;

import java.util.List;
import java.util.stream.Collectors;

import org.apache.maven.model.Plugin;

/**
Expand All @@ -35,6 38,18 @@ public PluginResolutionException(Plugin plugin, Throwable cause) {
this.plugin = plugin;
}

public PluginResolutionException(Plugin plugin, List<Exception> exceptions, Throwable cause) {
super(
"Plugin " plugin.getId() " or one of its dependencies could not be resolved:"
System.lineSeparator() "\t"
exceptions.stream()
.map(Throwable::getMessage)
.collect(Collectors.joining(System.lineSeparator() "\t"))
System.lineSeparator(),
cause);
this.plugin = plugin;
}

public Plugin getPlugin() {
return plugin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 132,17 @@ public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, Repo
pluginArtifact = pluginArtifact.setProperties(props);
}
} catch (ArtifactDescriptorException e) {
throw new PluginResolutionException(plugin, e);
throw new PluginResolutionException(
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
}

try {
ArtifactRequest request = new ArtifactRequest(pluginArtifact, repositories, REPOSITORY_CONTEXT);
request.setTrace(trace);
pluginArtifact = repoSystem.resolveArtifact(session, request).getArtifact();
} catch (ArtifactResolutionException e) {
throw new PluginResolutionException(plugin, e);
throw new PluginResolutionException(
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
}

return pluginArtifact;
Expand Down Expand Up @@ -229,9 231,11 @@ private DependencyResult resolveInternal(
depRequest.setRoot(node);
return repoSystem.resolveDependencies(session, depRequest);
} catch (DependencyCollectionException e) {
throw new PluginResolutionException(plugin, e);
throw new PluginResolutionException(
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
} catch (DependencyResolutionException e) {
throw new PluginResolutionException(plugin, e.getCause());
throw new PluginResolutionException(
plugin, e.getResult().getCollectExceptions(), logger.isDebugEnabled() ? e : null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 160,9 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
result.setCollectionErrors(e.getResult().getExceptions());

throw new DependencyResolutionException(
result, "Could not resolve dependencies for project " project.getId() ": " e.getMessage(), e);
result,
"Could not collect dependencies for project " project.getId(),
logger.isDebugEnabled() ? e : null);
}

depRequest.setRoot(node);
Expand Down Expand Up @@ -190,7 192,9 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
process(result, e.getResult().getArtifactResults());

throw new DependencyResolutionException(
result, "Could not resolve dependencies for project " project.getId() ": " e.getMessage(), e);
result,
"Could not resolve dependencies for project " project.getId(),
logger.isDebugEnabled() ? e : null);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 18,52 @@
*/
package org.apache.maven.project;

import java.util.List;

import org.eclipse.aether.graph.Dependency;

/**
*/
public class DependencyResolutionException extends Exception {

private final transient DependencyResolutionResult result;
private final transient String detailMessage;

public DependencyResolutionException(DependencyResolutionResult result, String message, Throwable cause) {
super(message, cause);
this.result = result;
this.detailMessage = prepareDetailMessage(message, result);
}

private static String prepareDetailMessage(String message, DependencyResolutionResult result) {
StringBuilder msg = new StringBuilder(message);
msg.append(System.lineSeparator());
for (Dependency dependency : result.getUnresolvedDependencies()) {
msg.append("dependency: ").append(dependency).append(System.lineSeparator());
List<Exception> exceptions = result.getResolutionErrors(dependency);
for (Exception e : exceptions) {
msg.append("\t").append(e.getMessage()).append(System.lineSeparator());
}
}

for (Exception exception : result.getCollectionErrors()) {
msg.append(exception.getMessage()).append(System.lineSeparator());
if (exception.getCause() != null) {
msg.append("\tCaused by: ")
.append(exception.getCause().getMessage())
.append(System.lineSeparator());
}
}

return msg.toString();
}

public DependencyResolutionResult getResult() {
return result;
}

@Override
public String getMessage() {
return detailMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 226,7 @@ private List<Artifact> resolveExtension(
.filter(ArtifactResult::isResolved)
.map(ArtifactResult::getArtifact)
.collect(Collectors.toList());
} catch (PluginResolutionException e) {
throw new ExtensionResolutionException(extension, e.getCause());
} catch (InterpolationException e) {
} catch (PluginResolutionException | InterpolationException e) {
throw new ExtensionResolutionException(extension, e);
}
}
Expand Down

0 comments on commit 768ebbc

Please sign in to comment.