Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tycho-4.0.x] Improve the error message in case of a DependencyResolutionException #3419

Merged
merged 1 commit into from
Jan 27, 2024
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 @@ -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