1 11 package org.eclipse.ant.internal.ui.console; 12 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.debug.ui.console.FileLink; 19 import org.eclipse.debug.ui.console.IConsole; 20 import org.eclipse.debug.ui.console.IConsoleLineTracker; 21 import org.eclipse.jface.text.BadLocationException; 22 import org.eclipse.jface.text.IRegion; 23 import org.eclipse.ui.externaltools.internal.model.StringMatcher; 24 25 28 public class JavacLineTracker implements IConsoleLineTracker { 29 30 private IConsole fConsole; 31 private IFile fLastFile; 32 private StringMatcher fEclipseCompilerMatcher; 33 private StringMatcher fJavacMatcher; 34 private StringMatcher fJikesMatcher; 35 36 private boolean fTrolling = false; 38 39 42 public JavacLineTracker() { 43 super(); 44 } 45 46 49 public void init(IConsole console) { 50 fConsole = console; 51 fEclipseCompilerMatcher = new StringMatcher("*[javac]*ERROR in*.java*(at line*)*",false, false); fJavacMatcher = new StringMatcher("*[javac] *.java:*:*",false, false); fJikesMatcher = new StringMatcher("*[javac] *\"*.java\":", false, false); } 55 56 59 public void lineAppended(IRegion line) { 60 try { 61 int lineOffset = line.getOffset(); 62 int lineLength = line.getLength(); 63 String text = fConsole.getDocument().get(lineOffset, lineLength); 64 String fileName = null; 65 String lineNumber = ""; int fileStart = -1; 67 if (fEclipseCompilerMatcher.match(text)) { 68 fTrolling = false; 69 int index = text.indexOf("ERROR in"); if (index > 0) { 71 fileStart = index + 9; 72 index = text.lastIndexOf("(at line "); if (index > 0) { 74 int fileEnd = index - 1; 75 int numberStart = index + 9; 76 index = text.lastIndexOf(')'); 77 if (index > 0) { 78 int numberEnd = index; 79 fileName = text.substring(fileStart, fileEnd).trim(); 80 lineNumber = text.substring(numberStart, numberEnd).trim(); 81 } 82 } 83 } 84 } else if (fJavacMatcher.match(text)) { 85 fTrolling = false; 86 fileStart = text.indexOf("[javac] "); fileStart += 8; 88 int index = text.indexOf(".java:", fileStart); if (index > 0) { 90 int numberStart = index + 6; 91 fileName = text.substring(fileStart, numberStart - 1).trim(); 92 index = text.indexOf(":", numberStart); if (index > numberStart) { 94 lineNumber = text.substring(numberStart, index); 95 } 96 } 97 } else if (fJikesMatcher.match(text)) { 98 fileStart = text.indexOf('"'); 99 fileStart++; 100 int index = text.indexOf(".java\"", fileStart); if (index > 0) { 102 index += 5; 103 fileName = text.substring(fileStart, index).trim(); 104 fTrolling = true; 105 } 106 } else if (fTrolling) { 107 int index = text.indexOf("[javac]"); if (index > 0) { 109 index+=7; 111 int numEnd = text.indexOf(".", index); if (numEnd > 0) { 113 String number = text.substring(index, numEnd).trim(); 114 try { 115 int num = Integer.parseInt(number); 116 int numStart = text.indexOf(number, index); 117 if (fLastFile != null && fLastFile.exists()) { 118 FileLink link = new FileLink(fLastFile, null, -1, -1, num); 119 fConsole.addLink(link, lineOffset + numStart, lineLength - numStart); 120 } 121 } catch (NumberFormatException e) { 122 } 124 } 125 } else { 126 fTrolling = false; 127 } 128 } 129 if (fileName != null) { 130 int num = -1; 131 try { 132 num = Integer.parseInt(lineNumber); 133 } catch (NumberFormatException e) { 134 } 135 IFile file= null; 136 IPath filePath= new Path(fileName); 137 if (fLastFile != null && fLastFile.getLocation().equals(filePath)) { 139 file= fLastFile; 140 } else { 141 IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath); 142 if (files.length != 0) { 143 file= files[0]; 144 } 145 } 146 fLastFile = file; 147 if (file != null && file.exists()) { 148 FileLink link = new FileLink(file, null, -1, -1, num); 149 fConsole.addLink(link, lineOffset + fileStart, lineLength - fileStart); 150 } 151 } 152 } catch (BadLocationException e) { 153 } 154 } 155 156 159 public void dispose() { 160 fConsole = null; 161 } 162 163 } 164 | Popular Tags |