jodd.io.findfile
Class ClassFinder

java.lang.Object
  extended by jodd.io.findfile.ClassFinder
Direct Known Subclasses:
ClassScanner

public abstract class ClassFinder
extends java.lang.Object

Simple utility that scans URLs for classes. Its purpose is to help scanning class paths for some classes. Content of Jar files is also examined.

All paths are matched using path-style wildcard matcher. All entries are matched using common-style wildcard matcher.

See Also:
ClassScanner

Nested Class Summary
protected static class ClassFinder.EntryData
          Provides input stream on demand.
 
Field Summary
protected  java.lang.String[] excludedEntries
           
protected  java.lang.String[] excludedJars
          Array of excluded jars.
protected  boolean ignoreException
          If set to true exceptions for entry scans are ignored.
protected  java.lang.String[] includedEntries
           
protected  java.lang.String[] includedJars
          Array of jar file name patterns that are included in the search.
protected  boolean includeResources
          If set to true all files will be scanned and not only classes.
protected  java.lang.String[] systemJars
          Array of system jars that are excluded from the search.
 
Constructor Summary
ClassFinder()
           
 
Method Summary
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.
 java.lang.String[] getExcludedEntries()
           
 java.lang.String[] getExcludedJars()
           
 java.lang.String[] getIncludedEntries()
           
 java.lang.String[] getIncludedJars()
           
 java.lang.String[] getSystemJars()
           
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 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 setExcludedEntries(java.lang.String... excludedEntries)
          Sets excluded names that narrows included set of packages.
 void setExcludedJars(java.lang.String... excludedJars)
           
 void setIgnoreException(boolean ignoreException)
           
 void setIncludedEntries(java.lang.String... includedEntries)
          Sets included set of names that will be considered during configuration,
 void setIncludedJars(java.lang.String... includedJars)
           
 void setIncludeResources(boolean includeResources)
           
 void setSystemJars(java.lang.String[] systemJars)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

systemJars

protected java.lang.String[] systemJars
Array of system jars that are excluded from the search. By default it consists of java runtime libraries.


excludedJars

protected java.lang.String[] excludedJars
Array of excluded jars.


includedJars

protected java.lang.String[] includedJars
Array of jar file name patterns that are included in the search. This rule is applied after the excluded rule.


includedEntries

protected java.lang.String[] includedEntries

excludedEntries

protected java.lang.String[] excludedEntries

includeResources

protected boolean includeResources
If set to true all files will be scanned and not only classes.


ignoreException

protected boolean ignoreException
If set to true exceptions for entry scans are ignored.

Constructor Detail

ClassFinder

public ClassFinder()
Method Detail

getSystemJars

public java.lang.String[] getSystemJars()

setSystemJars

public void setSystemJars(java.lang.String[] systemJars)

getExcludedJars

public java.lang.String[] getExcludedJars()

setExcludedJars

public void setExcludedJars(java.lang.String... excludedJars)

getIncludedJars

public java.lang.String[] getIncludedJars()

setIncludedJars

public void setIncludedJars(java.lang.String... includedJars)

getIncludedEntries

public java.lang.String[] getIncludedEntries()

setIncludedEntries

public void setIncludedEntries(java.lang.String... includedEntries)
Sets included set of names that will be considered during configuration,


getExcludedEntries

public java.lang.String[] getExcludedEntries()

setExcludedEntries

public void setExcludedEntries(java.lang.String... excludedEntries)
Sets excluded names that narrows included set of packages.


isIncludeResources

public boolean isIncludeResources()

setIncludeResources

public void setIncludeResources(boolean includeResources)

isIgnoreException

public boolean isIgnoreException()

setIgnoreException

public void setIgnoreException(boolean ignoreException)

scanUrls

protected void scanUrls(java.net.URL... urls)
Scans several URLs. If (#ignoreExceptions} is set, exceptions per one URL will be ignored and loops continues.


scanUrl

protected void scanUrl(java.net.URL url)
Scans single URL for classes and jar files. Callback onEntry(EntryData) is called on each class name.


scanPaths

protected void scanPaths(java.io.File... paths)

scanPaths

protected void scanPaths(java.lang.String... paths)

scanPath

protected void scanPath(java.lang.String path)

acceptJar

protected boolean acceptJar(java.io.File jarFile)
Returns true if some JAR file has to be accepted.


scanPath

protected void scanPath(java.io.File file)
Scans single path.


scanJarFile

protected void scanJarFile(java.io.File file)
Scans classes inside single JAR archive. Archive is scanned as a zip file.

See Also:
onEntry(EntryData)

scanClassPath

protected void scanClassPath(java.io.File root)
Scans single classpath directory.

See Also:
onEntry(EntryData)

scanClassFile

protected void scanClassFile(java.lang.String filePath,
                             java.lang.String rootPath,
                             java.io.File file,
                             boolean isClass)

prepareEntryName

protected java.lang.String prepareEntryName(java.lang.String name,
                                            boolean isClass)
Prepares resource and class names. For classes, it strips '.class' from the end and converts all (back)slashes to dots. For resources, it replaces all backslashes to slashes.


acceptEntry

protected boolean acceptEntry(java.lang.String entryName)
Returns true if some entry name has to be accepted.

See Also:
prepareEntryName(String, boolean), scanEntry(EntryData)

scanEntry

protected void scanEntry(ClassFinder.EntryData entryData)
If entry name is accepted invokes onEntry(EntryData) a callback}.


onEntry

protected abstract void onEntry(ClassFinder.EntryData entryData)
                         throws java.lang.Exception
Called during classpath scanning when class or resource is found.
  • Class name is java-alike class name (pk1.pk2.class) that may be immediately used for dynamic loading.
  • Resource name starts with '\' and represents either jar path (\pk1/pk2/res) or relative file path (\pk1\pk2\res). 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.

    Throws:
    java.lang.Exception

  • getTypeSignatureBytes

    protected byte[] getTypeSignatureBytes(java.lang.Class type)
    Returns type signature bytes used for searching in class file.


    isTypeSignatureInUse

    protected boolean isTypeSignatureInUse(java.io.InputStream inputStream,
                                           byte[] bytes)
    Returns 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.



    Copyright © 2003-2012 Jodd Team