java.lang.Object
org.matwoess.jsourceprofiler.tool.cli.FileCollector

public class FileCollector extends Object
Collects files with a specific file extension from a directory and its subdirectories.

The collected files can be filtered by excluding specific file names and paths. Whether to include hidden directories can be specified.

  • Constructor Details

    • FileCollector

      public FileCollector(Path baseDir, String fileExtension, boolean excludeHiddenDirs)
      Creates a new FileCollector for the given base directory and file extension.

      The file extension is case-insensitive and should not contain a leading dot.

      Parameters:
      baseDir - the base directory to start the search from
      fileExtension - the file extension to collect files for
      excludeHiddenDirs - whether to exclude hidden directories from the search
  • Method Details

    • excludeFileName

      public FileCollector excludeFileName(String fileName)
      Adds a file name to the list of exclusions.
      Parameters:
      fileName - the file name to exclude
      Returns:
      this FileCollector instance
    • excludePath

      public FileCollector excludePath(Path exclusion)
      Adds a path to the list of exclusions.
      Parameters:
      exclusion - the path to exclude
      Returns:
      this FileCollector instance
    • collect

      public List<Path> collect()
      Collects the files from the base directory and its subdirectories using Files.walkFileTree and a custom visitor. The collected files are filtered by the file extension and the exclusion lists. Hidden directory tree paths are excluded if specified.
      Returns:
      a list of paths to the collected files