469384 ClasspathPattern handles nested classes
Bug: 469384 Treat classnames with $ in them as exact match or exact prefix
This commit is contained in:
parent
1a572c3236
commit
f9a3bdab2a
|
@ -25,6 +25,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Classpath classes list performs sequential pattern matching of a class name
|
* Classpath classes list performs sequential pattern matching of a class name
|
||||||
|
@ -216,48 +218,27 @@ public class ClasspathPattern extends AbstractList<String>
|
||||||
*/
|
*/
|
||||||
public boolean match(String name)
|
public boolean match(String name)
|
||||||
{
|
{
|
||||||
boolean result=false;
|
name = name.replace('/','.');
|
||||||
|
|
||||||
if (_entries != null)
|
for (Entry entry : _entries)
|
||||||
{
|
{
|
||||||
name = name.replace('/','.');
|
if (entry==null)
|
||||||
|
continue;
|
||||||
int startIndex = 0;
|
if (entry._package)
|
||||||
|
|
||||||
while(startIndex < name.length() && name.charAt(startIndex) == '.') {
|
|
||||||
startIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dollar = name.indexOf("$");
|
|
||||||
|
|
||||||
int endIndex = dollar != -1 ? dollar : name.length();
|
|
||||||
|
|
||||||
for (Entry entry : _entries)
|
|
||||||
{
|
{
|
||||||
if (entry != null)
|
if (name.startsWith(entry._name))
|
||||||
{
|
return entry._inclusive;
|
||||||
if (entry._package)
|
}
|
||||||
{
|
else
|
||||||
if (name.regionMatches(startIndex, entry._name, 0, entry._name.length()))
|
{
|
||||||
{
|
if (name.equals(entry._name))
|
||||||
result = entry._inclusive;
|
return entry._inclusive;
|
||||||
break;
|
|
||||||
}
|
if (name.length()>entry._name.length() && '$'==name.charAt(entry._name.length()) && name.startsWith(entry._name))
|
||||||
}
|
return entry._inclusive;
|
||||||
else
|
|
||||||
{
|
|
||||||
int regionLength = endIndex-startIndex;
|
|
||||||
if (regionLength == entry._name.length()
|
|
||||||
&& name.regionMatches(startIndex, entry._name, 0, regionLength))
|
|
||||||
{
|
|
||||||
result = entry._inclusive;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAfter(String afterPattern,String... patterns)
|
public void addAfter(String afterPattern,String... patterns)
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.webapp;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ClasspathPatternTest
|
||||||
|
{
|
||||||
|
private final ClasspathPattern pattern = new ClasspathPattern();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before()
|
||||||
|
{
|
||||||
|
pattern.clear();
|
||||||
|
pattern.add("org.package.");
|
||||||
|
pattern.add("-org.excluded.");
|
||||||
|
pattern.add("org.example.FooBar");
|
||||||
|
pattern.add("-org.example.Excluded");
|
||||||
|
pattern.addAll(Arrays.asList(new String[]{"-org.example.Nested$Minus","org.example.Nested","org.example.Nested$Something"}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClassMatch()
|
||||||
|
{
|
||||||
|
assertTrue(pattern.match("org.example.FooBar"));
|
||||||
|
assertTrue(pattern.match("org.example.Nested"));
|
||||||
|
|
||||||
|
assertFalse(pattern.match("org.example.Unknown"));
|
||||||
|
assertFalse(pattern.match("org.example.FooBar.Unknown"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPackageMatch()
|
||||||
|
{
|
||||||
|
assertTrue(pattern.match("org.package.Something"));
|
||||||
|
assertTrue(pattern.match("org.package.other.Something"));
|
||||||
|
|
||||||
|
assertFalse(pattern.match("org.example.Unknown"));
|
||||||
|
assertFalse(pattern.match("org.example.FooBar.Unknown"));
|
||||||
|
assertFalse(pattern.match("org.example.FooBarElse"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExplicitNestedMatch()
|
||||||
|
{
|
||||||
|
assertTrue(pattern.match("org.example.Nested$Something"));
|
||||||
|
|
||||||
|
assertFalse(pattern.match("org.example.Nested$Minus"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImplicitNestedMatch()
|
||||||
|
{
|
||||||
|
assertTrue(pattern.match("org.example.FooBar$Other"));
|
||||||
|
assertTrue(pattern.match("org.example.Nested$Other"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddBefore()
|
||||||
|
{
|
||||||
|
pattern.addBefore("-org.excluded.","org.excluded.ExceptionOne","org.excluded.ExceptionTwo");
|
||||||
|
|
||||||
|
assertTrue(pattern.match("org.excluded.ExceptionOne"));
|
||||||
|
assertTrue(pattern.match("org.excluded.ExceptionTwo"));
|
||||||
|
|
||||||
|
assertFalse(pattern.match("org.example.Unknown"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddAfter()
|
||||||
|
{
|
||||||
|
pattern.addAfter("org.package.","org.excluded.ExceptionOne","org.excluded.ExceptionTwo");
|
||||||
|
|
||||||
|
assertTrue(pattern.match("org.excluded.ExceptionOne"));
|
||||||
|
assertTrue(pattern.match("org.excluded.ExceptionTwo"));
|
||||||
|
|
||||||
|
assertFalse(pattern.match("org.example.Unknown"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDoubledNested()
|
||||||
|
{
|
||||||
|
assertTrue(pattern.match("org.example.Nested$Something$Else"));
|
||||||
|
|
||||||
|
assertFalse(pattern.match("org.example.Nested$Minus$Else"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue