/* * Created on Jun 23, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package RegressionTest.buttons; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.IPath; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import CDBuilder.console.StreamHandler; /** * @author Ali Monadi * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public abstract class ResetFolders { /* This finction removes all Regression test models * * @param IWorkspaceRoot root * @param String path, this will ONLY be a name of project in the workspace NOT FULL PATH(ie: DevsRegression) */ public static boolean deleteProject(IWorkspaceRoot root, String path){ try{ //this is where the test models are located String deletePath =root.getLocation().append("\\" +path).toString(); File deleteFolder = new File(deletePath); if (deleteFolder.exists()){ // copy the project from the plugin dir to the workspace dir // the -R parameter is for copying directories Process movTestFileProc = Runtime.getRuntime().exec("rm -r " + deletePath); StreamHandler rmDerrorHandler = new StreamHandler(movTestFileProc.getErrorStream(), "ERROR",true); StreamHandler rmDoutputHandler = new StreamHandler(movTestFileProc.getInputStream(), "OUTPUT", true); rmDerrorHandler.start(); rmDoutputHandler.start(); while (new File(deletePath).exists()){}//pool until it has been deleted System.out.println("File has been deleted"); } return true; }catch(Exception e){ e.printStackTrace(); return false; } } /* * This function will copy the projects folder(DevsRegression or CellDevsRegression) provided by the path * to the workspace * * @param IWorkspaceRoot root * @param String path, will be the full path to the location of the folder which contains the projects */ public static boolean setupTestfolders(IWorkspaceRoot root, String path){ Process movTestFileProc; try{ //this is where the test models are located File RegressionFiles = new File(path); if(!RegressionFiles.exists()){ MessageBox npGui = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); npGui.setMessage("CD++ plugin does NOT contain require projects to start test "); npGui.setText("ERROR"); npGui.open(); return false; } // copy the project from the plugin dir to the workspace dir // the -R parameter is for copying directories movTestFileProc = Runtime.getRuntime().exec("cp -R " + path + " " + root.getLocation()); StreamHandler rmDerrorHandler = new StreamHandler(movTestFileProc.getErrorStream(), "ERROR",true); StreamHandler rmDoutputHandler = new StreamHandler(movTestFileProc.getInputStream(), "OUTPUT", true); rmDerrorHandler.start(); rmDoutputHandler.start(); //Thread.sleep(1000); }catch(Exception e){ e.printStackTrace(); return false; } String resultsFolder = root.getLocation().append(path.substring(path.lastIndexOf("/"), path.length())).toString(); File ModelsFolder = new File(resultsFolder.concat("\\Models")); System.out.println(ModelsFolder.toString()); File [] newRegression = ModelsFolder.listFiles(); boolean check = false; //polling files until all have been copied while( !( new File(resultsFolder).exists()) || !ModelsFolder.exists()){} while(check == false){ newRegression = ModelsFolder.listFiles(); if(newRegression != null){ File [] OrigRegression = new File(path.concat("\\Models")).listFiles(); if ( OrigRegression.length == newRegression.length ){ for (int i = 0; i < OrigRegression.length; i++ ){ //loop projects File [] origFiles = OrigRegression[i].listFiles(); File [] newFiles = newRegression[i].listFiles(); if (origFiles != null && newFiles != null){ if ( origFiles.length == newFiles.length ){ check = true; System.out.println("done checking project: "+ newRegression[i].getName()); }else check= false; }else check= false; }//loop projects }else{ check= false; System.out.println("ORIG files"+OrigRegression.length+ " NEW files" +newRegression.length); } }else{ check = false; System.out.println("\nnull"); } } return resultsFileStructure(root, resultsFolder ); } /* * For every project within the /Models directory it will create a folder * in the /Results directory. Also the '.log' and '.out' files from each of the projects will * be removed and placed in the coresponding folder in the /Results directory * * @param IworkSpaceRoot root * @param String path, a full path of the Regression folder * (IE: C:\eclipse\runtime-workspace\DevsRegression or * C:\eclipse\runtime-workspace\CellDevsRegression ) */ private static boolean resultsFileStructure(IWorkspaceRoot root, String path ){ File RegressionProjects = new File (path.concat("\\Models\\")); File results = new File( path.concat("\\Results")); File [] projects = RegressionProjects.listFiles(); Process mkdir; if (projects != null){ for (int i=0; i< projects.length; i++){ try{ File [] projectFiles = projects[i].listFiles(); String directory = results.toString().concat("\\"+projects[i].getName()); System.out.println(directory); mkdir = Runtime.getRuntime().exec("mkdir " + directory ); StreamHandler rmDerrorHandler = new StreamHandler(mkdir.getErrorStream(), "ERROR",true); StreamHandler rmDoutputHandler = new StreamHandler(mkdir.getInputStream(), "OUTPUT", true); rmDerrorHandler.start(); rmDoutputHandler.start(); while( !(new File(directory ).exists()) ){ System.out.println(directory); } for (int j=0; j