1 19 20 package org.netbeans.test.web; 21 22 import java.io.File ; 23 import java.io.FilenameFilter ; 24 import java.lang.reflect.Constructor ; 25 import java.util.Enumeration ; 26 import junit.framework.Test; 27 import org.netbeans.api.project.ProjectInformation; 28 import org.netbeans.api.project.ProjectUtils; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.junit.NbTestSuite; 31 import org.netbeans.junit.ide.ProjectSupport; 32 import org.netbeans.api.project.Project; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 36 37 41 public class RecurrentSuiteFactory { 42 private static boolean debug = true; 43 44 public static Test createSuite(Class clazz, File projectsDir, FileObjectFilter filter) { 45 String clazzName = clazz.getName(); 46 NbTestSuite suite = new NbTestSuite(clazzName); 47 try { 48 File [] projects = projectsDir.listFiles(new FilenameFilter () { 50 public boolean accept(File dir, String fileName) { 52 return !fileName.equals("CVS"); 53 } 54 }); 55 debug("RecurrentSuiteFactory"); 56 debug("Projects dir: " + projectsDir); 57 if (projects != null) { 58 for(int i = 0; i < projects.length; i++) { 59 debug("Prj Folder: " + projects[i].getName()); 60 Project project = (Project) ProjectSupport.openProject(projects[i]); 61 if (project == null) { 63 debug("WW: Not a project!!!"); 64 continue; 65 } 66 ProjectInformation projectInfo = ProjectUtils.getInformation(project); 67 70 74 FileObject prjDir = project.getProjectDirectory(); 75 Enumeration fileObjs = prjDir.getChildren(true); 76 77 while (fileObjs.hasMoreElements()) { 78 FileObject fo = (FileObject) fileObjs.nextElement(); 79 if (filter.accept(fo)) { 80 String testName = projectInfo.getName() + "_" 81 + FileUtil.getRelativePath(prjDir, fo).replaceAll("[/.]", "_"); 82 Constructor cnstr = clazz.getDeclaredConstructor(new Class [] {String .class, FileObject.class}); 83 NbTestCase test = (NbTestCase) cnstr.newInstance(new Object [] {testName, fo}); 84 suite.addTest(test); 85 } 86 } 87 } 88 } 89 } catch (Exception ex) { 90 ex.printStackTrace(System.out); 91 } 92 return suite; 93 } 94 95 private static void debug(Object msg) { 96 if (!debug) return; 97 System.err.println("[debug] " + msg); 98 } 99 } 100 | Popular Tags |