You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/04/22 21:31:11 UTC
[maven] 02/02: [MNG-7770] Implement workaround for MNG-7758/MRESOLVER-335
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch MNG-7758_workaround
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 30dbf2bb47dbb4df05b8c108f78e27cc40b2b3ba
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Apr 22 23:30:56 2023 +0200
[MNG-7770] Implement workaround for MNG-7758/MRESOLVER-335
---
.../maven/artifact/resolver/DefaultArtifactResolver.java | 4 +++-
.../java/org/apache/maven/project/DefaultProjectBuilder.java | 5 ++++-
.../apache/maven/project/artifact/MavenMetadataSource.java | 11 ++++++++---
.../project/collector/MultiModuleCollectionStrategy.java | 5 ++++-
.../repository/internal/DefaultArtifactDescriptorReader.java | 8 ++++++--
5 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
index 6277c1787..48537f771 100644
--- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
+++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
@@ -187,7 +187,9 @@ public class DefaultArtifactResolver implements ArtifactResolver, Disposable {
result = repoSystem.resolveArtifact(session, artifactRequest);
} catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
- if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
+ // 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 {
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index 55d52cac5..8235ef302 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -307,7 +307,10 @@ public class DefaultProjectBuilder implements ProjectBuilder {
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);
diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
index 41af27985..d4398ad09 100644
--- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
+++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
@@ -83,7 +83,6 @@ import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
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;
@@ -672,16 +671,22 @@ public class MavenMetadataSource implements ArtifactMetadataSource {
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() {
diff --git a/maven-core/src/main/java/org/apache/maven/project/collector/MultiModuleCollectionStrategy.java b/maven-core/src/main/java/org/apache/maven/project/collector/MultiModuleCollectionStrategy.java
index fa38120f4..2379bb228 100644
--- a/maven-core/src/main/java/org/apache/maven/project/collector/MultiModuleCollectionStrategy.java
+++ b/maven-core/src/main/java/org/apache/maven/project/collector/MultiModuleCollectionStrategy.java
@@ -160,7 +160,10 @@ public class MultiModuleCollectionStrategy implements ProjectCollectionStrategy
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())
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java
index 8a3ed3ed6..2caea1216 100644
--- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java
@@ -170,8 +170,12 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
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;
}