Skip to content
Draft
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 @@ -187,10 +187,14 @@ private void resolve(

result = repoSystem.resolveArtifact(session, artifactRequest);
} catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
throw new ArtifactNotFoundException(e.getMessage(), artifact, remoteRepositories, e);
// This is a workaround for MNG-7758/MRESOLVER-335
if (e.getResult().getExceptions().stream()
.anyMatch(re -> re instanceof org.eclipse.aether.transfer.ArtifactNotFoundException)) {
throw new ArtifactNotFoundException(
"Could not find artifact '" + artifact + "'", artifact, remoteRepositories, e);
} else {
throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
throw new ArtifactResolutionException(
"Failed to resolve artifact '" + artifact + "'", artifact, remoteRepositories, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,13 @@ public ProjectBuildingResult build(Artifact artifact, boolean allowStubModel, Pr
pomArtifact = pomResult.getArtifact();
localProject = pomResult.getRepository() instanceof WorkspaceRepository;
} catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
if (e.getResults().get(0).isMissing() && allowStubModel) {
// This is a workaround for MNG-7758/MRESOLVER-335
if (e.getResult().getExceptions().stream()
.anyMatch(re -> re instanceof org.eclipse.aether.transfer.ArtifactNotFoundException)
&& allowStubModel) {
return build(null, createStubModelSource(artifact), config);
}
throw new ProjectBuildingException(
artifact.getId(), "Error resolving project artifact: " + e.getMessage(), e);
throw new ProjectBuildingException(artifact.getId(), "Error resolving project artifact", e);
}

File pomFile = pomArtifact.getFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ public ModelSource resolveModel(String groupId, String artifactId, String versio
request.setTrace(trace);
pomArtifact = resolver.resolveArtifact(session, request).getArtifact();
} catch (ArtifactResolutionException e) {
throw new UnresolvableModelException(e.getMessage(), groupId, artifactId, version, e);
throw new UnresolvableModelException(
String.format("Failed to resolve model artifact '%s'", pomArtifact),
groupId,
artifactId,
version,
e);
}

return new ArtifactModelSource(pomArtifact.getFile(), groupId, artifactId, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.repository.WorkspaceReader;
import org.eclipse.aether.transfer.ArtifactNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -672,16 +671,22 @@ private boolean isMissingPom(Exception e) {
if (e.getCause() instanceof MultipleArtifactsNotFoundException) {
return true;
}
// This is a workaround for MNG-7758/MRESOLVER-335
return e.getCause() instanceof org.eclipse.aether.resolution.ArtifactResolutionException
&& e.getCause().getCause() instanceof ArtifactNotFoundException;
&& ((org.eclipse.aether.resolution.ArtifactResolutionException) e.getCause())
.getResult().getExceptions().stream()
.anyMatch(re -> re instanceof org.eclipse.aether.transfer.ArtifactNotFoundException);
}

private boolean isNonTransferablePom(Exception e) {
if (e.getCause() instanceof ArtifactResolutionException) {
return true;
}
// This is a workaround for MNG-7758/MRESOLVER-335
return e.getCause() instanceof org.eclipse.aether.resolution.ArtifactResolutionException
&& !(e.getCause().getCause() instanceof ArtifactNotFoundException);
&& ((org.eclipse.aether.resolution.ArtifactResolutionException) e.getCause())
.getResult().getExceptions().stream()
.noneMatch(re -> re instanceof org.eclipse.aether.transfer.ArtifactNotFoundException);
}

private Properties getSystemProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ private boolean isModuleOutsideRequestScopeDependingOnPluginModule(
Predicate<Exception> pluginArtifactNotFoundException = exc -> exc instanceof PluginManagerException
&& exc.getCause() instanceof PluginResolutionException
&& exc.getCause().getCause() instanceof ArtifactResolutionException
&& exc.getCause().getCause().getCause() instanceof ArtifactNotFoundException;
// This is a workaround for MNG-7758/MRESOLVER-335
&& ((ArtifactResolutionException) exc.getCause().getCause())
.getResult().getExceptions().stream()
.anyMatch(re -> re instanceof ArtifactNotFoundException);

Predicate<Plugin> isPluginPartOfRequestScope = plugin -> projectsInRequestScope.stream()
.anyMatch(project -> project.getGroupId().equals(plugin.getGroupId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exce
() -> newModelResolver().resolveModel(parent.getDelegate(), new AtomicReference<>()),
"Expected 'UnresolvableModelException' not thrown.");
assertNotNull(e.getMessage());
assertThat(e.getMessage(), containsString("Could not find artifact org.apache:apache:pom:0 in central"));
assertThat(e.getMessage(), containsString("Failed to resolve model artifact 'org.apache:apache:pom:0'"));
}

@Test
Expand Down Expand Up @@ -135,7 +135,7 @@ void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws
() -> newModelResolver().resolveModel(dependency.getDelegate(), new AtomicReference<>()),
"Expected 'UnresolvableModelException' not thrown.");
assertNotNull(e.getMessage());
assertThat(e.getMessage(), containsString("Could not find artifact org.apache:apache:pom:0 in central"));
assertThat(e.getMessage(), containsString("Failed to resolve model artifact 'org.apache:apache:pom:0'"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ private Model loadPom(
pomArtifact = resolveResult.getArtifact();
result.setRepository(resolveResult.getRepository());
} catch (ArtifactResolutionException e) {
if (e.getCause() instanceof ArtifactNotFoundException) {
missingDescriptor(session, trace, a, (Exception) e.getCause());
// This is a workaround for MNG-7758/MRESOLVER-335
if (e.getResult().getExceptions().stream().anyMatch(re -> re instanceof ArtifactNotFoundException)) {
missingDescriptor(session, trace, a, (Exception) e.getResult().getExceptions().stream()
.filter(re -> re instanceof ArtifactNotFoundException)
.findFirst()
.get());
if ((getPolicy(session, a, request) & ArtifactDescriptorPolicy.IGNORE_MISSING) != 0) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ public ModelSource resolveModel(String groupId, String artifactId, String versio
request.setTrace(trace);
pomArtifact = resolver.resolveArtifact(session, request).getArtifact();
} catch (ArtifactResolutionException e) {
throw new UnresolvableModelException(e.getMessage(), groupId, artifactId, version, e);
throw new UnresolvableModelException(
String.format("Failed to resolve model artifact '%s'", pomArtifact),
groupId,
artifactId,
version,
e);
}

return new ArtifactModelSource(pomArtifact.getFile(), groupId, artifactId, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exce
() -> newModelResolver().resolveModel(parent, new AtomicReference<>()),
"Expected 'UnresolvableModelException' not thrown.");
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("Could not find artifact ut.simple:artifact:pom:0 in repo"));
assertTrue(e.getMessage().contains("Failed to resolve model artifact 'ut.simple:artifact:pom:0'"));
}

@Test
Expand Down Expand Up @@ -138,7 +138,7 @@ void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws
() -> newModelResolver().resolveModel(dependency, new AtomicReference<>()),
"Expected 'UnresolvableModelException' not thrown.");
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("Could not find artifact ut.simple:artifact:pom:0 in repo"));
assertTrue(e.getMessage().contains("Failed to resolve model artifact 'ut.simple:artifact:pom:0'"));
}

@Test
Expand Down