mirror of https://github.com/apache/maven.git
[MNG-7758] Report dependency problems for all repository (#1563)
This commit is contained in:
parent
db33754938
commit
768ebbc263
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
package org.apache.maven.plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
||||
/**
|
||||
|
@ -35,6 +38,18 @@ public class PluginResolutionException extends Exception {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -132,7 +132,8 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
|
|||
pluginArtifact = pluginArtifact.setProperties(props);
|
||||
}
|
||||
} catch (ArtifactDescriptorException e) {
|
||||
throw new PluginResolutionException(plugin, e);
|
||||
throw new PluginResolutionException(
|
||||
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -140,7 +141,8 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
|
|||
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;
|
||||
|
@ -229,9 +231,11 @@ public class DefaultPluginDependenciesResolver implements PluginDependenciesReso
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,9 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesRe
|
|||
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);
|
||||
|
@ -190,7 +192,9 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesRe
|
|||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,9 +226,7 @@ public class BootstrapCoreExtensionManager {
|
|||
.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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue