From 1118750139b3200006274ab855e8680aec3d21af Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 21 Jun 2019 06:55:59 -0500 Subject: [PATCH] Issue #3700 - Fixing bad ClasspathPatternTest assumptions Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/util/TypeUtil.java | 10 +++++++--- .../jetty/webapp/ClasspathPatternTest.java | 16 ++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index 24a4f4414b1..f4e63fc2e40 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -684,10 +684,14 @@ public class TypeUtil { URI uri = url.toURI(); String uriStr = uri.toASCIIString(); - int idx = uriStr.indexOf(".jar!/"); - if (idx > 0) + if(uriStr.startsWith("jar:file:")) { - return URI.create(uriStr.substring(0, idx + 4)); + uriStr = uriStr.substring(4); + int idx = uriStr.indexOf("!/"); + if (idx > 0) + { + return URI.create(uriStr.substring(0, idx)); + } } return uri; } diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java index 117d553deda..735fb446a1a 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java @@ -18,12 +18,7 @@ package org.eclipse.jetty.webapp; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.net.URI; -import java.nio.file.Paths; import java.util.Arrays; import org.eclipse.jetty.util.TypeUtil; @@ -34,6 +29,10 @@ import org.junit.jupiter.api.condition.DisabledOnJre; import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.JRE; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class ClasspathPatternTest { private final ClasspathPattern _pattern = new ClasspathPattern(); @@ -122,15 +121,12 @@ public class ClasspathPatternTest { // jar from JVM classloader URI loc_string = TypeUtil.getLocationOfClass(String.class); - // System.err.println(loc_string); // a jar from maven repo jar URI loc_junit = TypeUtil.getLocationOfClass(Test.class); - // System.err.println(loc_junit); // class file URI loc_test = TypeUtil.getLocationOfClass(ClasspathPatternTest.class); - // System.err.println(loc_test); ClasspathPattern pattern = new ClasspathPattern(); pattern.include("something"); @@ -139,7 +135,7 @@ public class ClasspathPatternTest assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(false)); // Add directory for both JVM classes - pattern.include(Paths.get(loc_string).getParent().toUri().toString()); + pattern.include(loc_string.toASCIIString()); // Add jar for individual class and classes directory pattern.include(loc_junit.toString(), loc_test.toString()); @@ -220,7 +216,7 @@ public class ClasspathPatternTest assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); // Add directory for both JVM classes - pattern.exclude(Paths.get(loc_string).getParent().toUri().toString()); + pattern.exclude(loc_string.toString()); // Add jar for individual class and classes directory pattern.exclude(loc_junit.toString(), loc_test.toString());