Skip to content

Commit

Permalink
Improve the error message in case of a DependencyResolutionException
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 26, 2024
1 parent cf9a060 commit 9361742
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws
try {
resolver.resolveProject(mavenSession, mavenProject);
} catch (DependencyResolutionException e) {
ResolverException resolverException = findResolverException(e);
ResolverException resolverException = ResolverException.findResolverException(e);
if (resolverException == null) {
throw new LifecycleExecutionException(
"Cannot resolve dependencies of project " + mavenProject.getId(), null, mavenProject, e);
Expand Down Expand Up @@ -148,21 +148,6 @@ public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws
}
}

private ResolverException findResolverException(Throwable t) {
if (t != null) {
if (t instanceof ResolverException re) {
return re;
}
for (Throwable sup : t.getSuppressed()) {
if (sup instanceof ResolverException re) {
return re;
}
}
return findResolverException(t.getCause());
}
return null;
}

private Set<MavenProject> checkBuildState(TychoProject tychoProject, MavenProject project) throws CoreException {
ReactorProject reactorProject = DefaultReactorProject.adapt(project);
DependencyArtifacts artifacts = tychoProject.getDependencyArtifacts(reactorProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,19 @@ public Stream<Explanation> explanations() {
return explanation.stream();
}

public static ResolverException findResolverException(Throwable t) {
if (t != null) {
if (t instanceof ResolverException re) {
return re;
}
for (Throwable sup : t.getSuppressed()) {
if (sup instanceof ResolverException re) {
return re;
}
}
return findResolverException(t.getCause());
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -27,6 +28,7 @@
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactDescriptor;
import org.eclipse.tycho.DependencyArtifacts;
import org.eclipse.tycho.DependencyResolutionException;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetPlatform;
import org.eclipse.tycho.TychoConstants;
Expand All @@ -35,6 +37,7 @@
import org.eclipse.tycho.core.TargetPlatformConfiguration;
import org.eclipse.tycho.core.TychoProjectManager;
import org.eclipse.tycho.p2.repository.RepositoryBlackboardKey;
import org.eclipse.tycho.p2.resolver.ResolverException;
import org.eclipse.tycho.p2.tools.RepositoryReferences;

/**
Expand Down Expand Up @@ -144,6 +147,17 @@ private void addTargetPlatformRepository(RepositoryReferences sources, MavenSess
sources.addMetadataRepository(repositoryLocation);
} catch (IOException e) {
throw new MojoExecutionException("I/O exception while writing the build target platform to disk", e);
} catch (DependencyResolutionException e) {
ResolverException resolverException = ResolverException.findResolverException(e);
if (resolverException == null) {
throw new MojoFailureException("Cannot resolve dependencies of project " + project.getId(), e);
} else {
throw new MojoFailureException("Cannot resolve dependencies of project "
+ project.getId() + System.lineSeparator() + " with context "
+ resolverException.getSelectionContext() + System.lineSeparator() + resolverException
.explanations().map(exp -> " " + exp.toString()).collect(Collectors.joining("\n")),
resolverException);
}
}
}

Expand Down

0 comments on commit 9361742

Please sign in to comment.