1 19 20 package org.netbeans.test.jsf.el; 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 System.out.println(fo.getName()); 80 if (filter.accept(fo)) { 81 String testName = projectInfo.getName() + "_" 82 + FileUtil.getRelativePath(prjDir, fo).replaceAll("[/.]", "_"); 83 Constructor cnstr = clazz.getDeclaredConstructor(new Class [] {String .class, FileObject.class}); 84 NbTestCase test = (NbTestCase) cnstr.newInstance(new Object [] {testName, fo}); 85 suite.addTest(test); 86 } 87 } 88 } 89 } 90 } catch (Exception ex) { 91 ex.printStackTrace(System.out); 92 } 93 return suite; 94 } 95 96 private static void debug(Object msg) { 97 if (!debug) return; 98 System.err.println("[debug] " + msg); 99 } 100 } 101 | Popular Tags |