Package picard.cmdline
Class ClassFinder
- java.lang.Object
-
- picard.cmdline.ClassFinder
-
public class ClassFinder extends Object
Utility class that can scan for classes in the classpath and find all the ones annotated with a particular annotation.
-
-
Constructor Summary
Constructors Constructor Description ClassFinder()
ClassFinder(File jarFile)
ClassFinder(ClassLoader loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
find(String packageName, Class<?> parentType)
Scans the classpath for classes within the specified package and sub-packages that extend the parentType.Set<Class<?>>
getClasses()
Fetches the set of classes discovered so far.protected void
handleItem(String name)
Checks an item to see if it is a class and is annotated with the specified annotation.protected void
scanDir(File file, String path)
Scans a directory on the filesystem for classes.protected void
scanJar(File file, String packagePath)
Scans the entries in a ZIP/JAR file for classes under the parent package.String
toClassName(String filename)
Convert a filename to a class name by removing '.class' and converting '/'s to '.'s.
-
-
-
Constructor Detail
-
ClassFinder
public ClassFinder()
-
ClassFinder
public ClassFinder(ClassLoader loader)
-
ClassFinder
public ClassFinder(File jarFile) throws IOException
- Throws:
IOException
-
-
Method Detail
-
toClassName
public String toClassName(String filename)
Convert a filename to a class name by removing '.class' and converting '/'s to '.'s.
-
find
public void find(String packageName, Class<?> parentType)
Scans the classpath for classes within the specified package and sub-packages that extend the parentType. This method can be called repeatedly with different packages. Classes are accumulated internally and can be accessed by callinggetClasses()
.
-
scanJar
protected void scanJar(File file, String packagePath) throws IOException
Scans the entries in a ZIP/JAR file for classes under the parent package.- Parameters:
file
- the jar file to be scannedpackagePath
- the top level package to start from- Throws:
IOException
-
scanDir
protected void scanDir(File file, String path)
Scans a directory on the filesystem for classes.- Parameters:
file
- the directory or file to examinepath
- the package path acculmulated so far (e.g. edu/mit/broad)
-
handleItem
protected void handleItem(String name)
Checks an item to see if it is a class and is annotated with the specified annotation. If so, adds it to the set, otherwise ignores it.- Parameters:
name
- the path equivelant to the package + class/item name
-
-