blob: 72f2a3acf82429ae3e4ab10a9ea73573cb956af2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ant.internal.ui.console;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.ui.console.FileLink;
import org.eclipse.debug.ui.console.IConsole;
import org.eclipse.debug.ui.console.IConsoleLineTracker;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
/**
* Generates hyperlinks for build failures
*/
public class BuildFailedTracker implements IConsoleLineTracker {
private IConsole fConsole;
private Pattern fErrorPattern;
private Pattern fErrorPattern2;
private boolean fBuildFailed= false;
/* (non-Javadoc)
* @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
*/
public void init(IConsole console) {
fConsole = console;
//BUILD FAILED: file:c:/1115/test/buildFiles/23638.xml:12:
fErrorPattern = Pattern.compile(".*BUILD FAILED"); //$NON-NLS-1$
fErrorPattern2 = Pattern.compile(".*\\.xml.*"); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
*/
public void lineAppended(IRegion line) {
try {
int lineOffset = line.getOffset();
int lineLength = line.getLength();
String text = fConsole.getDocument().get(lineOffset, lineLength);
String fileName = null;
String lineNumber = ""; //$NON-NLS-1$
int fileStart = -1;
int index= -1;
Matcher errorMatcher = fErrorPattern.matcher(text);
Matcher errorMatcher2 = fErrorPattern2.matcher(text);
if (errorMatcher.find()) {
fBuildFailed= true;
} else if (fBuildFailed && errorMatcher2.find()) {
index= 0;
fileStart= 0;
}
if (index > -1) {
index = text.indexOf("xml", index); //$NON-NLS-1$
if (index > 0) {
int numberStart= index + 4;
int numberEnd= text.indexOf(':', numberStart);
int fileEnd = index + 3;
if (numberStart > 0 && fileEnd > 0) {
fileName = text.substring(fileStart, fileEnd).trim();
if (numberEnd > 0) {
lineNumber = text.substring(numberStart, numberEnd).trim();
}
}
}
}
if (fileName != null) {
int num = -1;
try {
num = Integer.parseInt(lineNumber);
} catch (NumberFormatException e) {
}
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileName));
IFile file= null;
if (files.length > 0) {
file= files[0];
}
if (file != null && file.exists()) {
FileLink link = new FileLink(file, null, -1, -1, num);
fConsole.addLink(link, lineOffset + fileStart, lineLength - fileStart);
}
}
} catch (BadLocationException e) {
}
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
*/
public void dispose() {
fConsole = null;
}
}