/* * Created on 05.02.2008 * emonic.test emonic.test MBelIntoFile.java */ package emonic.test; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.Map; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.emonic.base.EMonoPlugin; import org.emonic.base.codehierarchy.AssemblyParser; import org.emonic.base.codehierarchy.IAssembly; import org.emonic.base.codehierarchy.IDotNetElement; import org.emonic.base.codehierarchy.IField; import org.emonic.base.codehierarchy.IMethod; import org.emonic.base.codehierarchy.INamespace; import org.emonic.base.codehierarchy.IType; import org.emonic.base.filemanipulators.FileDocument; import junit.framework.TestCase; public class MBelIntoFile extends TestCase { //FIXME dynamic path introduction private static final String dllPathOne = "/home/dertl/ViMEM.dll"; private static final String dllDirPath = "/home/dertl/vimem/mono/lib/mono/1.0/"; private static final String assemblyFilePath ="/home/dertl/vimem/assembly.txt"; private String text; public MBelIntoFile(){ super(); } public void testCreation() throws Throwable{ text = ""; //FIXME MBEL is unable to work with large files like mscorlib.dll => Remy is on track //HINT: it works with the object browser but not with this file => maybe too much info? Job job = new Job("Parsing...") { public IStatus run(IProgressMonitor monitor) { try { monitor.beginTask("Analyzing " , 10); //Call AssemblyParser of MBel => use dllPathOne Vector fileVec = new Vector(); fileVec.add(new File(dllPathOne)); File dllDir = new File(dllDirPath); if(dllDir.isDirectory()){ String[] files = dllDir.list(); for(int i=0; i< files.length;i++){ //if file = dll if(files[i].endsWith(".dll") && !files[i].endsWith("mscorlib.dll")) fileVec.add(new File(dllDir, files[i])); } } Map[] maps = new Map[]{ Collections.EMPTY_MAP, Collections.EMPTY_MAP }; monitor.worked(5); FileOutputStream fos = getFileOutputStreamForDlls(); //create file with file input of MBel Iterator iter = fileVec.iterator(); while(iter.hasNext()){ File actualFile = (File) iter.next(); maps = new Map[]{ Collections.EMPTY_MAP, Collections.EMPTY_MAP }; System.out.print(actualFile.getName()); Date start = new Date(); createFile(AssemblyParser.parseAssembly(new FileInputStream(actualFile.getAbsolutePath()), new Path(actualFile.getAbsolutePath()), maps), fos); Date end = new Date(); System.out.println( " Time: "+(end.getTime()-start.getTime())+"ms"); } //grep for elements Date grepstart = new Date(); grepElements(); Date grepend = new Date(); System.out.println("[GREP] Time: "+(grepend.getTime()-grepstart.getTime())+"ms"); return Status.OK_STATUS; }catch (Exception e) { e.printStackTrace(); return Status.CANCEL_STATUS; } finally { monitor.done(); } } }; job.schedule(); while(true){ if(job.getState() == job.NONE) break; } } private void grepElements() { //Search file via java-grep => accords to string //bei this => create String re = "IParaFrame"; String line; BufferedReader input =null; Matcher matcher; Pattern pattern; try { input = new BufferedReader(new FileReader(assemblyFilePath)); } catch (FileNotFoundException e1) { e1.printStackTrace(); } pattern = Pattern.compile(".*"+re+".*"); try{ while((line = input.readLine()) != null){ matcher = pattern.matcher(line); if(matcher.matches()){ System.out.println(line); } } }catch(IOException e){ e.printStackTrace(); } } private void createFile(IAssembly assembly, FileOutputStream fos) { //get namespace[] INamespace[] namespaces = assembly.getNamespaces(); for(int i=0; i