Class AntPatternFileCollector


  • public class AntPatternFileCollector
    extends java.lang.Object
    Since:
    8.1
    Author:
    Sergey.Pak Date: 6/24/13 Time: 7:19 PM
    • Constructor Detail

      • AntPatternFileCollector

        public AntPatternFileCollector()
    • Method Detail

      • scanDir

        public static java.util.List<java.io.File> scanDir​(@NotNull
                                                           java.io.File baseDir,
                                                           @NotNull
                                                           java.lang.String[] includeRules,
                                                           @NotNull
                                                           java.lang.String[] excludeRules,
                                                           @Nullable
                                                           AntPatternFileCollector.ScanOption[] options)

        Ant-style files collector (supports double-stars **).

        Rules:

        • Rules are applied in the order they were provided. As soon as file matches the first rule, no further rules will apply to it (like iptables in Linux).
        • Only files (File.isFile()==true) are collected
        • By default no rules at all results in no files are collected, but if there only exclude rules, all files except excluded ones will be collected

        Available options:

        • PRIORITIZE_EXCLUDES - exclude rules are applied first. Without this options rules are applied in the order they were submitted
        • USE_RULE_STRICTNESS - applies stricter rules first. Rule is considered stricter than other rule only if its match area always lays completely within other rules match area, for example a*ba.xml is stricter than a*ba.*, but not a*cba.*.
          Rules are compared by pairs. If it cannot be determined which one is stricter, rules are applied in the order they were supplied
        • INCLUDE_ALL_IF_NO_RULES - if no rules are provided all files under baseDir will be included into search results.
        • ALLOW_EXTERNAL_SCAN - Allows scan outside of baseDir. This option is required if you'd like to use rules like ..\*\*.txt. It is also required for absolute path rules
        • NOT_FOLLOW_SYMLINK_DIRS - while searching attempts to resolve symlink directories and if directory is a symlink - it will be skipped
        • MATCH_DIRECTORIES - matches directories and includes them into the result. This applies only to directories that match the rule(s) completely. Intermediate directories are not included.

        Parameters:
        baseDir - - directory to start scan from
        includeRules - - not null array of include rules. one string - one rule.
        excludeRules - - not null array of exclude rules. one string - one rule. Exclude rules apply first
        options - - nullable array of options. See above for details
        Returns:
        List of files that match search criteria
      • scanDir

        public static java.util.List<java.io.File> scanDir​(@NotNull
                                                           java.io.File baseDir,
                                                           @NotNull
                                                           java.lang.String[] rules,
                                                           @Nullable
                                                           AntPatternFileCollector.ScanOption[] options)

        Ant-style files collector (supports double-stars **).

        Rules:

        • Rules are applied in the order they were provided. As soon as file matches the first rule, no further rules will apply to it (like iptables in Linux).
        • Only files (File.isFile()==true) are collected
        • By default no rules at all results in no files are collected, but if there only exclude rules, all files except excluded ones will be collected

        Available options:

        • PRIORITIZE_EXCLUDES - exclude rules are applied first. Without this options rules are applied in the order they were submitted
        • USE_RULE_STRICTNESS - applies stricter rules first. Rule is considered stricter than other rule only if its match area always lays completely within other rules match area, for example a*ba.xml is stricter than a*ba.*, but not a*cba.*.
          Rules are compared by pairs. If it cannot be determined which one is stricter, rules are applied in the order they were supplied
        • INCLUDE_ALL_IF_NO_RULES - if no rules are provided all files under baseDir will be included into search results.
        • ALLOW_EXTERNAL_SCAN - Allows scan outside of baseDir. This option is required if you'd like to use rules like ..\*\*.txt. It is also required for absolute path rules
        • NOT_FOLLOW_SYMLINK_DIRS - while searching attempts to resolve symlink directories and if directory is a symlink - it will be skipped
        • MATCH_DIRECTORIES - matches directories and includes them into the result. This applies only to directories that match the rule(s) completely. Intermediate directories are not included.

        Parameters:
        baseDir - - directory to start scan from
        rules - - not null array of rules. one string - one rule.
        options - - nullable array of options. See above for details
        Returns:
        List of files that match search criteria
      • scanDirIteratively

        public static java.util.Iterator<java.io.File> scanDirIteratively​(@NotNull
                                                                          java.io.File baseDir,
                                                                          @NotNull
                                                                          java.lang.String[] rules,
                                                                          @Nullable
                                                                          AntPatternFileCollector.ScanOption[] options)
      • validate

        @Nullable
        public static java.lang.String validate​(@NotNull
                                                java.io.File baseDir,
                                                @NotNull
                                                java.lang.String[] includePatterns,
                                                @NotNull
                                                java.lang.String[] excludePatterns,
                                                @Nullable
                                                AntPatternFileCollector.ScanOption... options)

        Will not perform any scan. Will only check parameters returning error message if any.

        Parameters:
        includePatterns - - not null array of include rules. one string - one rule.
        excludePatterns - - not null array of exclude rules. one string - one rule. Exclude rules apply first
        options - - nullable array of options. See above for details
        Returns:
        Error if any, null if rules are applicable