Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-19047] Use column position in parsers when available.
  • Loading branch information
uhafner committed Aug 16, 2013
1 parent 390dc75 commit c11874ad9fa96a87891c031b07c1e8ce2bd85728
@@ -14,7 +14,7 @@
@Extension
public class ClangParser extends RegexpLineParser {
private static final long serialVersionUID = -3015592762345283182L;
private static final String CLANG_WARNING_PATTERN = "^\\s*(?:\\d+%)?([^%]*?):(\\d+):(?:\\d+:)?(?:(?:\\{\\d+:\\d+-\\d+:\\d+\\})+:)?\\s*(warning|.*error):\\s*(.*?)(?:\\[(.*)\\])?$";
private static final String CLANG_WARNING_PATTERN = "^\\s*(?:\\d+%)?([^%]*?):(\\d+):(?:(\\d+):)?(?:(?:\\{\\d+:\\d+-\\d+:\\d+\\})+:)?\\s*(warning|.*error):\\s*(.*?)(?:\\[(.*)\\])?$";

/**
* Creates a new instance of {@link ClangParser}.
@@ -30,9 +30,10 @@ public ClangParser() {
protected Warning createWarning(final Matcher matcher) {
String filename = matcher.group(1);
int lineNumber = getLineNumber(matcher.group(2));
String type = matcher.group(3);
String message = matcher.group(4);
String category = matcher.group(5);
int column = getLineNumber(matcher.group(3));
String type = matcher.group(4);
String message = matcher.group(5);
String category = matcher.group(6);

Priority priority;
if (type.contains("error")) {
@@ -41,11 +42,15 @@ protected Warning createWarning(final Matcher matcher) {
else {
priority = Priority.NORMAL;
}
Warning warning;
if (category == null) {
return createWarning(filename, lineNumber, message, priority);
warning = createWarning(filename, lineNumber, message, priority);
}

return createWarning(filename, lineNumber, category, message, priority);
else {
warning = createWarning(filename, lineNumber, category, message, priority);
}
warning.setColumnPosition(column);
return warning;
}

@Override
@@ -16,7 +16,7 @@
public class Gcc4CompilerParser extends RegexpLineParser {
private static final long serialVersionUID = 5490211629355204910L;
private static final String ERROR = "error";
private static final String GCC_WARNING_PATTERN = ANT_TASK + "(.+?):(\\d+):(?:\\d+:)? (warning|.*error): (.*)$";
private static final String GCC_WARNING_PATTERN = ANT_TASK + "(.+?):(\\d+):(?:(\\d+):)? (warning|.*error): (.*)$";
private static final Pattern CLASS_PATTERN = Pattern.compile("\\[-W(.+)\\]$");

/**
@@ -38,11 +38,12 @@ protected String getId() {
protected Warning createWarning(final Matcher matcher) {
String fileName = matcher.group(1);
int lineNumber = getLineNumber(matcher.group(2));
String message = matcher.group(4);
int column = getLineNumber(matcher.group(3));
String message = matcher.group(5);
Priority priority;

StringBuilder category = new StringBuilder();
if (matcher.group(3).contains(ERROR)) {
if (matcher.group(4).contains(ERROR)) {
priority = Priority.HIGH;
category.append("Error");
}
@@ -56,7 +57,9 @@ protected Warning createWarning(final Matcher matcher) {
}
}

return createWarning(fileName, lineNumber, category.toString(), message, priority);
Warning warning = createWarning(fileName, lineNumber, category.toString(), message, priority);
warning.setColumnPosition(column);
return warning;
}
}

@@ -16,7 +16,7 @@
@Extension
public class IntelCParser extends RegexpLineParser {
private static final long serialVersionUID = 8409744276858003050L;
private static final String INTEL_PATTERN = "^(.*)\\((\\d*)\\)?:.*((?:remark|warning|error)\\s*#*\\d*)\\s*:\\s*(.*)$";
private static final String INTEL_PATTERN = "^(.*)\\((\\d*)\\)?:(?:\\s*\\(col\\. (\\d+)\\))?.*((?:remark|warning|error)\\s*#*\\d*)\\s*:\\s*(.*)$";

/**
* Creates a new instance of {@link IntelCParser}.
@@ -42,7 +42,7 @@ protected boolean isLineInteresting(final String line) {

@Override
protected Warning createWarning(final Matcher matcher) {
String category = StringUtils.capitalize(matcher.group(3));
String category = StringUtils.capitalize(matcher.group(4));

Priority priority;
if (StringUtils.startsWith(category, "Remark")) {
@@ -55,7 +55,9 @@ else if (StringUtils.startsWith(category, "Error")) {
priority = Priority.NORMAL;
}

return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, matcher.group(4), priority);
Warning warning = createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, matcher.group(5), priority);
warning.setColumnPosition(getLineNumber(matcher.group(3)));
return warning;
}
}

@@ -17,7 +17,7 @@ public class JavacParser extends RegexpLineParser {
static final String JAVA_LARGE_ICON = WarningsDescriptor.IMAGE_PREFIX + "java-48x48.png";

private static final long serialVersionUID = 7199325311690082782L;
private static final String JAVAC_WARNING_PATTERN = "^(?:\\[WARNING\\]\\s+)?([^\\[]*):\\[(\\d+)[.,; 0-9]*\\]\\s*(?:\\[(\\w+)\\])?\\s*(.*)$";
private static final String JAVAC_WARNING_PATTERN = "^(?:\\[WARNING\\]\\s+)?([^\\[]*):\\[(\\d+)[.,;]*(\\d+)?\\]\\s*(?:\\[(\\w+)\\])?\\s*(.*)$";

/**
* Creates a new instance of {@link JavacParser}.
@@ -36,10 +36,12 @@ protected boolean isLineInteresting(final String line) {

@Override
protected Warning createWarning(final Matcher matcher) {
String message = matcher.group(4);
String category = classifyIfEmpty(matcher.group(3), message);
String message = matcher.group(5);
String category = classifyIfEmpty(matcher.group(4), message);

return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message);
Warning warning = createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message);
warning.setColumnPosition(getLineNumber(matcher.group(3)));
return warning;
}

@Override
@@ -18,7 +18,7 @@
public class MsBuildParser extends RegexpLineParser {
private static final long serialVersionUID = -2141974437420906595L;
static final String WARNING_TYPE = "MSBuild";
private static final String MS_BUILD_WARNING_PATTERN = ANT_TASK + "(?:\\s*\\d+>)?(?:(?:(?:(.*)\\((\\d*).*\\)|.*LINK)\\s*:|(.*):)\\s*([Nn]ote|[Ii]nfo|[Ww]arning|(?:fatal\\s*)?[Ee]rror)\\s*:?\\s*([A-Za-z0-9]+):\\s*(.*)|(.*)\\s*:.*error\\s*(LNK[0-9]+):\\s*(.*))$";
private static final String MS_BUILD_WARNING_PATTERN = ANT_TASK + "(?:\\s*\\d+>)?(?:(?:(?:(.*)\\((\\d*)(?:,(\\d+))?.*\\)|.*LINK)\\s*:|(.*):)\\s*([Nn]ote|[Ii]nfo|[Ww]arning|(?:fatal\\s*)?[Ee]rror)\\s*:?\\s*([A-Za-z0-9]+):\\s*(.*)|(.*)\\s*:.*error\\s*(LNK[0-9]+):\\s*(.*))$";

/**
* Creates a new instance of {@link MsBuildParser}.
@@ -46,12 +46,14 @@ public MsBuildParser(final Localizable parserName, final Localizable linkName, f
@Override
protected Warning createWarning(final Matcher matcher) {
String fileName = determineFileName(matcher);
if (StringUtils.isNotBlank(matcher.group(7))) {
return createWarning(fileName, 0, matcher.group(8), matcher.group(9), Priority.HIGH);
if (StringUtils.isNotBlank(matcher.group(8))) {
return createWarning(fileName, 0, matcher.group(9), matcher.group(10), Priority.HIGH);
}
else {
return createWarning(fileName, getLineNumber(matcher.group(2)),
matcher.group(5), matcher.group(6), determinePriority(matcher));
Warning warning = createWarning(fileName, getLineNumber(matcher.group(2)),
matcher.group(6), matcher.group(7), determinePriority(matcher));
warning.setColumnPosition(getLineNumber(matcher.group(3)));
return warning;
}
}

@@ -64,17 +66,17 @@ protected Warning createWarning(final Matcher matcher) {
*/
private String determineFileName(final Matcher matcher) {
String fileName;
if (StringUtils.isNotBlank(matcher.group(3))) {
fileName = matcher.group(3);
if (StringUtils.isNotBlank(matcher.group(4))) {
fileName = matcher.group(4);
}
else if (StringUtils.isNotBlank(matcher.group(7))) {
fileName = matcher.group(7);
else if (StringUtils.isNotBlank(matcher.group(8))) {
fileName = matcher.group(8);
}
else {
fileName = matcher.group(1);
}
if (StringUtils.isBlank(fileName)) {
fileName = StringUtils.substringBetween(matcher.group(6), "'");
fileName = StringUtils.substringBetween(matcher.group(7), "'");
}
if (StringUtils.isBlank(fileName)) {
fileName = "unknown.file";
@@ -109,7 +111,7 @@ else if (isOfType(matcher, "warning")) {
* @return <code>true</code> if the warning type is of the specified type
*/
private boolean isOfType(final Matcher matcher, final String type) {
return StringUtils.containsIgnoreCase(matcher.group(4), type);
return StringUtils.containsIgnoreCase(matcher.group(5), type);
}
}

@@ -15,7 +15,7 @@
public class Pep8Parser extends RegexpLineParser {
private static final long serialVersionUID = -8444940209330966997L;

private static final String PEP8_WARNING_PATTERN = "(.*):(\\d+):\\d+: (\\D\\d*) (.*)";
private static final String PEP8_WARNING_PATTERN = "(.*):(\\d+):(\\d+): (\\D\\d*) (.*)";

/**
* Creates a new instance of {@link Pep8Parser}.
@@ -29,10 +29,12 @@ public Pep8Parser() {

@Override
protected Warning createWarning(final Matcher matcher) {
String message = matcher.group(4);
String category = classifyIfEmpty(matcher.group(3), message);
String message = matcher.group(5);
String category = classifyIfEmpty(matcher.group(4), message);

return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message, mapPriority(category));
Warning warning = createWarning(matcher.group(1), getLineNumber(matcher.group(2)), category, message, mapPriority(category));
warning.setColumnPosition(getLineNumber(matcher.group(3)));
return warning;
}

@Override
@@ -33,7 +33,7 @@ public void issue18084() throws IOException {

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size());
FileAnnotation annotation = warnings.iterator().next();
checkWarning(annotation, 10, "'test.h' file not found",
checkWarning(annotation, 10, 10, "'test.h' file not found",
"./test.h", StringUtils.EMPTY, Priority.HIGH);
}

@@ -50,7 +50,7 @@ public void issue14333() throws IOException {

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size());
FileAnnotation annotation = warnings.iterator().next();
checkWarning(annotation, 1518, "Array access (via field 'yy_buffer_stack') results in a null pointer dereference",
checkWarning(annotation, 1518, 28, "Array access (via field 'yy_buffer_stack') results in a null pointer dereference",
"scanner.cpp", StringUtils.EMPTY, Priority.NORMAL);
}

@@ -69,13 +69,13 @@ public void testWarningsParser() throws IOException {
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
28,
28, 8,
"extra tokens at end of #endif directive",
"test.c",
TYPE, "-Wextra-tokens", Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
28,
28, 8,
"extra tokens at end of #endif directive",
"/path/to/test.c",
TYPE, "-Wextra-tokens", Priority.NORMAL);
@@ -93,26 +93,26 @@ public void testWarningsParser() throws IOException {
TYPE, "", Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
3,
3, 11,
"conversion specifies type 'char *' but the argument has type 'int'",
"t.c",
TYPE, "-Wformat", Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
3,
3, 11,
"conversion specifies type 'char *' but the argument has type 'int'",
"t.c",
TYPE, "-Wformat,1", Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
3,
3, 11,
"conversion specifies type 'char *' but the argument has type 'int'",
"t.c",
TYPE, "-Wformat,Format String", Priority.NORMAL);

annotation = iterator.next();
checkWarning(annotation,
47,
47, 15,
"invalid operands to binary expression ('int *' and '_Complex float')",
"exprs.c",
TYPE, "", Priority.NORMAL);
@@ -94,7 +94,7 @@ public void testWarningsParser() throws IOException {
"/u1/drjohn/bfdist/packages/RegrTest/V00-03-01/RgtAddressLineScan.cc",
WARNING_TYPE, ERROR_CATEGORY, Priority.HIGH);
checkWarning(iterator.next(),
4,
4, 39,
"foo.h: No such file or directory",
"foo.cc",
WARNING_TYPE, ERROR_CATEGORY, Priority.HIGH);
@@ -32,14 +32,14 @@ public void testWarningsParser() throws IOException {
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
1460,
1460, 20,
"LOOP WAS VECTORIZED.",
"D:/Hudson/workspace/foo/busdates.cpp",
TYPE, "Remark", Priority.LOW);
annotation = iterator.next();
// remark
checkWarning(annotation,
2630,
2630, 15,
"FUSED LOOP WAS VECTORIZED.",
"D:/Hudson/workspace/foo/hols.cpp",
TYPE, "Remark", Priority.LOW);
@@ -65,13 +65,13 @@ public void parseDeprecation() throws IOException {
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
12,
12, 39,
"org.eclipse.jface.contentassist.SubjectControlContentAssistant in org.eclipse.jface.contentassist has been deprecated",
"C:/Build/Results/jobs/ADT-Base/workspace/com.avaloq.adt.ui/src/main/java/com/avaloq/adt/ui/elements/AvaloqDialog.java",
WARNING_TYPE, RegexpParser.DEPRECATION, Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
40,
40, 36,
"org.eclipse.ui.contentassist.ContentAssistHandler in org.eclipse.ui.contentassist has been deprecated",
"C:/Build/Results/jobs/ADT-Base/workspace/com.avaloq.adt.ui/src/main/java/com/avaloq/adt/ui/elements/AvaloqDialog.java",
WARNING_TYPE, RegexpParser.DEPRECATION, Priority.NORMAL);
@@ -192,7 +192,7 @@ public void parseWarnings() throws IOException {
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation annotation = iterator.next();
checkWarning(annotation,
2242,
2242, 17,
"The variable 'type' is declared but never used",
"Src/Parser/CSharp/cs.ATG",
MsBuildParser.WARNING_TYPE, "CS0168", Priority.NORMAL);
@@ -210,7 +210,7 @@ public void parseWarnings() throws IOException {
MsBuildParser.WARNING_TYPE, "CS0618", Priority.NORMAL);
annotation = iterator.next();
checkWarning(annotation,
3001,
3001, 5,
"Hier kommt der Warnings Text",
"MediaPortal.cs",
MsBuildParser.WARNING_TYPE, "CS0162", Priority.NORMAL);
@@ -31,22 +31,22 @@ public void testParseSimpleAndComplexMessage() throws IOException {
Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation warning = iterator.next();

checkWarning(warning, 1, "trailing whitespace", "trunk/src/python/file.py",
checkWarning(warning, 1, 2, "trailing whitespace", "trunk/src/python/file.py",
WARNING_TYPE, "W291", Priority.HIGH);

warning = iterator.next();

checkWarning(warning, 98, "Message #has! 12special-_ chars|?.",
checkWarning(warning, 98, 11, "Message #has! 12special-_ chars|?.",
"trunk/src/python/file.py", WARNING_TYPE, "E111", Priority.HIGH);

warning = iterator.next();

checkWarning(warning, 98, "Message #has! 12special-_ chars|?.",
checkWarning(warning, 98, 11, "Message #has! 12special-_ chars|?.",
"trunk2/src/python/file.py", WARNING_TYPE, "R111", Priority.NORMAL);

warning = iterator.next();

checkWarning(warning, 98, "Message #has! 12special-_ chars|?.",
checkWarning(warning, 98, 11, "Message #has! 12special-_ chars|?.",
"trunk3/src/python/file.py", WARNING_TYPE, "C111", Priority.LOW);
}

0 comments on commit c11874a

Please sign in to comment.