Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -36,6 +39,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 @@ -129,15 +129,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 @@ -218,9 +220,11 @@ private DependencyNode resolveInternal(
depRequest.setRoot(node);
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);
}

return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,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 @@ -184,7 +186,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,19 +18,53 @@
*/
package org.apache.maven.project;

import java.util.List;

import org.eclipse.aether.graph.Dependency;

/**
* @author Benjamin Bentmann
*/
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 @@ -178,9 +178,7 @@ private List<Artifact> resolveExtension(
List<Artifact> artifacts = nlg.getArtifacts(false);

return artifacts;
} catch (PluginResolutionException e) {
throw new ExtensionResolutionException(extension, e.getCause());
} catch (InterpolationException e) {
} catch (PluginResolutionException | InterpolationException e) {
throw new ExtensionResolutionException(extension, e);
}
}
Expand Down