Class ClassPathScanner

  • All Implemented Interfaces:
    Scanner

    public class ClassPathScanner
    extends Object
    implements Scanner
    Scan classpath for a directory and visits each file.

    Thread context classloader is used to scan.

    Author:
    Jiri Bubnik
    • Constructor Detail

      • ClassPathScanner

        public ClassPathScanner()
    • Method Detail

      • scan

        public void scan​(ClassLoader classLoader,
                         String path,
                         ScannerVisitor visitor)
                  throws IOException
        Description copied from interface: Scanner
        Scan all directories matching path (there might be multiple locations on classpath, JAR directory, ...) and call visitor for each found file.
        Specified by:
        scan in interface Scanner
        Parameters:
        classLoader - classloader to resolve path
        path - a '/'-separated path name that identifies the resource directory. Semantics same as ClassLoader.getResources(java.lang.String).
        visitor - visit each file on the path
        Throws:
        IOException - any IO exception while scanning
      • scanDirectory

        protected void scanDirectory​(File pluginDir,
                                     ScannerVisitor visitor)
                              throws IOException
        Recursively scan the directory.
        Parameters:
        pluginDir - directory.
        visitor - callback
        Throws:
        IOException - exception from a visitor
      • toURI

        public static URI toURI​(String location)
                         throws URISyntaxException
        Create a URI instance for the given location String, replacing spaces with "%20" quotes first.
        Parameters:
        location - the location String to convert into a URI instance
        Returns:
        the URI instance
        Throws:
        URISyntaxException - if the location wasn't a valid URI