From f27e4e727365ec12b5d0e46d883aaf56d53cd9c0 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 17 Oct 2022 15:16:39 -0500 Subject: [PATCH] Improved ClassMatcher/Location behavior. + Reduces need for Resource / ResourceFactory. + Corrected path equals logic --- .../jetty/ee10/webapp/ClassMatcher.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java index 1c9070226f0..e78527ffbbe 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/ClassMatcher.java @@ -13,6 +13,7 @@ package org.eclipse.jetty.ee10.webapp; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -36,7 +37,6 @@ import org.eclipse.jetty.util.Index; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.resource.ResourceFactory; /** * A matcher for classes based on package and/or location and/or module/ @@ -131,10 +131,11 @@ public class ClassMatcher extends AbstractSet protected LocationEntry(String name, boolean inclusive) { super(name, inclusive); - if (!getName().startsWith("file:")) - throw new IllegalArgumentException(name); + URI uri = URI.create(name); + if (!uri.isAbsolute() && !"file".equalsIgnoreCase(uri.getScheme())) + throw new IllegalArgumentException("Not a valid file URI: " + name); - _path = ResourceFactory.root().newResource(getName()).getPath(); + _path = Paths.get(uri); } public Path getPath() @@ -356,9 +357,21 @@ public class ClassMatcher extends AbstractSet } else { - if (path.equals(entryPath)) + try { - return true; + if (Files.isSameFile(path, entryPath)) + { + return true; + } + } + catch (IOException ignore) + { + // this means there is a FileSystem issue preventing comparison. + // Use old technique + if (path.equals(entryPath)) + { + return true; + } } } }