1 package jester; 2 3 import java.io.File ; 4 5 public class FileBasedClassIterator implements ClassIterator { 6 private Configuration myConfiguration; 7 private String [] myFileNames; 8 private Report myReport; 9 10 public FileBasedClassIterator(Configuration configuration, String [] fileNames, Report aReport) { 11 super(); 12 myConfiguration = configuration; 13 myFileNames = fileNames; myReport = aReport; 15 } 16 17 public void iterate(final ClassTestTester visitor) throws SourceChangeException { 18 final int[] numberOfFiles = new int[1]; 19 numberOfFiles[0] = 0; 20 FileVisitor fileCounter = new FileVisitor() { 21 public void visit(String fileName) { 22 if (fileName.endsWith(myConfiguration.sourceFileExtension())) { 23 numberOfFiles[0]++; 24 } 25 } 26 }; 27 for (int i = 0; i < myFileNames.length; i++) { 28 visitFileOrDirectory(myFileNames[i], fileCounter); 29 } 30 myReport.setNumberOfFilesThatWillBeTested(numberOfFiles[0]); 31 32 FileVisitor classTestVisitorWrapper = new FileVisitor() { 33 public void visit(String fileName) throws SourceChangeException { 34 if (fileName.endsWith(myConfiguration.sourceFileExtension())) { 35 ClassSourceCodeChanger sourceCodeSystem = new FileBasedClassSourceCodeChanger(myConfiguration, fileName, myReport); 36 visitor.testUsing(sourceCodeSystem); 37 } 38 } 39 }; 40 41 for (int i = 0; i < myFileNames.length; i++) { 42 visitFileOrDirectory(myFileNames[i], classTestVisitorWrapper); 43 } 44 } 45 46 private void visitFileOrDirectory(String fileName, FileVisitor visitor) throws SourceChangeException { 47 File file = new File (fileName); 48 if (file.isDirectory()) { 49 iterateForFilesInDirectory(file, visitor); 50 } else { 51 visitor.visit(fileName); 52 } 53 } 54 55 private void iterateForFilesInDirectory(File directory, FileVisitor visitor) throws SourceChangeException { 56 String [] fileNames = directory.list(); 57 for (int i = 0; i < fileNames.length; i++) { 58 String fileName = directory.getPath() + File.separator + fileNames[i]; 59 visitFileOrDirectory(fileName, visitor); 60 } 61 } 62 }
| Popular Tags
|