mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
new streams based builder command errorparsing to
reduce memory usage
This commit is contained in:
parent
a3e38434ac
commit
c4b64b397d
13 changed files with 458 additions and 370 deletions
|
@ -1,3 +1,24 @@
|
||||||
|
2002-10-23 David Inglis
|
||||||
|
|
||||||
|
Error parsing is now done as the streams from the commands
|
||||||
|
are read, this reduces memory usage during the build
|
||||||
|
process, and we can now add options to the build console to
|
||||||
|
only keep 'n' lines of output, again reducing the memory
|
||||||
|
usage. Also refactored IErrorParser and ErrorParserManager out
|
||||||
|
of internal.
|
||||||
|
|
||||||
|
* src/.../errorparser/ErrorParserManager.java:
|
||||||
|
* src/.../errorparser/IErrorParser.java:
|
||||||
|
* src/.../internal/errorparser/GASErrorParser.java:
|
||||||
|
* src/.../internal/errorparser/GCCErrorParser.java:
|
||||||
|
* src/.../internal/errorparser/GLDErrorParser.java:
|
||||||
|
* src/.../internal/errorparser/MakeErrorParser.java:
|
||||||
|
* src/.../internal/errorparser/VCErrorParser.java:
|
||||||
|
* src/.../internal/core/CBuilder.java:
|
||||||
|
* src/.../internal/core/ProcessCloseure.java:
|
||||||
|
* src/.../core/ConsoleOutputStream.java:
|
||||||
|
|
||||||
|
|
||||||
2002-10-22 Alain Magloire
|
2002-10-22 Alain Magloire
|
||||||
|
|
||||||
* src/.../internal/parser/LinePositionInputStream.java:
|
* src/.../internal/parser/LinePositionInputStream.java:
|
||||||
|
|
|
@ -16,48 +16,19 @@ public class ConsoleOutputStream extends OutputStream {
|
||||||
|
|
||||||
protected StringBuffer fBuffer;
|
protected StringBuffer fBuffer;
|
||||||
|
|
||||||
protected StringBuffer fContent;
|
|
||||||
|
|
||||||
protected int pos;
|
|
||||||
|
|
||||||
public ConsoleOutputStream() {
|
public ConsoleOutputStream() {
|
||||||
fBuffer= new StringBuffer(256);
|
fBuffer= new StringBuffer();
|
||||||
fContent= new StringBuffer();
|
|
||||||
pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see OutputStream#flush
|
public String readBuffer() {
|
||||||
*/
|
String buf = fBuffer.toString();
|
||||||
public synchronized void flush() throws IOException {
|
|
||||||
final String content= fBuffer.toString();
|
|
||||||
fBuffer.setLength(0);
|
fBuffer.setLength(0);
|
||||||
fContent.append(content);
|
return buf;
|
||||||
}
|
|
||||||
|
|
||||||
public String getContent(int len) {
|
|
||||||
String s = null;
|
|
||||||
try {
|
|
||||||
s = fContent.substring (len);
|
|
||||||
} catch (StringIndexOutOfBoundsException e) {
|
|
||||||
s = "";
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContent() {
|
|
||||||
// return fContent.toString();
|
|
||||||
if (pos >= fContent.length())
|
|
||||||
pos = 0;
|
|
||||||
String s = getContent(pos);
|
|
||||||
pos += s.length();
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
fBuffer.setLength (0);
|
fBuffer.setLength (0);
|
||||||
fContent.setLength (0);
|
|
||||||
pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,8 +37,5 @@ public class ConsoleOutputStream extends OutputStream {
|
||||||
*/
|
*/
|
||||||
public synchronized void write(int c) throws IOException {
|
public synchronized void write(int c) throws IOException {
|
||||||
fBuffer.append((char) c);
|
fBuffer.append((char) c);
|
||||||
if (fBuffer.length() > 250) {
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,404 @@
|
||||||
|
package org.eclipse.cdt.errorparsers;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) Copyright IBM Corp. 2000, 2001.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
|
import org.eclipse.cdt.core.resources.ACBuilder;
|
||||||
|
import org.eclipse.cdt.internal.errorparsers.GASErrorParser;
|
||||||
|
import org.eclipse.cdt.internal.errorparsers.GCCErrorParser;
|
||||||
|
import org.eclipse.cdt.internal.errorparsers.GLDErrorParser;
|
||||||
|
import org.eclipse.cdt.internal.errorparsers.MakeErrorParser;
|
||||||
|
import org.eclipse.cdt.internal.errorparsers.VCErrorParser;
|
||||||
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
|
public class ErrorParserManager extends OutputStream {
|
||||||
|
private int nOpens;
|
||||||
|
|
||||||
|
private static String PREF_ERROR_PARSER = "errorOutputParser";
|
||||||
|
|
||||||
|
private IProject fProject;
|
||||||
|
private IMarkerGenerator fMarkerGenerator;
|
||||||
|
private Map fFilesInProject;
|
||||||
|
private List fNameConflicts;
|
||||||
|
|
||||||
|
private ArrayList fErrorParsers;
|
||||||
|
private ArrayList fErrors;
|
||||||
|
|
||||||
|
private Vector fDirectoryStack;
|
||||||
|
private IPath fBaseDirectory;
|
||||||
|
|
||||||
|
private String previousLine;
|
||||||
|
private OutputStream outputStream;
|
||||||
|
private StringBuffer currentLine = new StringBuffer();
|
||||||
|
|
||||||
|
public ErrorParserManager(ACBuilder builder) {
|
||||||
|
this(builder.getProject(), builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator) {
|
||||||
|
fProject = project;
|
||||||
|
fErrorParsers = new ArrayList();
|
||||||
|
fMarkerGenerator = markerGenerator;
|
||||||
|
readPreferences();
|
||||||
|
initParser();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initParser() {
|
||||||
|
fFilesInProject = new HashMap();
|
||||||
|
fNameConflicts = new ArrayList();
|
||||||
|
fDirectoryStack = new Vector();
|
||||||
|
fErrors = new ArrayList();
|
||||||
|
|
||||||
|
// prepare file lists
|
||||||
|
fFilesInProject.clear();
|
||||||
|
fNameConflicts.clear();
|
||||||
|
|
||||||
|
List collectedFiles = new ArrayList();
|
||||||
|
fBaseDirectory = fProject.getLocation();
|
||||||
|
collectFiles(fProject, collectedFiles);
|
||||||
|
|
||||||
|
for (int i = 0; i < collectedFiles.size(); i++) {
|
||||||
|
IFile curr = (IFile) collectedFiles.get(i);
|
||||||
|
Object existing = fFilesInProject.put(curr.getName(), curr);
|
||||||
|
if (existing != null) {
|
||||||
|
fNameConflicts.add(curr.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPath getWorkingDirectory() {
|
||||||
|
if (fDirectoryStack.size() != 0) {
|
||||||
|
return (IPath) fDirectoryStack.lastElement();
|
||||||
|
}
|
||||||
|
return new Path("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pushDirectory(IPath dir) {
|
||||||
|
if (dir != null) {
|
||||||
|
IPath pwd = null;
|
||||||
|
if (fBaseDirectory.isPrefixOf(dir)) {
|
||||||
|
int segments = fBaseDirectory.matchingFirstSegments(dir);
|
||||||
|
pwd = dir.removeFirstSegments(segments);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pwd = dir;
|
||||||
|
}
|
||||||
|
fDirectoryStack.addElement(pwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPath popDirectory() {
|
||||||
|
int i = fDirectoryStack.size();
|
||||||
|
IPath dir = (IPath) fDirectoryStack.lastElement();
|
||||||
|
if (i != 0) {
|
||||||
|
fDirectoryStack.removeElementAt(i - 1);
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDirectoryLevel() {
|
||||||
|
return fDirectoryStack.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addParser(IErrorParser parser) {
|
||||||
|
fErrorParsers.add(parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readPreferences() {
|
||||||
|
fErrorParsers.clear();
|
||||||
|
String parserNames = CCorePlugin.getDefault().getPluginPreferences().getString(PREF_ERROR_PARSER);
|
||||||
|
if (parserNames != null && parserNames.length() > 0) {
|
||||||
|
StringTokenizer tok = new StringTokenizer(parserNames, ";");
|
||||||
|
while (tok.hasMoreElements()) {
|
||||||
|
String clName = tok.nextToken();
|
||||||
|
try {
|
||||||
|
IErrorParser parser = (IErrorParser) getClass().forName(clName).newInstance();
|
||||||
|
fErrorParsers.add(parser);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
// not found
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
catch (InstantiationException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
catch (ClassCastException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fErrorParsers.size() == 0) {
|
||||||
|
initErrorParsersArray(fErrorParsers);
|
||||||
|
}
|
||||||
|
savePreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initErrorParsersArray(List errorParsers) {
|
||||||
|
errorParsers.add(new VCErrorParser());
|
||||||
|
errorParsers.add(new GCCErrorParser());
|
||||||
|
errorParsers.add(new GLDErrorParser());
|
||||||
|
errorParsers.add(new GASErrorParser());
|
||||||
|
errorParsers.add(new MakeErrorParser());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void savePreferences() {
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
for (int i = 0; i < fErrorParsers.size(); i++) {
|
||||||
|
buf.append(fErrorParsers.get(i).getClass().getName());
|
||||||
|
buf.append(';');
|
||||||
|
}
|
||||||
|
CCorePlugin.getDefault().getPluginPreferences().setValue(PREF_ERROR_PARSER, buf.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void collectFiles(IContainer parent, List result) {
|
||||||
|
try {
|
||||||
|
IResource[] resources = parent.members();
|
||||||
|
for (int i = 0; i < resources.length; i++) {
|
||||||
|
IResource resource = resources[i];
|
||||||
|
if (resource instanceof IFile) {
|
||||||
|
result.add(resource);
|
||||||
|
}
|
||||||
|
else if (resource instanceof IContainer) {
|
||||||
|
collectFiles((IContainer) resource, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the input and try to generate error or warning markers
|
||||||
|
*/
|
||||||
|
public void parse(String output) {
|
||||||
|
BufferedReader rd = new BufferedReader(new StringReader(output));
|
||||||
|
try {
|
||||||
|
String line = rd.readLine();
|
||||||
|
while (line != null) {
|
||||||
|
processLine(line);
|
||||||
|
previousLine = line;
|
||||||
|
line = rd.readLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
rd.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fDirectoryStack.removeAllElements();
|
||||||
|
fBaseDirectory = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processLine(String line) {
|
||||||
|
int top = fErrorParsers.size() - 1;
|
||||||
|
int i = top;
|
||||||
|
do {
|
||||||
|
IErrorParser curr = (IErrorParser) fErrorParsers.get(i);
|
||||||
|
if (curr.processLine(line, this)) {
|
||||||
|
if (i != top) {
|
||||||
|
// move to top
|
||||||
|
Object used = fErrorParsers.remove(i);
|
||||||
|
fErrorParsers.add(used);
|
||||||
|
savePreferences();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
while (i >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the error parsers.
|
||||||
|
*/
|
||||||
|
public IFile findFileName(String fileName) {
|
||||||
|
IPath path = new Path(fileName);
|
||||||
|
return (IFile) fFilesInProject.get(path.lastSegment());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the error parsers.
|
||||||
|
*/
|
||||||
|
public boolean isConflictingName(String fileName) {
|
||||||
|
IPath path = new Path(fileName);
|
||||||
|
return fNameConflicts.contains(path.lastSegment());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the error parsers.
|
||||||
|
*/
|
||||||
|
public IFile findFilePath(String filePath) {
|
||||||
|
IPath path = null;
|
||||||
|
IPath fp = new Path(filePath);
|
||||||
|
if (fp.isAbsolute()) {
|
||||||
|
if (fBaseDirectory.isPrefixOf(fp)) {
|
||||||
|
int segments = fBaseDirectory.matchingFirstSegments(fp);
|
||||||
|
path = fp.removeFirstSegments(segments);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path = fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path = (IPath) getWorkingDirectory().append(filePath);
|
||||||
|
}
|
||||||
|
return (IFile) fProject.getFile(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class Problem {
|
||||||
|
protected IResource file;
|
||||||
|
protected int lineNumber;
|
||||||
|
protected String description;
|
||||||
|
protected int severity;
|
||||||
|
protected String variableName;
|
||||||
|
|
||||||
|
public Problem(IResource file, int lineNumber, String desciption, int severity, String variableName) {
|
||||||
|
this.file = file;
|
||||||
|
this.lineNumber = lineNumber;
|
||||||
|
this.description = desciption;
|
||||||
|
this.severity = severity;
|
||||||
|
this.variableName = variableName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the error parsers.
|
||||||
|
*/
|
||||||
|
public void generateMarker(IResource file, int lineNumber, String desc, int severity, String varName) {
|
||||||
|
Problem problem = new Problem(file, lineNumber, desc, severity, varName);
|
||||||
|
fErrors.add(problem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the error parsers. Return the previous line, save in the working buffer.
|
||||||
|
*/
|
||||||
|
public String getPreviousLine() {
|
||||||
|
return new String((previousLine) == null ? "" : previousLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method setOutputStream.
|
||||||
|
* @param cos
|
||||||
|
*/
|
||||||
|
public void setOutputStream(OutputStream os) {
|
||||||
|
outputStream = os;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getInputStream.
|
||||||
|
* @return OutputStream
|
||||||
|
*/
|
||||||
|
public OutputStream getOutputStream() {
|
||||||
|
nOpens++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.io.OutputStream#close()
|
||||||
|
*/
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (nOpens > 0 && --nOpens == 0) {
|
||||||
|
fDirectoryStack.removeAllElements();
|
||||||
|
fBaseDirectory = null;
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.io.OutputStream#flush()
|
||||||
|
*/
|
||||||
|
public void flush() throws IOException {
|
||||||
|
outputStream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.io.OutputStream#write(int)
|
||||||
|
*/
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
currentLine.append((char) b);
|
||||||
|
checkLine();
|
||||||
|
outputStream.write(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void write(byte[] b, int off, int len) throws IOException {
|
||||||
|
if (b == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
else if (off != 0 || (len < 0) || (len > b.length)) {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
else if (len == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentLine.append(new String(b, 0, len));
|
||||||
|
checkLine();
|
||||||
|
outputStream.write(b, off, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkLine() {
|
||||||
|
String line = currentLine.toString();
|
||||||
|
if (line.endsWith("\n")) {
|
||||||
|
processLine(line);
|
||||||
|
previousLine = line;
|
||||||
|
currentLine.setLength(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reportProblems() {
|
||||||
|
if (nOpens == 0) {
|
||||||
|
Iterator iter = fErrors.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Problem problem = (Problem) iter.next();
|
||||||
|
if (problem.file == null) {
|
||||||
|
fMarkerGenerator.addMarker(
|
||||||
|
fProject,
|
||||||
|
problem.lineNumber,
|
||||||
|
problem.description,
|
||||||
|
problem.severity,
|
||||||
|
problem.variableName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fMarkerGenerator.addMarker(
|
||||||
|
problem.file,
|
||||||
|
problem.lineNumber,
|
||||||
|
problem.description,
|
||||||
|
problem.severity,
|
||||||
|
problem.variableName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fErrors.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.eclipse.cdt.internal.errorparsers;
|
package org.eclipse.cdt.errorparsers;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) Copyright IBM Corp. 2000, 2001.
|
* (c) Copyright IBM Corp. 2000, 2001.
|
|
@ -19,7 +19,7 @@ import org.eclipse.cdt.core.model.ICModelMarker;
|
||||||
import org.eclipse.cdt.core.resources.ACBuilder;
|
import org.eclipse.cdt.core.resources.ACBuilder;
|
||||||
import org.eclipse.cdt.core.resources.IConsole;
|
import org.eclipse.cdt.core.resources.IConsole;
|
||||||
import org.eclipse.cdt.core.resources.MakeUtil;
|
import org.eclipse.cdt.core.resources.MakeUtil;
|
||||||
import org.eclipse.cdt.internal.errorparsers.ErrorParserManager;
|
import org.eclipse.cdt.errorparsers.ErrorParserManager;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -110,13 +110,13 @@ public class CBuilder extends ACBuilder {
|
||||||
}
|
}
|
||||||
env = (String []) envList.toArray(new String [envList.size()]);
|
env = (String []) envList.toArray(new String [envList.size()]);
|
||||||
}
|
}
|
||||||
|
ErrorParserManager epm= new ErrorParserManager(this);
|
||||||
|
epm.setOutputStream(cos);
|
||||||
|
|
||||||
launcher.execute(makepath, userArgs, env, workingDirectory);
|
launcher.execute(makepath, userArgs, env, workingDirectory);
|
||||||
if (launcher.waitAndRead(cos, cos, subMonitor) != CommandLauncher.OK)
|
if (launcher.waitAndRead(epm.getOutputStream(), epm.getOutputStream(), subMonitor) != CommandLauncher.OK)
|
||||||
errMsg = launcher.getErrorMessage();
|
errMsg = launcher.getErrorMessage();
|
||||||
|
|
||||||
monitor.setCanceled(false);
|
monitor.setCanceled(false);
|
||||||
|
|
||||||
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
||||||
subMonitor.subTask("Refresh From Local");
|
subMonitor.subTask("Refresh From Local");
|
||||||
|
|
||||||
|
@ -127,10 +127,6 @@ public class CBuilder extends ACBuilder {
|
||||||
|
|
||||||
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
||||||
subMonitor.subTask("Parsing");
|
subMonitor.subTask("Parsing");
|
||||||
cos.flush();
|
|
||||||
|
|
||||||
ErrorParserManager epm= new ErrorParserManager(this);
|
|
||||||
epm.parse(cos.getContent());
|
|
||||||
|
|
||||||
if (errMsg != null) {
|
if (errMsg != null) {
|
||||||
String errorDesc= CCorePlugin.getFormattedString(BUILD_ERROR, makepath.toString());
|
String errorDesc= CCorePlugin.getFormattedString(BUILD_ERROR, makepath.toString());
|
||||||
|
@ -142,6 +138,8 @@ public class CBuilder extends ACBuilder {
|
||||||
cos.write(buf.toString().getBytes());
|
cos.write(buf.toString().getBytes());
|
||||||
cos.flush();
|
cos.flush();
|
||||||
}
|
}
|
||||||
|
epm.close();
|
||||||
|
epm.reportProblems();
|
||||||
subMonitor.done();
|
subMonitor.done();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -5,12 +5,12 @@ package org.eclipse.cdt.internal.core;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class ProcessClosure {
|
||||||
private InputStream fInputStream;
|
private InputStream fInputStream;
|
||||||
private OutputStream fOutputStream;
|
private OutputStream fOutputStream;
|
||||||
private boolean fFinished = false;
|
private boolean fFinished = false;
|
||||||
|
private String lineSeparator;
|
||||||
/*
|
/*
|
||||||
* outputStream can be null
|
* outputStream can be null
|
||||||
*/
|
*/
|
||||||
|
@ -38,6 +38,7 @@ public class ProcessClosure {
|
||||||
fOutputStream= out;
|
fOutputStream= out;
|
||||||
fInputStream= in;
|
fInputStream= in;
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
|
lineSeparator = (String) System.getProperty("line.separator");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -46,9 +47,9 @@ public class ProcessClosure {
|
||||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fOutputStream));
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fOutputStream));
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
line += lineSeparator;
|
||||||
char[] array = line.toCharArray();
|
char[] array = line.toCharArray();
|
||||||
writer.write(array, 0, array.length);
|
writer.write(array, 0, array.length);
|
||||||
writer.newLine();
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
|
|
|
@ -1,282 +0,0 @@
|
||||||
package org.eclipse.cdt.internal.errorparsers;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (c) Copyright IBM Corp. 2000, 2001.
|
|
||||||
* All Rights Reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Vector;
|
|
||||||
import java.util.StringTokenizer;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IContainer;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.resources.IProject;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
|
||||||
import org.eclipse.cdt.core.resources.ACBuilder;
|
|
||||||
|
|
||||||
public class ErrorParserManager {
|
|
||||||
|
|
||||||
private static String PREF_ERROR_PARSER= "errorOutputParser";
|
|
||||||
|
|
||||||
private IProject fProject;
|
|
||||||
private IMarkerGenerator fMarkerGenerator;
|
|
||||||
private Map fFilesInProject;
|
|
||||||
private List fNameConflicts;
|
|
||||||
|
|
||||||
private ArrayList fErrorParsers;
|
|
||||||
|
|
||||||
private Vector fDirectoryStack;
|
|
||||||
private IPath fBaseDirectory;
|
|
||||||
|
|
||||||
private String previousLine;
|
|
||||||
|
|
||||||
static String SEPARATOR = System.getProperty("file.separator");
|
|
||||||
|
|
||||||
public ErrorParserManager(ACBuilder builder) {
|
|
||||||
this(builder.getProject(), builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator) {
|
|
||||||
fProject= project;
|
|
||||||
fMarkerGenerator= markerGenerator;
|
|
||||||
fFilesInProject= new HashMap();
|
|
||||||
fNameConflicts= new ArrayList();
|
|
||||||
fErrorParsers= new ArrayList();
|
|
||||||
fDirectoryStack = new Vector();
|
|
||||||
fBaseDirectory = null;
|
|
||||||
readPreferences();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPath getWorkingDirectory() {
|
|
||||||
if (fDirectoryStack.size() != 0) {
|
|
||||||
return (IPath)fDirectoryStack.lastElement();
|
|
||||||
}
|
|
||||||
return new Path("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pushDirectory(IPath dir) {
|
|
||||||
if (dir != null) {
|
|
||||||
IPath pwd = null;
|
|
||||||
if (fBaseDirectory.isPrefixOf(dir)) {
|
|
||||||
int segments = fBaseDirectory.matchingFirstSegments(dir);
|
|
||||||
pwd = dir.removeFirstSegments(segments);
|
|
||||||
} else {
|
|
||||||
pwd = dir;
|
|
||||||
}
|
|
||||||
fDirectoryStack.addElement(pwd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPath popDirectory() {
|
|
||||||
int i = fDirectoryStack.size();
|
|
||||||
IPath dir = (IPath)fDirectoryStack.lastElement();
|
|
||||||
if (i != 0) {
|
|
||||||
fDirectoryStack.removeElementAt(i-1);
|
|
||||||
}
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDirectoryLevel() {
|
|
||||||
return fDirectoryStack.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addParser(IErrorParser parser) {
|
|
||||||
fErrorParsers.add(parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void readPreferences() {
|
|
||||||
fErrorParsers.clear();
|
|
||||||
String parserNames= CCorePlugin.getDefault().getPluginPreferences().getString(PREF_ERROR_PARSER);
|
|
||||||
if (parserNames != null && parserNames.length() > 0) {
|
|
||||||
StringTokenizer tok= new StringTokenizer(parserNames, ";");
|
|
||||||
while (tok.hasMoreElements()) {
|
|
||||||
String clName= tok.nextToken();
|
|
||||||
try {
|
|
||||||
IErrorParser parser= (IErrorParser)getClass().forName(clName).newInstance();
|
|
||||||
fErrorParsers.add(parser);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// not found
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fErrorParsers.size() == 0) {
|
|
||||||
initErrorParsersArray(fErrorParsers);
|
|
||||||
}
|
|
||||||
savePreferences();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initErrorParsersArray(List errorParsers) {
|
|
||||||
errorParsers.add(new VCErrorParser());
|
|
||||||
errorParsers.add(new GCCErrorParser());
|
|
||||||
errorParsers.add (new GLDErrorParser ());
|
|
||||||
errorParsers.add (new GASErrorParser ());
|
|
||||||
errorParsers.add (new MakeErrorParser ());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void savePreferences() {
|
|
||||||
StringBuffer buf= new StringBuffer();
|
|
||||||
for (int i= 0; i < fErrorParsers.size(); i++) {
|
|
||||||
buf.append(fErrorParsers.get(i).getClass().getName());
|
|
||||||
buf.append(';');
|
|
||||||
}
|
|
||||||
CCorePlugin.getDefault().getPluginPreferences().setValue(PREF_ERROR_PARSER, buf.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void collectFiles(IContainer parent, List result) {
|
|
||||||
try {
|
|
||||||
IResource[] resources= parent.members();
|
|
||||||
for (int i= 0; i < resources.length; i++) {
|
|
||||||
IResource resource= resources[i];
|
|
||||||
if (resource instanceof IFile) {
|
|
||||||
result.add(resource);
|
|
||||||
} else if (resource instanceof IContainer) {
|
|
||||||
collectFiles((IContainer)resource, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e.getStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the input and try to generate error or warning markers
|
|
||||||
*/
|
|
||||||
public void parse(String output) {
|
|
||||||
// prepare file lists
|
|
||||||
fFilesInProject.clear();
|
|
||||||
fNameConflicts.clear();
|
|
||||||
|
|
||||||
List collectedFiles= new ArrayList();
|
|
||||||
fBaseDirectory = fProject.getLocation();
|
|
||||||
collectFiles(fProject, collectedFiles);
|
|
||||||
|
|
||||||
for (int i= 0; i < collectedFiles.size(); i++) {
|
|
||||||
IFile curr= (IFile)collectedFiles.get(i);
|
|
||||||
Object existing= fFilesInProject.put(curr.getName(), curr);
|
|
||||||
if (existing != null) {
|
|
||||||
fNameConflicts.add(curr.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader rd= new BufferedReader(new StringReader(output));
|
|
||||||
try {
|
|
||||||
String line= rd.readLine();
|
|
||||||
while (line != null) {
|
|
||||||
processLine(line);
|
|
||||||
previousLine = line;
|
|
||||||
line= rd.readLine();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
} finally {
|
|
||||||
try { rd.close(); } catch (IOException e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fFilesInProject.clear();
|
|
||||||
fNameConflicts.clear();
|
|
||||||
fDirectoryStack.removeAllElements();
|
|
||||||
fBaseDirectory = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processLine(String line) {
|
|
||||||
int top= fErrorParsers.size()-1;
|
|
||||||
int i= top;
|
|
||||||
do {
|
|
||||||
IErrorParser curr= (IErrorParser)fErrorParsers.get(i);
|
|
||||||
if (curr.processLine(line, this)) {
|
|
||||||
if (i != top) {
|
|
||||||
// move to top
|
|
||||||
Object used= fErrorParsers.remove(i);
|
|
||||||
fErrorParsers.add(used);
|
|
||||||
savePreferences();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
i--;
|
|
||||||
} while (i >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the error parsers.
|
|
||||||
*/
|
|
||||||
public IFile findFileName(String fileName) {
|
|
||||||
IPath path= new Path(fileName);
|
|
||||||
return (IFile)fFilesInProject.get(path.lastSegment());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the error parsers.
|
|
||||||
*/
|
|
||||||
public boolean isConflictingName(String fileName) {
|
|
||||||
IPath path= new Path(fileName);
|
|
||||||
return fNameConflicts.contains(path.lastSegment());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the error parsers.
|
|
||||||
*/
|
|
||||||
public IFile findFilePath(String filePath) {
|
|
||||||
IPath path = null;
|
|
||||||
IPath fp = new Path(filePath);
|
|
||||||
if (fp.isAbsolute()) {
|
|
||||||
if (fBaseDirectory.isPrefixOf(fp)) {
|
|
||||||
int segments = fBaseDirectory.matchingFirstSegments(fp);
|
|
||||||
path = fp.removeFirstSegments(segments);
|
|
||||||
} else {
|
|
||||||
path = fp;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
path = (IPath)getWorkingDirectory().append(filePath);
|
|
||||||
}
|
|
||||||
return (IFile)fProject.getFile(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the error parsers.
|
|
||||||
*/
|
|
||||||
public void generateMarker(IResource file, int lineNumber, String desc, int severity, String varName) {
|
|
||||||
if (file == null) {
|
|
||||||
fMarkerGenerator.addMarker (fProject, lineNumber, desc, severity, varName);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
fMarkerGenerator.addMarker(file, lineNumber, desc, severity, varName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the error parsers. Return the previous line, save in the working buffer.
|
|
||||||
*/
|
|
||||||
public String getPreviousLine() {
|
|
||||||
return new String ((previousLine) == null ? "" : previousLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the error parsers. Overload in Makebuilder.
|
|
||||||
*/
|
|
||||||
public IPath getBuildCommand() {
|
|
||||||
return new Path("");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,6 +5,8 @@ package org.eclipse.cdt.internal.errorparsers;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.eclipse.cdt.errorparsers.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.errorparsers.IErrorParser;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ package org.eclipse.cdt.internal.errorparsers;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.eclipse.cdt.errorparsers.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.errorparsers.IErrorParser;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ public class GCCErrorParser implements IErrorParser {
|
||||||
String fileName = line.substring(0, firstColon);
|
String fileName = line.substring(0, firstColon);
|
||||||
String lineNumber = line.substring(firstColon + 1, secondColon);
|
String lineNumber = line.substring(firstColon + 1, secondColon);
|
||||||
String varName = null;
|
String varName = null;
|
||||||
String desc = line.substring(secondColon + 2);
|
String desc = line.substring(secondColon + 1).trim();
|
||||||
int severity = IMarker.SEVERITY_ERROR;
|
int severity = IMarker.SEVERITY_ERROR;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ package org.eclipse.cdt.internal.errorparsers;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.eclipse.cdt.errorparsers.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.errorparsers.IErrorParser;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ package org.eclipse.cdt.internal.errorparsers;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.eclipse.cdt.errorparsers.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.errorparsers.IErrorParser;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class MakeErrorParser implements IErrorParser {
|
public class MakeErrorParser implements IErrorParser {
|
||||||
|
|
|
@ -8,6 +8,8 @@ package org.eclipse.cdt.internal.errorparsers;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.errorparsers.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.errorparsers.IErrorParser;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,6 @@ public class CPlugin extends AbstractUIPlugin {
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
Display.getDefault().syncExec(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
fDocument.set("");
|
fDocument.set("");
|
||||||
fContent.setLength(0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -172,7 +171,7 @@ public class CPlugin extends AbstractUIPlugin {
|
||||||
bringConsoleOnTop();
|
bringConsoleOnTop();
|
||||||
try {
|
try {
|
||||||
int len = fDocument.getLength ();
|
int len = fDocument.getLength ();
|
||||||
fDocument.replace(len, 0, getContent(len));
|
fDocument.replace(len, 0, readBuffer());
|
||||||
} catch (BadLocationException x) {
|
} catch (BadLocationException x) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,37 +206,6 @@ public class CPlugin extends AbstractUIPlugin {
|
||||||
public CPlugin(IPluginDescriptor descriptor) {
|
public CPlugin(IPluginDescriptor descriptor) {
|
||||||
super(descriptor);
|
super(descriptor);
|
||||||
fgCPlugin= this;
|
fgCPlugin= this;
|
||||||
/*
|
|
||||||
fModel = new ACDebugModel() {
|
|
||||||
public Object createPresentation() {
|
|
||||||
return new CDebugModelPresentation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdentifier() {
|
|
||||||
return PLUGIN_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IMarker createBreakpoint( final IResource resource,
|
|
||||||
final Map attributes,
|
|
||||||
final String markerType ) throws CoreException {
|
|
||||||
|
|
||||||
class BreakpointRunnable implements IWorkspaceRunnable {
|
|
||||||
IMarker fBreakpoint = null;
|
|
||||||
|
|
||||||
public void run( IProgressMonitor monitor ) throws CoreException
|
|
||||||
{
|
|
||||||
fBreakpoint = resource.createMarker( markerType );
|
|
||||||
fBreakpoint.setAttributes( attributes );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
BreakpointRunnable r = new BreakpointRunnable();
|
|
||||||
|
|
||||||
resource.getWorkspace().run( r, null );
|
|
||||||
|
|
||||||
return r.fBreakpoint;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
fConsoleDocument= new ConsoleDocument();
|
fConsoleDocument= new ConsoleDocument();
|
||||||
fDocumentProvider= null;
|
fDocumentProvider= null;
|
||||||
fTextTools= null;
|
fTextTools= null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue