mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
PR: 215492 - moved to external package
This commit is contained in:
parent
c1438bceb5
commit
8e64dbaaa5
9 changed files with 240 additions and 172 deletions
|
@ -21,6 +21,7 @@ Export-Package: org.eclipse.cdt.core,
|
||||||
org.eclipse.cdt.core.dom.parser.cpp,
|
org.eclipse.cdt.core.dom.parser.cpp,
|
||||||
org.eclipse.cdt.core.dom.rewrite,
|
org.eclipse.cdt.core.dom.rewrite,
|
||||||
org.eclipse.cdt.core.envvar,
|
org.eclipse.cdt.core.envvar,
|
||||||
|
org.eclipse.cdt.core.errorparsers,
|
||||||
org.eclipse.cdt.core.formatter,
|
org.eclipse.cdt.core.formatter,
|
||||||
org.eclipse.cdt.core.index,
|
org.eclipse.cdt.core.index,
|
||||||
org.eclipse.cdt.core.index.export,
|
org.eclipse.cdt.core.index.export,
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2006, 2007 QNX Software Systems 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:
|
||||||
|
* QNX - initial API and implementation, @author Doug Schaefer
|
||||||
|
* Warren Paul (Nokia) - Bug 178124, have processLine return true if processed.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.core.errorparsers;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.core.IErrorParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract Error Parser that implements simple line processing using patterns array
|
||||||
|
*/
|
||||||
|
public class AbstractErrorParser implements IErrorParser {
|
||||||
|
|
||||||
|
private ErrorPattern[] patterns;
|
||||||
|
|
||||||
|
protected AbstractErrorParser(ErrorPattern[] patterns) {
|
||||||
|
this.patterns = patterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param line - line of the input
|
||||||
|
* @param epManager - error parsers manager
|
||||||
|
* @return true if error parser recognized and accepted line, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean processLine(String line, ErrorParserManager epManager) {
|
||||||
|
for (int i = 0; i < patterns.length; ++i)
|
||||||
|
if (patterns[i].processLine(line, epManager))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2006, 2007 QNX Software Systems 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:
|
||||||
|
* QNX - initial API and implementation, @author Doug Schaefer
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.core.errorparsers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.utils.CygPath;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error Pattern - used by Error Parser to convert build output to problem markers
|
||||||
|
*/
|
||||||
|
public class ErrorPattern {
|
||||||
|
private final Pattern pattern;
|
||||||
|
private final int groupFileName;
|
||||||
|
private final int groupLineNum;
|
||||||
|
private final int groupDesc;
|
||||||
|
private final int groupVarName;
|
||||||
|
private final int severity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full Pattern Constructor.
|
||||||
|
*
|
||||||
|
* @param pattern
|
||||||
|
* @param groupFileName
|
||||||
|
* @param groupLineNum
|
||||||
|
* @param groupDesc
|
||||||
|
* @param groupVarName
|
||||||
|
* @param severity
|
||||||
|
*/
|
||||||
|
public ErrorPattern(String pattern,
|
||||||
|
int groupFileName,
|
||||||
|
int groupLineNum,
|
||||||
|
int groupDesc,
|
||||||
|
int groupVarName,
|
||||||
|
int severity) {
|
||||||
|
this.pattern = Pattern.compile(pattern);
|
||||||
|
this.groupFileName = groupFileName;
|
||||||
|
this.groupLineNum = groupLineNum;
|
||||||
|
this.groupDesc = groupDesc;
|
||||||
|
this.groupVarName = groupVarName;
|
||||||
|
this.severity = severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pattern for errors not associated file a file
|
||||||
|
* (e.g. make and linker errors).
|
||||||
|
*
|
||||||
|
* @param pattern
|
||||||
|
* @param groupDesc
|
||||||
|
* @param severity
|
||||||
|
*/
|
||||||
|
public ErrorPattern(String pattern, int groupDesc, int severity) {
|
||||||
|
this(pattern, 0, 0, groupDesc, 0, severity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pattern for errors that should be skipped.
|
||||||
|
*
|
||||||
|
* @param pattern
|
||||||
|
*/
|
||||||
|
public ErrorPattern(String pattern) {
|
||||||
|
this(pattern, 0, 0, 0, 0, -1);
|
||||||
|
}
|
||||||
|
public Matcher getMatcher(CharSequence input) {
|
||||||
|
return pattern.matcher(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName(Matcher matcher) {
|
||||||
|
return groupFileName != 0 ? matcher.group(groupFileName) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLineNum(Matcher matcher) {
|
||||||
|
try {
|
||||||
|
return groupLineNum != 0
|
||||||
|
? Integer.valueOf(matcher.group(groupLineNum)).intValue()
|
||||||
|
: 0;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc(Matcher matcher) {
|
||||||
|
return groupDesc != 0 ? matcher.group(groupDesc) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVarName(Matcher matcher) {
|
||||||
|
return groupVarName != 0 ? matcher.group(groupVarName) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeverity(Matcher matcher) {
|
||||||
|
return severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean processLine(String line, ErrorParserManager eoParser) {
|
||||||
|
Matcher matcher = getMatcher(line);
|
||||||
|
if (!matcher.find())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return recordError(matcher, eoParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean recordError(Matcher matcher, ErrorParserManager eoParser) {
|
||||||
|
int severity = getSeverity(matcher);
|
||||||
|
if (severity == -1)
|
||||||
|
// Skip
|
||||||
|
return true;
|
||||||
|
|
||||||
|
String fileName = getFileName(matcher);
|
||||||
|
int lineNum = getLineNum(matcher);
|
||||||
|
String desc = getDesc(matcher);
|
||||||
|
String varName = getVarName(matcher);
|
||||||
|
IPath externalPath = null ;
|
||||||
|
|
||||||
|
IResource file = null;
|
||||||
|
if (fileName != null) {
|
||||||
|
file = eoParser.findFileName(fileName);
|
||||||
|
if (file == null) {
|
||||||
|
file = eoParser.findFilePath(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
// If the file is not found in the workspace we attach the problem to the project
|
||||||
|
// and add the external path to the file.
|
||||||
|
desc = fileName + " " + desc; //$NON-NLS-1$
|
||||||
|
file = eoParser.getProject();
|
||||||
|
externalPath = getLocation(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eoParser.generateExternalMarker(file, lineNum, desc, severity, varName, externalPath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the file designated by filename exists, return the IPath representation of the filename
|
||||||
|
* If it does not exist, try cygpath translation
|
||||||
|
*/
|
||||||
|
protected IPath getLocation(String filename) {
|
||||||
|
IPath path = new Path(filename);
|
||||||
|
File file = path.toFile() ;
|
||||||
|
if (!file.exists()) {
|
||||||
|
CygPath cygpath = null ;
|
||||||
|
try {
|
||||||
|
cygpath = new CygPath("cygpath"); //$NON-NLS-1$
|
||||||
|
String cygfilename = cygpath.getFileName(filename);
|
||||||
|
path = new Path(cygfilename);
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (null!=cygpath) {
|
||||||
|
cygpath.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,30 +7,19 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - initial API and implementation
|
* QNX - initial API and implementation
|
||||||
* Warren Paul (Nokia) - Bug 178124, have processLine return true if processed.
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.errorparsers;
|
package org.eclipse.cdt.internal.errorparsers;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.ErrorParserManager;
|
import org.eclipse.cdt.core.errorparsers.ErrorPattern;
|
||||||
import org.eclipse.cdt.core.IErrorParser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @deprecated use org.eclipse.cdt.core.errorparsers.AbstractErrorParser
|
||||||
*
|
* this class is moved to public package
|
||||||
*/
|
*/
|
||||||
public class AbstractErrorParser implements IErrorParser {
|
@Deprecated
|
||||||
|
public class AbstractErrorParser extends org.eclipse.cdt.core.errorparsers.AbstractErrorParser{
|
||||||
private ErrorPattern[] patterns;
|
|
||||||
|
|
||||||
protected AbstractErrorParser(ErrorPattern[] patterns) {
|
protected AbstractErrorParser(ErrorPattern[] patterns) {
|
||||||
this.patterns = patterns;
|
super(patterns);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean processLine(String line, ErrorParserManager eoParser) {
|
|
||||||
for (int i = 0; i < patterns.length; ++i)
|
|
||||||
if (patterns[i].processLine(line, eoParser))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,168 +8,24 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - initial API and implementation
|
* QNX - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.errorparsers;
|
package org.eclipse.cdt.internal.errorparsers;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.ErrorParserManager;
|
|
||||||
import org.eclipse.cdt.utils.CygPath;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @deprecated use org.eclipse.cdt.core.errorparsers.ErrorPattern
|
||||||
*
|
* this class is moved to public package
|
||||||
*/
|
*/
|
||||||
public class ErrorPattern {
|
@Deprecated
|
||||||
private final Pattern pattern;
|
public class ErrorPattern extends org.eclipse.cdt.core.errorparsers.ErrorPattern {
|
||||||
private final int groupFileName;
|
public ErrorPattern(String pattern, int groupFileName, int groupLineNum, int groupDesc, int groupVarName,
|
||||||
private final int groupLineNum;
|
int severity) {
|
||||||
private final int groupDesc;
|
super(pattern, groupFileName, groupLineNum, groupDesc, groupVarName, severity);
|
||||||
private final int groupVarName;
|
|
||||||
private final int severity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Full Pattern Constructor.
|
|
||||||
*
|
|
||||||
* @param pattern
|
|
||||||
* @param groupFileName
|
|
||||||
* @param groupLineNum
|
|
||||||
* @param groupDesc
|
|
||||||
* @param groupVarName
|
|
||||||
* @param severity
|
|
||||||
*/
|
|
||||||
public ErrorPattern(String pattern,
|
|
||||||
int groupFileName,
|
|
||||||
int groupLineNum,
|
|
||||||
int groupDesc,
|
|
||||||
int groupVarName,
|
|
||||||
int severity) {
|
|
||||||
this.pattern = Pattern.compile(pattern);
|
|
||||||
this.groupFileName = groupFileName;
|
|
||||||
this.groupLineNum = groupLineNum;
|
|
||||||
this.groupDesc = groupDesc;
|
|
||||||
this.groupVarName = groupVarName;
|
|
||||||
this.severity = severity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pattern for errors not associated file a file
|
|
||||||
* (e.g. make and linker errors).
|
|
||||||
*
|
|
||||||
* @param pattern
|
|
||||||
* @param groupDesc
|
|
||||||
* @param severity
|
|
||||||
*/
|
|
||||||
public ErrorPattern(String pattern, int groupDesc, int severity) {
|
public ErrorPattern(String pattern, int groupDesc, int severity) {
|
||||||
this(pattern, 0, 0, groupDesc, 0, severity);
|
super(pattern, groupDesc, severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pattern for errors that should be skipped.
|
|
||||||
*
|
|
||||||
* @param pattern
|
|
||||||
*/
|
|
||||||
public ErrorPattern(String pattern) {
|
public ErrorPattern(String pattern) {
|
||||||
this(pattern, 0, 0, 0, 0, -1);
|
super(pattern);
|
||||||
}
|
}
|
||||||
public Matcher getMatcher(CharSequence input) {
|
|
||||||
return pattern.matcher(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileName(Matcher matcher) {
|
|
||||||
return groupFileName != 0 ? matcher.group(groupFileName) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLineNum(Matcher matcher) {
|
|
||||||
try {
|
|
||||||
return groupLineNum != 0
|
|
||||||
? Integer.valueOf(matcher.group(groupLineNum)).intValue()
|
|
||||||
: 0;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc(Matcher matcher) {
|
|
||||||
return groupDesc != 0 ? matcher.group(groupDesc) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVarName(Matcher matcher) {
|
|
||||||
return groupVarName != 0 ? matcher.group(groupVarName) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSeverity(Matcher matcher) {
|
|
||||||
return severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean processLine(String line, ErrorParserManager eoParser) {
|
|
||||||
Matcher matcher = getMatcher(line);
|
|
||||||
if (!matcher.find())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return recordError(matcher, eoParser);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean recordError(Matcher matcher, ErrorParserManager eoParser) {
|
|
||||||
int severity = getSeverity(matcher);
|
|
||||||
if (severity == -1)
|
|
||||||
// Skip
|
|
||||||
return true;
|
|
||||||
|
|
||||||
String fileName = getFileName(matcher);
|
|
||||||
int lineNum = getLineNum(matcher);
|
|
||||||
String desc = getDesc(matcher);
|
|
||||||
String varName = getVarName(matcher);
|
|
||||||
IPath externalPath = null ;
|
|
||||||
|
|
||||||
IResource file = null;
|
|
||||||
if (fileName != null) {
|
|
||||||
file = eoParser.findFileName(fileName);
|
|
||||||
if (file == null) {
|
|
||||||
file = eoParser.findFilePath(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file == null) {
|
|
||||||
// If the file is not found in the workspace we attach the problem to the project
|
|
||||||
// and add the external path to the file.
|
|
||||||
desc = fileName + " " + desc; //$NON-NLS-1$
|
|
||||||
file = eoParser.getProject();
|
|
||||||
externalPath = getLocation(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eoParser.generateExternalMarker(file, lineNum, desc, severity, varName, externalPath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the file designated by filename exists, return the IPath representation of the filename
|
|
||||||
* If it does not exist, try cygpath translation
|
|
||||||
*/
|
|
||||||
protected IPath getLocation(String filename) {
|
|
||||||
IPath path = new Path(filename);
|
|
||||||
File file = path.toFile() ;
|
|
||||||
if (!file.exists()) {
|
|
||||||
CygPath cygpath = null ;
|
|
||||||
try {
|
|
||||||
cygpath = new CygPath("cygpath"); //$NON-NLS-1$
|
|
||||||
String cygfilename = cygpath.getFileName(filename);
|
|
||||||
path = new Path(cygfilename);
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (null!=cygpath) {
|
|
||||||
cygpath.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return path ;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.AbstractErrorParser;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.ErrorPattern;
|
||||||
|
|
||||||
public class GCCErrorParser extends AbstractErrorParser {
|
public class GCCErrorParser extends AbstractErrorParser {
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
package org.eclipse.cdt.internal.errorparsers;
|
package org.eclipse.cdt.internal.errorparsers;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.AbstractErrorParser;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.ErrorPattern;
|
||||||
|
|
||||||
public class GLDErrorParser extends AbstractErrorParser {
|
public class GLDErrorParser extends AbstractErrorParser {
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ import java.util.regex.Matcher;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.ErrorParserManager;
|
import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.AbstractErrorParser;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.ErrorPattern;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class MakeErrorParser extends AbstractErrorParser {
|
public class MakeErrorParser extends AbstractErrorParser {
|
||||||
|
|
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.errorparsers;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.AbstractErrorParser;
|
||||||
|
import org.eclipse.cdt.core.errorparsers.ErrorPattern;
|
||||||
|
|
||||||
public class VCErrorParser extends AbstractErrorParser {
|
public class VCErrorParser extends AbstractErrorParser {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue