public abstract class ClassFinder
extends java.lang.Object
URLs for classes.
Its purpose is to help scanning class paths for some classes.
Content of Jar files is also examined.
Scanning starts in included all mode (blacklist mode) for both jars and lists. User can set explicit excludes. Of course, mode can be changed.
All paths are matched using path-style
wildcard matcher. All entries are matched using Wildcard.match(CharSequence, CharSequence) common-style}
wildcard matcher.
ClassScanner| Modifier and Type | Class and Description |
|---|---|
protected static class |
ClassFinder.EntryData
Provides input stream on demand.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
ignoreException
If set to
true exceptions for entry scans are ignored. |
protected boolean |
includeResources
If set to
true all files will be scanned and not only classes. |
protected InExRules<java.lang.String,java.lang.String> |
rulesEntries |
protected InExRules<java.lang.String,java.lang.String> |
rulesJars |
protected static java.lang.String[] |
systemJars
Array of system jars that are excluded from the search.
|
| Constructor and Description |
|---|
ClassFinder() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acceptEntry(java.lang.String entryName)
Returns
true if some entry name has to be accepted. |
protected boolean |
acceptJar(java.io.File jarFile)
Returns
true if some JAR file has to be accepted. |
protected InExRules<java.lang.String,java.lang.String> |
createEntriesRules() |
protected InExRules<java.lang.String,java.lang.String> |
createJarRules()
Creates JAR rules.
|
static java.lang.String[] |
getSystemJars()
Returns system jars.
|
protected byte[] |
getTypeSignatureBytes(java.lang.Class type)
Returns type signature bytes used for searching in class file.
|
boolean |
isIgnoreException() |
boolean |
isIncludeResources() |
protected boolean |
isTypeSignatureInUse(java.io.InputStream inputStream,
byte[] bytes)
Returns
true if class contains type signature. |
protected java.lang.Class |
loadClass(java.lang.String className)
Loads class by its name.
|
protected abstract void |
onEntry(ClassFinder.EntryData entryData)
Called during classpath scanning when class or resource is found.
|
protected java.lang.String |
prepareEntryName(java.lang.String name,
boolean isClass)
Prepares resource and class names.
|
protected void |
scanClassFile(java.lang.String filePath,
java.lang.String rootPath,
java.io.File file,
boolean isClass) |
protected void |
scanClassPath(java.io.File root)
Scans single classpath directory.
|
protected void |
scanEntry(ClassFinder.EntryData entryData)
If entry name is
accepted invokes onEntry(EntryData) a callback}. |
protected void |
scanJarFile(java.io.File file)
Scans classes inside single JAR archive.
|
protected void |
scanPath(java.io.File file)
Scans single path.
|
protected void |
scanPath(java.lang.String path) |
protected void |
scanPaths(java.io.File... paths) |
protected void |
scanPaths(java.lang.String... paths) |
protected void |
scanUrl(java.net.URL url)
Scans single URL for classes and jar files.
|
protected void |
scanUrls(java.net.URL... urls)
Scans several URLs.
|
void |
setExcludeAllEntries(boolean whitelist)
Sets white/black list mode for entries.
|
void |
setExcludeAllJars(boolean whitelist)
Sets white/black list mode for jars.
|
void |
setExcludedEntries(java.lang.String... excludedEntries)
Sets excluded names that narrows included set of packages.
|
void |
setExcludedJars(java.lang.String... excludedJars)
Specify excluded jars.
|
void |
setIgnoreException(boolean ignoreException)
Sets if exceptions during scanning process should be ignored or not.
|
void |
setIncludeAllEntries(boolean blacklist)
Sets white/black list mode for entries.
|
void |
setIncludeAllJars(boolean blacklist)
Sets white/black list mode for jars.
|
void |
setIncludedEntries(java.lang.String... includedEntries)
Sets included set of names that will be considered during configuration.
|
void |
setIncludedJars(java.lang.String... includedJars)
Specify included jars.
|
void |
setIncludeResources(boolean includeResources) |
protected static java.lang.String[] systemJars
protected final InExRules<java.lang.String,java.lang.String> rulesJars
protected final InExRules<java.lang.String,java.lang.String> rulesEntries
protected boolean includeResources
true all files will be scanned and not only classes.protected boolean ignoreException
true exceptions for entry scans are ignored.protected InExRules<java.lang.String,java.lang.String> createJarRules()
public static java.lang.String[] getSystemJars()
public void setExcludedJars(java.lang.String... excludedJars)
public void setIncludedJars(java.lang.String... includedJars)
public void setIncludeAllJars(boolean blacklist)
public void setExcludeAllJars(boolean whitelist)
protected InExRules<java.lang.String,java.lang.String> createEntriesRules()
public void setIncludedEntries(java.lang.String... includedEntries)
InExRulespublic void setIncludeAllEntries(boolean blacklist)
public void setExcludeAllEntries(boolean whitelist)
public void setExcludedEntries(java.lang.String... excludedEntries)
InExRulespublic boolean isIncludeResources()
public void setIncludeResources(boolean includeResources)
public boolean isIgnoreException()
public void setIgnoreException(boolean ignoreException)
protected void scanUrls(java.net.URL... urls)
protected void scanUrl(java.net.URL url)
onEntry(EntryData) is called on
each class name.protected void scanPaths(java.io.File... paths)
protected void scanPaths(java.lang.String... paths)
protected void scanPath(java.lang.String path)
protected boolean acceptJar(java.io.File jarFile)
true if some JAR file has to be accepted.protected void scanPath(java.io.File file)
protected void scanJarFile(java.io.File file)
onEntry(EntryData)protected void scanClassPath(java.io.File root)
onEntry(EntryData)protected void scanClassFile(java.lang.String filePath,
java.lang.String rootPath,
java.io.File file,
boolean isClass)
protected java.lang.String prepareEntryName(java.lang.String name,
boolean isClass)
protected boolean acceptEntry(java.lang.String entryName)
true if some entry name has to be accepted.protected void scanEntry(ClassFinder.EntryData entryData)
accepted invokes onEntry(EntryData) a callback}.protected abstract void onEntry(ClassFinder.EntryData entryData) throws java.lang.Exception
InputStream is provided by InputStreamProvider and opened lazy.
Once opened, input stream doesn't have to be closed - this is done by this class anyway.java.lang.Exceptionprotected byte[] getTypeSignatureBytes(java.lang.Class type)
protected boolean isTypeSignatureInUse(java.io.InputStream inputStream,
byte[] bytes)
true if class contains type signature.
It searches the class content for bytecode signature. This is the fastest way of finding if come
class uses some type. Please note that if signature exists it still doesn't means that class uses
it in expected way, therefore, class should be loaded to complete the scan.protected java.lang.Class loadClass(java.lang.String className)
throws java.lang.ClassNotFoundException
ignoreException is set,
no exception is thrown, but null is returned.java.lang.ClassNotFoundExceptionCopyright © 2003-2013 Jodd Team