Package org.eclipse.jetty.webapp
Class ClasspathPattern
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<java.lang.String>
-
- org.eclipse.jetty.webapp.ClasspathPattern
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
,java.util.Collection<java.lang.String>
,java.util.Set<java.lang.String>
public class ClasspathPattern extends java.util.AbstractSet<java.lang.String>
Classpath classes list performs pattern matching of a class name against an internal array of classpath pattern entries. A class pattern is a string of one of the forms:- 'org.package.SomeClass' will match a specific class
- 'org.package.' will match a specific package hierarchy
- 'org.package.SomeClass$NestedClass ' will match a nested class exactly otherwise. Nested classes are matched by their containing class. (eg. org.example.MyClass matches org.example.MyClass$AnyNestedClass)
- 'file:///some/location/' - A file system directory from which the class was loaded
- 'file:///some/location.jar' - The URI of a jar file from which the class was loaded
- 'jrt:/modulename' - A Java9 module name
- Any of the above patterns preceded by '-' will exclude rather than include the match.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClasspathPattern.ByClass
static class
ClasspathPattern.ByLocation
static class
ClasspathPattern.ByLocationOrModule
static class
ClasspathPattern.ByModule
static class
ClasspathPattern.ByPackage
static class
ClasspathPattern.ByPackageOrName
private static class
ClasspathPattern.ClassEntry
(package private) static class
ClasspathPattern.Entry
private static class
ClasspathPattern.LocationEntry
private static class
ClasspathPattern.ModuleEntry
private static class
ClasspathPattern.PackageEntry
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,ClasspathPattern.Entry>
_entries
(package private) IncludeExcludeSet<ClasspathPattern.Entry,java.net.URI>
_locations
(package private) IncludeExcludeSet<ClasspathPattern.Entry,java.lang.String>
_packageOrNamePatterns
-
Constructor Summary
Constructors Constructor Description ClasspathPattern()
ClasspathPattern(java.lang.String pattern)
ClasspathPattern(java.lang.String[] patterns)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(java.lang.String pattern)
boolean
add(java.lang.String... pattern)
protected boolean
add(ClasspathPattern.Entry entry)
private void
addAll(java.lang.String[] classes)
void
clear()
(package private) static boolean
combine(IncludeExcludeSet<ClasspathPattern.Entry,java.lang.String> names, java.lang.String name, IncludeExcludeSet<ClasspathPattern.Entry,java.net.URI> locations, java.util.function.Supplier<java.net.URI> location)
Match a class against inclusions and exclusions by name and location.boolean
exclude(java.lang.String name)
boolean
exclude(java.lang.String... name)
java.lang.String[]
getPatterns()
boolean
include(java.lang.String name)
boolean
include(java.lang.String... name)
java.util.Iterator<java.lang.String>
iterator()
boolean
match(java.lang.Class<?> clazz)
Match the class name against the patternboolean
match(java.lang.String name)
Match the class name against the patternboolean
match(java.lang.String name, java.net.URL url)
protected ClasspathPattern.Entry
newEntry(java.lang.String pattern)
protected ClasspathPattern.Entry
newEntry(java.lang.String name, boolean inclusive)
boolean
remove(java.lang.Object o)
private void
setAll(java.lang.String[] classes)
Initialize the matcher by parsing each classpath pattern in an arrayint
size()
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
-
-
-
-
Field Detail
-
_entries
java.util.Map<java.lang.String,ClasspathPattern.Entry> _entries
-
_packageOrNamePatterns
IncludeExcludeSet<ClasspathPattern.Entry,java.lang.String> _packageOrNamePatterns
-
_locations
IncludeExcludeSet<ClasspathPattern.Entry,java.net.URI> _locations
-
-
Method Detail
-
include
public boolean include(java.lang.String name)
-
include
public boolean include(java.lang.String... name)
-
exclude
public boolean exclude(java.lang.String name)
-
exclude
public boolean exclude(java.lang.String... name)
-
add
public boolean add(java.lang.String pattern)
- Specified by:
add
in interfacejava.util.Collection<java.lang.String>
- Specified by:
add
in interfacejava.util.Set<java.lang.String>
- Overrides:
add
in classjava.util.AbstractCollection<java.lang.String>
-
add
public boolean add(java.lang.String... pattern)
-
newEntry
protected ClasspathPattern.Entry newEntry(java.lang.String pattern)
-
newEntry
protected ClasspathPattern.Entry newEntry(java.lang.String name, boolean inclusive)
-
add
protected boolean add(ClasspathPattern.Entry entry)
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<java.lang.String>
- Specified by:
remove
in interfacejava.util.Set<java.lang.String>
- Overrides:
remove
in classjava.util.AbstractCollection<java.lang.String>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<java.lang.String>
- Specified by:
clear
in interfacejava.util.Set<java.lang.String>
- Overrides:
clear
in classjava.util.AbstractCollection<java.lang.String>
-
iterator
public java.util.Iterator<java.lang.String> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<java.lang.String>
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.String>
- Specified by:
iterator
in interfacejava.util.Set<java.lang.String>
- Specified by:
iterator
in classjava.util.AbstractCollection<java.lang.String>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<java.lang.String>
- Specified by:
size
in interfacejava.util.Set<java.lang.String>
- Specified by:
size
in classjava.util.AbstractCollection<java.lang.String>
-
setAll
private void setAll(java.lang.String[] classes)
Initialize the matcher by parsing each classpath pattern in an array- Parameters:
classes
- array of classpath patterns
-
addAll
private void addAll(java.lang.String[] classes)
- Parameters:
classes
- array of classpath patterns
-
getPatterns
public java.lang.String[] getPatterns()
- Returns:
- array of classpath patterns
-
match
public boolean match(java.lang.String name)
Match the class name against the pattern- Parameters:
name
- name of the class to match- Returns:
- true if class matches the pattern
-
match
public boolean match(java.lang.Class<?> clazz)
Match the class name against the pattern- Parameters:
clazz
- A class to try to match- Returns:
- true if class matches the pattern
-
match
public boolean match(java.lang.String name, java.net.URL url)
-
combine
static boolean combine(IncludeExcludeSet<ClasspathPattern.Entry,java.lang.String> names, java.lang.String name, IncludeExcludeSet<ClasspathPattern.Entry,java.net.URI> locations, java.util.function.Supplier<java.net.URI> location)
Match a class against inclusions and exclusions by name and location. Name based checks are performed before location checks. For a class to match, it must not be excluded by either name or location, and must either be explicitly included, or for there to be no inclusions. In the case where the location of the class is null, it will match if it is included by name, or if there are no location exclusions.- Parameters:
names
- configured inclusions and exclusions by namename
- the name to checklocations
- configured inclusions and exclusions by locationlocation
- the location of the class (can be null)- Returns:
- true if the class is not excluded but is included, or there are no inclusions. False otherwise.
-
-