Issue #3700 - Fixing bad ClasspathPatternTest assumptions

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-06-21 06:55:59 -05:00
parent 075333a627
commit 1118750139
2 changed files with 13 additions and 13 deletions

View File

@ -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;
}

View File

@ -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());