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 Details

  • Method Details

    • 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 calling getClasses().
    • 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 scanned
      packagePath - 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 examine
      path - 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
    • getClasses

      public Set<Class<?>> getClasses()
      Fetches the set of classes discovered so far.