@Test public void testIdentifyClassFilesWithAntScannerWithListIncludesExcludes() { Map<String, Object> parameters = Maps.newHashMap(); parameters.put("baseDir", TEST_CLASSES_DIR); parameters.put("includes", Arrays.asList("***UtilTest.class")); parameters.put("excludes", Collections.singletonList("**/Java*.class")); List<File> files = FileNameUtil.identifyFiles(parameters); String aTestFileName = JarFileUtilTest.class.getCanonicalName().replaceAll("\\.", "/"); File aTestFile = new File(TEST_CLASSES_DIR + aTestFileName + ".class"); assertThat(files.contains(new File(aTestFile.getPath())), CoreMatchers.is(true)); String bTestFileName = ClassHandler.class.getCanonicalName().replaceAll("\\.", "/"); File bTestFile = new File(TEST_CLASSES_DIR + bTestFileName + ".class"); assertThat(files.contains(new File(bTestFile.getPath())), CoreMatchers.is(false)); }
public static List<File> identifyFiles(Map parameters) { String baseDir = (String) parameters.get("baseDir"); if (Strings.isNullOrEmpty(baseDir) || !new File(baseDir).exists()) { return new ArrayList<>(); } DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(baseDir); setIncludesExcludes(parameters.get("includes"), scanner::setIncludes); setIncludesExcludes(parameters.get("excludes"), scanner::setExcludes); scanner.setCaseSensitive(false); scanner.scan(); String[] files = scanner.getIncludedFiles(); return Arrays.stream(files) .map(filename -> new File(baseDir, filename)) .sorted(Comparator.comparing(File::getAbsolutePath)) .collect(Collectors.toList()); }
FileNameUtil { public static List<File> identifyFiles(Map parameters) { String baseDir = (String) parameters.get("baseDir"); if (Strings.isNullOrEmpty(baseDir) || !new File(baseDir).exists()) { return new ArrayList<>(); } DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(baseDir); setIncludesExcludes(parameters.get("includes"), scanner::setIncludes); setIncludesExcludes(parameters.get("excludes"), scanner::setExcludes); scanner.setCaseSensitive(false); scanner.scan(); String[] files = scanner.getIncludedFiles(); return Arrays.stream(files) .map(filename -> new File(baseDir, filename)) .sorted(Comparator.comparing(File::getAbsolutePath)) .collect(Collectors.toList()); } }
FileNameUtil { public static List<File> identifyFiles(Map parameters) { String baseDir = (String) parameters.get("baseDir"); if (Strings.isNullOrEmpty(baseDir) || !new File(baseDir).exists()) { return new ArrayList<>(); } DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(baseDir); setIncludesExcludes(parameters.get("includes"), scanner::setIncludes); setIncludesExcludes(parameters.get("excludes"), scanner::setExcludes); scanner.setCaseSensitive(false); scanner.scan(); String[] files = scanner.getIncludedFiles(); return Arrays.stream(files) .map(filename -> new File(baseDir, filename)) .sorted(Comparator.comparing(File::getAbsolutePath)) .collect(Collectors.toList()); } private  FileNameUtil(); }
FileNameUtil { public static List<File> identifyFiles(Map parameters) { String baseDir = (String) parameters.get("baseDir"); if (Strings.isNullOrEmpty(baseDir) || !new File(baseDir).exists()) { return new ArrayList<>(); } DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(baseDir); setIncludesExcludes(parameters.get("includes"), scanner::setIncludes); setIncludesExcludes(parameters.get("excludes"), scanner::setExcludes); scanner.setCaseSensitive(false); scanner.scan(); String[] files = scanner.getIncludedFiles(); return Arrays.stream(files) .map(filename -> new File(baseDir, filename)) .sorted(Comparator.comparing(File::getAbsolutePath)) .collect(Collectors.toList()); } private  FileNameUtil(); static List<File> identifyFiles(Map parameters); static boolean isIncluded(String name, Map parameters); static boolean matches(String name, List<String> patterns, boolean defaultValue); static boolean matches(String name, String pattern); static String getParentPath(String fileName); static String getCanonicalPath(String path); }
FileNameUtil { public static List<File> identifyFiles(Map parameters) { String baseDir = (String) parameters.get("baseDir"); if (Strings.isNullOrEmpty(baseDir) || !new File(baseDir).exists()) { return new ArrayList<>(); } DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(baseDir); setIncludesExcludes(parameters.get("includes"), scanner::setIncludes); setIncludesExcludes(parameters.get("excludes"), scanner::setExcludes); scanner.setCaseSensitive(false); scanner.scan(); String[] files = scanner.getIncludedFiles(); return Arrays.stream(files) .map(filename -> new File(baseDir, filename)) .sorted(Comparator.comparing(File::getAbsolutePath)) .collect(Collectors.toList()); } private  FileNameUtil(); static List<File> identifyFiles(Map parameters); static boolean isIncluded(String name, Map parameters); static boolean matches(String name, List<String> patterns, boolean defaultValue); static boolean matches(String name, String pattern); static String getParentPath(String fileName); static String getCanonicalPath(String path);  }