This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MRESOLVER-337
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit 7f557049130c6b905156174dde510d2608ed2b47
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Wed Mar 1 21:07:03 2023 +0100

    [MRESOLVER-337] Real cause when artifact not found with repository filtering
    
    When we use remote repository filtering real cause for artifact not found 
may be hidden.
---
 .../resolution/ArtifactResolutionException.java    |  5 +--
 .../transfer/RepositoryFilteredException.java      | 38 ++++++++++++++++++++++
 .../internal/impl/DefaultArtifactResolver.java     |  3 +-
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git 
a/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
 
b/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
index 2d829e18..4f23d666 100644
--- 
a/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
+++ 
b/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.eclipse.aether.RepositoryException;
 import org.eclipse.aether.transfer.ArtifactNotFoundException;
+import org.eclipse.aether.transfer.RepositoryFilteredException;
 import org.eclipse.aether.transfer.RepositoryOfflineException;
 
 /**
@@ -58,7 +59,7 @@ public class ArtifactResolutionException extends 
RepositoryException {
      *
      * @param results The resolution results at the point the exception 
occurred, may be {@code null}.
      * @param message The detail message, may be {@code null}.
-     * @param cause The exception that caused this one, may be {@code null}.
+     * @param cause   The exception that caused this one, may be {@code null}.
      */
     public ArtifactResolutionException(List<ArtifactResult> results, String 
message, Throwable cause) {
         super(message, cause);
@@ -122,7 +123,7 @@ public class ArtifactResolutionException extends 
RepositoryException {
                 Throwable notFound = null, offline = null;
                 for (Throwable t : result.getExceptions()) {
                     if (t instanceof ArtifactNotFoundException) {
-                        if (notFound == null) {
+                        if (notFound == null || notFound instanceof 
RepositoryFilteredException) {
                             notFound = t;
                         }
                         if (offline == null && t.getCause() instanceof 
RepositoryOfflineException) {
diff --git 
a/maven-resolver-api/src/main/java/org/eclipse/aether/transfer/RepositoryFilteredException.java
 
b/maven-resolver-api/src/main/java/org/eclipse/aether/transfer/RepositoryFilteredException.java
new file mode 100644
index 00000000..0855f183
--- /dev/null
+++ 
b/maven-resolver-api/src/main/java/org/eclipse/aether/transfer/RepositoryFilteredException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eclipse.aether.transfer;
+
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.repository.RemoteRepository;
+
+/**
+ * Thrown when an artifact was filtered from a particular repository.
+ */
+public class RepositoryFilteredException extends ArtifactNotFoundException {
+
+    /*** Creates a new exception with the specified artifact, repository and 
detail message.
+     *
+     * @param artifact The missing artifact, may be {@code null}.
+     * @param repository The involved remote repository, may be {@code null}.
+     * @param message The detail message, may be {@code null}.
+     */
+    public RepositoryFilteredException(Artifact artifact, RemoteRepository 
repository, String message) {
+        super(artifact, repository, message);
+    }
+}
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
index 58b4a31a..dd505cb9 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java
@@ -75,6 +75,7 @@ import org.eclipse.aether.spi.synccontext.SyncContextFactory;
 import org.eclipse.aether.transfer.ArtifactNotFoundException;
 import org.eclipse.aether.transfer.ArtifactTransferException;
 import org.eclipse.aether.transfer.NoRepositoryConnectorException;
+import org.eclipse.aether.transfer.RepositoryFilteredException;
 import org.eclipse.aether.transfer.RepositoryOfflineException;
 import org.eclipse.aether.util.ConfigUtils;
 import org.slf4j.Logger;
@@ -308,7 +309,7 @@ public class DefaultArtifactResolver implements 
ArtifactResolver, Service {
                     RemoteRepositoryFilter.Result filterResult = 
filter.acceptArtifact(repository, artifact);
                     if (!filterResult.isAccepted()) {
                         result.addException(
-                                new ArtifactNotFoundException(artifact, 
repository, filterResult.reasoning()));
+                                new RepositoryFilteredException(artifact, 
repository, filterResult.reasoning()));
                         filteredRemoteRepositories.remove(repository);
                     }
                 }

Reply via email to