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.Path; 17 import org.eclipse.debug.ui.console.FileLink; 18 import org.eclipse.debug.ui.console.IConsole; 19 import org.eclipse.debug.ui.console.IConsoleLineTracker; 20 import org.eclipse.jface.text.BadLocationException; 21 import org.eclipse.jface.text.IRegion; 22 import org.eclipse.ui.externaltools.internal.model.StringMatcher; 23 24 27 public class BuildFailedTracker implements IConsoleLineTracker { 28 29 private IConsole fConsole; 30 private StringMatcher fErrorMatcher; 31 private StringMatcher fErrorMatcher2; 32 private boolean fBuildFailed= false; 33 34 37 public void init(IConsole console) { 38 fConsole = console; 39 fErrorMatcher = new StringMatcher("*BUILD FAILED: *.xml*", false, false); fErrorMatcher2= new StringMatcher("*.xml*", false, false); } 43 44 47 public void lineAppended(IRegion line) { 48 try { 49 int lineOffset = line.getOffset(); 50 int lineLength = line.getLength(); 51 String text = fConsole.getDocument().get(lineOffset, lineLength); 52 String fileName = null; 53 String lineNumber = ""; int fileStart = -1; 55 int index= -1; 56 if (fErrorMatcher.match(text)) { 57 fBuildFailed= true; 58 index = text.indexOf("file:"); if (index > 0) { 60 fileStart = index + 5; 61 } else { 62 fileStart = text.indexOf("BUILD FAILED:") + 14; index= fileStart; 64 } 65 } else if (fBuildFailed && fErrorMatcher2.match(text)) { 66 index= 0; 70 fileStart= 0; 71 } 72 if (index > -1) { 73 index = text.indexOf("xml", index); if (index > 0) { 75 int numberStart= index + 4; 76 int numberEnd= text.indexOf(':', numberStart); 77 int fileEnd = index + 3; 78 if (numberStart > 0 && fileEnd > 0) { 79 fileName = text.substring(fileStart, fileEnd).trim(); 80 if (numberEnd > 0) { 81 lineNumber = text.substring(numberStart, numberEnd).trim(); 82 } 83 } 84 } 85 } 86 if (fileName != null) { 87 int num = -1; 88 try { 89 num = Integer.parseInt(lineNumber); 90 } catch (NumberFormatException e) { 91 } 92 IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileName)); 93 IFile file= null; 94 if (files.length > 0) { 95 file= files[0]; 96 } 97 if (file != null && file.exists()) { 98 FileLink link = new FileLink(file, null, -1, -1, num); 99 fConsole.addLink(link, lineOffset + fileStart, lineLength - fileStart); 100 } 101 } 102 } catch (BadLocationException e) { 103 } 104 } 105 106 109 public void dispose() { 110 fConsole = null; 111 } 112 } | Popular Tags |