1 package org.springframework.beans; 2 3 import java.io.File; 4 import java.io.FileFilter; 5 import java.io.IOException; 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class ProblemFileDetector { 10 public List<File> getProblemFiles(ProblemFileContext context) throws IOException { 11 File baseDir = context.getBaseDir(); 12 FileFilter exclude = context.getExclude(); 13 FileFilter include = context.getInclude(); 14 FileFilter problem = context.getProblem(); 15 List<File> files = getFiles(baseDir, exclude, include); 16 System.out.println("Located " + files.size() + " total files"); 17 List<File> problemFiles = getProblemFiles(files, problem); 18 return problemFiles; 19 } 20 21 protected List<File> getProblemFiles(List<File> files, FileFilter problem) throws IOException { 22 List<File> problemFiles = new ArrayList<File>(); 23 for (File file : files) { 24 if (problem.accept(file)) { 25 problemFiles.add(file); 26 } 27 } 28 return problemFiles; 29 } 30 31 protected List<File> getFiles(File dir, FileFilter exclude, FileFilter include) { 32 File[] contents = dir.listFiles(); 33 List<File> files = new ArrayList<File>(); 34 for (File file : contents) { 35 if (!exclude.accept(file)) { 36 continue; 37 } 38 if (file.isDirectory()) { 39 files.addAll(getFiles(file, exclude, include)); 40 } else { 41 if (include.accept(file)) { 42 files.add(file); 43 } 44 } 45 } 46 return files; 47 } 48 }