/* * Created on 05.02.2008 * emonic.test emonic.test MBelIntoFile.java */ package emonic.test; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; 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 java.nio.ByteBuffer; import java.nio.channels.*; import java.nio.charset.*; 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 edu.arizona.cs.mbel2.parse.MSILParseException; 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 dllPathOne = "/home/dertl/vimem/mono/lib/mono/2.0/mscorlib.dll"; private static final String dllDirPath = "/home/dertl/vimem/mono/lib/mono/1.0/"; private static final String dllDirPath2 = "/home/dertl/vimem/mono/lib/mono/2.0/"; //NOT 2.0! private static final String assemblyFilePath ="/home/dertl/vimem/assembly.txt"; private StringBuffer text; public MBelIntoFile(){ super(); } public void testCreation() throws Throwable{ Job job = new Job("Parsing...") { public IStatus run(IProgressMonitor monitor) { try { monitor.beginTask("Analyzing " , 10); //Call AssemblyParser of MBel => use dllPathOne Vector fileVec = addAssembliesToArray(); monitor.worked(5); ByteArrayOutputStream bos = iterateAssembliesToBB(fileVec); writeBBToFile(bos); //grep for elements //GREP WITH BYTE BUFFER /*long start = System.currentTimeMillis(); Grep.compile("ViMEM> IParaFrame.KeyRegistry.KEY_8"); ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray()); Grep.grep(bb); long end = System.currentTimeMillis(); System.out.println("[GREP with ByteBuffer] Time: "+(end-start)+"ms");*/ //GREP WITH FILE /*start = System.currentTimeMillis(); Grep.compile("ViMEM> IParaFrame.KeyRegistry.KEY_8"); Grep.grep(new File(assemblyFilePath)); end = System.currentTimeMillis(); System.out.println("[GREP with File] Time: "+(end-start)+"ms");*/ //alternative grep long start = System.currentTimeMillis(); grepElements( "ViMEM> IParaFrame.KeyRegistry.KEY_8"); long end = System.currentTimeMillis(); System.out.println("[Alternative GREP self written with file] Time: " + (end-start) + "ms"); //grep delete and add incremental => comparable to save of file //delete only lines from ViMEM assembly! //Grep.compile("ViMEM> IParaFrame.KeyRegistry"); //Grep.grepDelete(bb); //Grep.grep(bb); //grep delete => remove dll, delete file //grep add => new file, add dll 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; } } //alternative grep private void grepElements(String toGrep) { //Search file via java-grep => accords to string //bei this => create String line; BufferedReader input = null; Matcher matcher; Pattern pattern; try { input = new BufferedReader(new FileReader(assemblyFilePath)); } catch (FileNotFoundException e1) { e1.printStackTrace(); } pattern = Pattern.compile(".*"+toGrep+".*"); try{ while((line = input.readLine()) != null){ matcher = pattern.matcher(line); if(matcher.matches()){ System.out.println(line); } } }catch(IOException e){ e.printStackTrace(); } } private void updateMetadataFile(IAssembly assembly, ByteArrayOutputStream bos) { text = new StringBuffer(); //get namespace[] INamespace[] namespaces = assembly.getNamespaces(); for(int i=0; i " + namespaceName + "\n"); //IDotNetElement[] dotnetelements = namespaces[i].getChildren(); IType[] dotnetTypes = namespaces[i].getTypes(); //get dotnetelements of types like classes for(int j=0; j " + namespaceName + "." + dotnetTypes[j].getElementName(); //type itself has to be element of file text.append(dotnettext +"\n"); IDotNetElement[] dotnetelements = dotnetTypes[j].getChildren(); for(int k=0; k