Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/backend/processing/ProjectsValidator.java

Go to the documentation of this file.
00001 
00021 package m2m.backend.processing;
00022 
00023 import java.io.File;
00024 import java.util.Vector;
00025 
00026 import m2m.backend.octaveparser.ParsingException;
00027 import m2m.backend.project.M2MProject;
00028 
00033 public class ProjectsValidator {
00034         
00035 
00036         private static void testDirInternal(String dir,Vector<String> errors) {
00037 
00038                 File dirFile = new File(dir);
00039                 File[] files = dirFile.listFiles();
00040                                 
00041                 for (int i = 0; i < files.length; i++) {
00042                         if (files[i].isDirectory()) {
00043                                 testDirInternal(files[i].getAbsolutePath(),errors);
00044                         }
00045                         else {
00046                                 File file=files[i];
00047                                 // get the file extension
00048                             String ext = (file.getName().lastIndexOf(".") == -1 ? "" :
00049                             file.getName().substring(file.getName().lastIndexOf(".")+1, file.getName().length()));
00050                                         
00051                             // if it is a m2m project file (*.m2m), create the corresponding class to extract information
00052                                 if (ext.equalsIgnoreCase("m2m")) {
00053                                         if (file.exists()) {
00054                                                 System.out.println("********************************************************************************");
00055                                                 System.out.println("Testing project "+file.getAbsolutePath());
00056                                                 System.out.println("--------------------------------------------------------------------------------");
00057                                                 M2MProject project = new M2MProject();
00058                                                 project.openProject(file.getAbsolutePath());
00059                                                 try{
00060                                                         project.getStructTreatment().parse(project.getSourceFile());
00061                                                         project.clear();
00062                                                         if (ExternalRuns.runAll(project)) {
00063                                                                 if (project.getSimulationResult().getNbErrors()>0)
00064                                                                         errors.add("Number of simulation errors for "+project.getProperties().getProjectFullFilename()+" : "+project.getSimulationResult().getNbErrors());
00065 
00066                                                                 System.out.println("--------------------------------------------------------------------------------");
00067                                                                 System.out.println("End of test for project "+file.getAbsolutePath());
00068                                                                 System.out.println("********************************************************************************");
00069                                                         }
00070                                                         else {
00071                                                                 errors.add("Can not launch simulation for "+project.getProperties().getProjectFullFilename());
00072                                                         }
00073                                                 }       
00074                                                 catch (ParsingException e1) {
00075                                                         errors.add("Can not parse file of "+project.getProperties().getProjectFullFilename());
00076                                                 }
00077                                                 project.clear();
00078                                         }
00079                                 }               
00080                         }
00081                 }
00082         }
00083         
00084         public static boolean testDir(String dir) {
00085                 Vector<String> errors=new Vector<String>(); 
00086                 testDirInternal(dir,errors);    
00087                 System.out.println("********************************************************************************");
00088                 System.out.println("Simulation results");
00089                 System.out.println("--------------------------------------------------------------------------------");
00090                 if (errors.size()==0)
00091                         System.out.println("There are no errors in the different projects");
00092                 for (int i=0;i<errors.size();i++) {
00093                         System.out.println(errors.elementAt(i)+"\n");
00094                 }
00095                 System.out.println("--------------------------------------------------------------------------------");
00096                 System.out.println("End of Simulation results");
00097                 System.out.println("********************************************************************************");
00098                 return true;
00099         }       
00100 
00101 }
 All Classes Namespaces Files Functions Variables Enumerations