001    package org.springframework.beans;
002    
003    import java.io.File;
004    import java.io.FileFilter;
005    import java.io.IOException;
006    import java.util.ArrayList;
007    import java.util.List;
008    
009    public class ProblemFileDetector {
010        public List<File> getProblemFiles(ProblemFileContext context) throws IOException {
011            File baseDir = context.getBaseDir();
012            FileFilter exclude = context.getExclude();
013            FileFilter include = context.getInclude();
014            FileFilter problem = context.getProblem();
015            List<File> files = getFiles(baseDir, exclude, include);
016            System.out.println("Located " + files.size() + " total files");
017            List<File> problemFiles = getProblemFiles(files, problem);
018            return problemFiles;
019        }
020    
021        protected List<File> getProblemFiles(List<File> files, FileFilter problem) throws IOException {
022            List<File> problemFiles = new ArrayList<File>();
023            for (File file : files) {
024                if (problem.accept(file)) {
025                    problemFiles.add(file);
026                }
027            }
028            return problemFiles;
029        }
030    
031        protected List<File> getFiles(File dir, FileFilter exclude, FileFilter include) {
032            File[] contents = dir.listFiles();
033            List<File> files = new ArrayList<File>();
034            for (File file : contents) {
035                if (!exclude.accept(file)) {
036                    continue;
037                }
038                if (file.isDirectory()) {
039                    files.addAll(getFiles(file, exclude, include));
040                } else {
041                    if (include.accept(file)) {
042                        files.add(file);
043                    }
044                }
045            }
046            return files;
047        }
048    }