00001 package edu.stanford.hci.r3.tools.debug; 00002 00003 import java.io.BufferedReader; 00004 import java.io.File; 00005 import java.io.FileInputStream; 00006 import java.io.IOException; 00007 import java.io.InputStreamReader; 00008 import java.util.ArrayList; 00009 import java.util.HashMap; 00010 import java.util.List; 00011 import java.util.Map; 00012 00013 /* 00014 import com.sun.jdi.AbsentInformationException; 00015 import com.sun.jdi.Bootstrap; 00016 import com.sun.jdi.Location; 00017 import com.sun.jdi.Method; 00018 import com.sun.jdi.VirtualMachine; 00019 import com.sun.jdi.VirtualMachineManager; 00020 import com.sun.jdi.connect.AttachingConnector; 00021 import com.sun.jdi.connect.IllegalConnectorArgumentsException; 00022 import com.sun.jdi.connect.Connector.Argument; 00023 */ 00024 00035 public class Utils { 00036 /* 00037 public static void main(String args[]) { 00038 System.out.println("vm = "+getVM()); 00039 } 00040 00041 public static VirtualMachine getVM() { 00042 / 00043 # Debugger is launched. Debugger selects a connector in the list returned by attachingConnectors() matching the transport with the name "xxx". 00044 * # Debugger presents the default connector parameters (obtained through Connector.defaultArguments()) to the end user, allowing the user to fill in the transport-specific address generated by the target VM. 00045 * # Debugger calls the AttachingConnector.attach(java.util.Map) method of the selected to attach to the target VM. A VirtualMachine mirror is returned. 00046 00047 VirtualMachineManager vmm = Bootstrap.virtualMachineManager(); 00048 VirtualMachine vm = null; 00049 for (AttachingConnector ac : vmm.attachingConnectors()) { 00050 System.out.println("ac = "+ac+"[name="+ac.name()+",transport="+ac.transport()+",desc="+ac.description()); 00051 if (ac.name().equals("com.sun.jdi.SocketAttach")) { 00052 Map<String,Argument> map = ac.defaultArguments(); 00053 map.get("port").setValue("3000"); 00054 for (String key : map.keySet()) { 00055 System.out.println("key = "+key+" argument = "+map.get(key)); 00056 } 00057 try { 00058 vm = ac.attach(map); 00059 } catch (IOException e) { 00060 // TODO Auto-generated catch block 00061 e.printStackTrace(); 00062 } catch (IllegalConnectorArgumentsException e) { 00063 // TODO Auto-generated catch block 00064 e.printStackTrace(); 00065 } 00066 } 00067 } 00068 return vm; 00069 } 00070 00071 00072 00073 public String getSource(String sourcebase, Method m) { 00074 StringBuffer sb = new StringBuffer(); 00075 00076 Map<String,List<String>> files = new HashMap<String,List<String>>(); 00077 00078 try { 00079 for (Location l : m.allLineLocations()) { 00080 //l.sourcePath() 00081 //l.lineNumber() 00082 } 00083 } catch (AbsentInformationException ex) { 00084 return ex.toString(); 00085 } 00086 00087 00088 return sb.toString(); 00089 }*/ 00096 public static List<String> getLines(File file) throws IOException { 00097 FileInputStream fis = new FileInputStream(file); 00098 BufferedReader read = new BufferedReader(new InputStreamReader(fis)); 00099 00100 String line; 00101 List<String> strings = new ArrayList<String>(); 00102 while ((line = read.readLine())!=null) 00103 strings.add(line); 00104 return strings; 00105 } 00106 }
1.4.7