1 22 23 package org.aspectj.debugger.request; 24 25 import org.aspectj.debugger.base.*; 26 27 import java.io.*; 28 import java.util.*; 29 30 38 39 public class ReadRequest extends Request { 40 41 private String fileName; 42 private boolean silent; 43 44 public ReadRequest(Debugger debugger, String fileName, boolean silent) { 45 super(debugger); 46 this.fileName = fileName; 47 this.silent = silent; 48 } 49 50 public ReadRequest(Debugger debugger, String fileName) { 51 this(debugger, fileName, false); 52 } 53 54 public Object go() throws NoVMException, DebuggerException { 55 List commands = new Vector(); 56 FileReader fileReader = null; 57 File file; 58 String filePath = fileName; 59 try { 60 file = getFile(); 61 filePath = file.getAbsolutePath(); 63 fileReader = new FileReader(file); 64 } catch (IOException ioe) { 65 throw new DebuggerException("Invalid file name '" + fileName + "'."); 66 } 67 BufferedReader in = new BufferedReader(fileReader); 68 String line = ""; 69 try { 70 if (!silent) { 71 debugger.outln("*** Reading commands from " + filePath); 72 } 73 while ((line = in.readLine()) != null) { 74 Object o; 75 if (!isComment(line)) { 76 commands.add(line); 77 if (!silent) { 78 o = debugger.execute(line); 79 } 80 } 81 } 82 } catch (IOException ioe) { 83 } 84 85 return commands; 86 } 87 88 private boolean isComment(String line) { 89 line = line.trim(); 90 if (line.startsWith("#")) { 91 return true; 92 } 93 return false; 94 } 95 96 private File getFile() throws IOException { 97 Iterator iter = getDirs().iterator(); 98 File file = new File(fileName); 99 if (file.exists()) { 100 return file.getAbsoluteFile(); 101 } 102 while (iter.hasNext()) { 103 String dir = iter.next() + ""; 104 file = new File(dir + File.separator + fileName); 106 if (file.exists()) { 107 return file.getAbsoluteFile(); 109 } 110 } 113 throw new IOException("File not found '" + fileName + "'."); 114 115 } 116 117 private List getDirs() { 118 Vector dirs = new Vector(); 119 dirs.add("."); 120 try { 121 dirs.add(System.getProperty("user.home") + ""); 122 } catch (SecurityException se) { 123 } 124 try { 125 dirs.add(System.getProperty("user.dir") + ""); 126 } catch (SecurityException se) { 127 } 128 dirs.add(debugger.getSourceManager().getSourcePath()); 129 return dirs; 130 } 131 } 132 | Popular Tags |