You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/08/08 14:50:54 UTC
(maven-build-cache-extension) branch master updated: Stop compiling against Wagon; classify not-found via the Resolver SPI (#521)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git
The following commit(s) were added to refs/heads/master by this push:
new f20a7491 Stop compiling against Wagon; classify not-found via the Resolver SPI (#521)
f20a7491 is described below
commit f20a749178f36413b0485aa49477e1dbe0623e4f
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Aug 8 16:50:49 2026 +0200
Stop compiling against Wagon; classify not-found via the Resolver SPI (#521)
* Stop compiling against Wagon; classify not-found via the Resolver SPI
RemoteCacheRepositoryImpl caught org.apache.maven.wagon.ResourceDoesNotExistException
to recognise a remote cache miss under the Wagon transport, and matched HTTP 404 by
walking exception class *names* plus a reflective getStatusCode() call, because the
transport's exception types live in a different class realm.
Transporter.classify() already answers exactly this question and every implementation
maps its own not-found signal: WagonTransporter maps ResourceDoesNotExistException,
the native HTTP transports map 404/410. Delegating to it drops the direct Wagon
compile dependency and the reflection, and additionally treats 410 Gone as a miss.
wagon-webdav-jackrabbit stays: it is not compiled against, it ships the "dav" Wagon
provider that no Maven distribution bundles, so removing it would break remote cache
URLs of the form dav:http://... (documented in src/site/markdown/remote-cache.md).
wagon-provider-api remains on the runtime classpath transitively via that artifact,
so the resolved dependency set is unchanged.
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <17...@users.noreply.github.com>
---------
Co-authored-by: Copilot Autofix powered by AI <17...@users.noreply.github.com>
---
pom.xml | 7 +--
.../buildcache/RemoteCacheRepositoryImpl.java | 54 +++++-----------------
2 files changed, 14 insertions(+), 47 deletions(-)
diff --git a/pom.xml b/pom.xml
index aa8482ee..f83ab481 100644
--- a/pom.xml
+++ b/pom.xml
@@ -217,16 +217,13 @@ under the License.
<version>${slf4jVersion}</version>
</dependency>
+ <!-- Not compiled against: ships the "dav" Wagon provider so that a remote cache configured with a
+ dav: URL works. Maven distributions do not bundle the WebDAV wagon, so this dependency supplies it at runtime. -->
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>${wagonVersion}</version>
</dependency>
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-provider-api</artifactId>
- <version>${wagonVersion}</version>
- </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
diff --git a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
index 8dafe4f3..37954618 100644
--- a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
+++ b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
@@ -25,8 +25,6 @@
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -45,7 +43,6 @@
import org.apache.maven.buildcache.xml.report.ProjectReport;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.Proxy;
@@ -154,13 +151,10 @@ public Optional<byte[]> getResourceContent(String url) {
GetTask task = new GetTask(new URI(url));
transporter.get(task);
return Optional.of(task.getDataBytes());
- } catch (ResourceDoesNotExistException e) {
- logNotFound(fullUrl, e);
- return Optional.empty();
} catch (Exception e) {
- // this can be wagon used so the exception may be different
- // we want wagon users not flooded with logs when not found
- if (isHttpResponseException(e) && getStatusCode(e) == 404) {
+ // the transport in use (native HTTP, Wagon, ...) decides how a missing resource is signalled,
+ // so let it classify the failure instead of matching on transport specific exception types
+ if (isNotFound(e)) {
logNotFound(fullUrl, e);
return Optional.empty();
}
@@ -174,39 +168,15 @@ public Optional<byte[]> getResourceContent(String url) {
}
}
- private boolean isHttpResponseException(Exception ex) {
- Class<?> currentClass = ex.getClass();
-
- while (currentClass != null) {
- // Apache HttpClient 4.x
- if ("org.apache.http.client.HttpResponseException".equals(currentClass.getName())) {
- return true;
- }
- // Resolver 2 generic; used by all clients
- if ("org.eclipse.aether.spi.connector.transport.http.HttpTransporterException"
- .equals(currentClass.getName())) {
- return true;
- }
- currentClass = currentClass.getSuperclass();
- }
-
- return false;
- }
-
- private int getStatusCode(Exception exception) {
- // just to avoid this when using wagon provide
- // java.lang.ClassCastException: class org.apache.http.client.HttpResponseException cannot be cast to class
- // org.apache.http.client.HttpResponseException
- // (org.apache.http.client.HttpResponseException is in unnamed module of loader
- // org.codehaus.plexus.classworlds.realm.ClassRealm @23cd4ff2;
- //
- try {
- Method method = exception.getClass().getMethod("getStatusCode");
- return (int) method.invoke(exception);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | RuntimeException ex) {
- LOGGER.debug(ex.getMessage(), ex);
- return 0;
- }
+ /**
+ * Asks the transport whether the failure means "the resource is not there", so that a cache miss is not
+ * reported as an error. Every {@link Transporter} implementation knows its own not-found signal: the native
+ * HTTP transports map a 404/410 response, the Wagon transport maps
+ * {@code org.apache.maven.wagon.ResourceDoesNotExistException}. Delegating also avoids comparing exception
+ * types across class realms, which never matches when the transport is loaded by another realm.
+ */
+ private boolean isNotFound(Exception e) {
+ return transporter != null && transporter.classify(e) == Transporter.ERROR_NOT_FOUND;
}
private void logNotFound(String fullUrl, Exception e) {