This is an automated email from the ASF dual-hosted git repository.
elharo 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 f848837 Breah dependency on org.apache.http (#441)
f848837 is described below
commit f848837d8ba6cc900512f338c4e3b4ff2918f84b
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sun Jan 25 17:40:32 2026 +0000
Breah dependency on org.apache.http (#441)
---
.../buildcache/RemoteCacheRepositoryImpl.java | 30 ++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git
a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
index 8d884cd..9d18350 100644
--- a/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
+++ b/src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java
@@ -25,6 +25,7 @@
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;
@@ -33,8 +34,6 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.HttpResponseException;
import org.apache.maven.SessionScoped;
import org.apache.maven.buildcache.checksum.MavenProjectInput;
import org.apache.maven.buildcache.xml.Build;
@@ -161,9 +160,7 @@ public Optional<byte[]> getResourceContent(String url) {
} 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 ((e instanceof HttpResponseException
- ||
e.getClass().getName().equals(HttpResponseException.class.getName()))
- && getStatusCode(e) == HttpStatus.SC_NOT_FOUND) {
+ if (isHttpResponseException(e) && getStatusCode(e) == 404) {
logNotFound(fullUrl, e);
return Optional.empty();
}
@@ -177,7 +174,20 @@ && getStatusCode(e) == HttpStatus.SC_NOT_FOUND) {
}
}
- private int getStatusCode(Exception ex) {
+ private boolean isHttpResponseException(Exception ex) {
+ Class<?> currentClass = ex.getClass();
+
+ while (currentClass != null) {
+ if
("org.apache.http.client.HttpResponseException".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
@@ -185,10 +195,10 @@ private int getStatusCode(Exception ex) {
// org.codehaus.plexus.classworlds.realm.ClassRealm @23cd4ff2;
//
try {
- Method method = ex.getClass().getMethod("getStatusCode");
- return (int) method.invoke(ex);
- } catch (Throwable t) {
- LOGGER.debug(t.getMessage(), t);
+ Method method = exception.getClass().getMethod("getStatusCode");
+ return (int) method.invoke(exception);
+ } catch (NoSuchMethodException | IllegalAccessException |
InvocationTargetException | RuntimeException ex) {
+ LOGGER.debug(ex.getMessage(), ex);
return 0;
}
}