Skip to content

Commit

Permalink
Add Fatal error and add short error detection to the parser.
Browse files Browse the repository at this point in the history
leave the false positive because that is not the case.  this regular expression makes sure the hits are better.
  • Loading branch information
kvdz authored May 23, 2017
1 parent fa1777d commit c234b94
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions src/main/java/edu/hm/hafner/analysis/parser/IarParser.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hudson.plugins.warnings.parser;

import java.util.regex.Matcher;
import java.util.*;

import hudson.Extension;

import hudson.plugins.analysis.util.model.Priority;

/**
Expand All @@ -14,27 +14,30 @@
*
* @author Claus Klein
* @author Ulli Hafner
* @author Kay van der Zander
*/
@Extension
public class IarParser extends RegexpLineParser {
private static final long serialVersionUID = 7695540852439013425L;

private static final String IAR_WARNING_PATTERN =
"^(?:\\[.*\\]\\s*)?\\\"?(.*?)\\\"?(?:,|\\()(\\d+)(?:\\s*|\\)\\s*:\\s*)(Error|Remark|Warning|Fatal error)\\[(\\w+)\\]: (.*)$";

private static int GROUP_NUMBER = 5;

// search for: Fatal Error[Pe1696]: cannot open source file "c:\filename.c"
// search for: c:\filename.h(17) : Fatal Error[Pe1696]: cannot open source file "System/ProcDef_LPC17xx.h"
private static final String IAR_WARNING_PATTERN =
"((\\[exec\\] )?(.*)\\((\\d+)\\)?.*)?(Fatal [Ee]rror|Remark|Warning)\\[(\\w+)\\]: (.*(\\\".*(c|h)\\\")|.*)";
/**
* Creates a new instance of {@link IarParser}.
*/
public IarParser() {
super(Messages._Warnings_iar_ParserName(),
Messages._Warnings_iar_LinkName(),
Messages._Warnings_iar_TrendName(),
IAR_WARNING_PATTERN, true);
IAR_WARNING_PATTERN);
}

@Override
protected boolean isLineInteresting(final String line) {
return line.contains("Warning") || line.contains("rror") || line.contains("Remark");
return line.contains("Warning") || line.contains("rror") || line.contains("Remark") || line.contains("[");
}

@Override
Expand All @@ -45,26 +48,30 @@ protected String getId() {
@Override
protected Warning createWarning(final Matcher matcher) {
Priority priority;
if ("Remark".equals(matcher.group(3))) {
priority = Priority.LOW;
}
else if ("Warning".equals(matcher.group(3))) {
priority = Priority.NORMAL;
}
else if ("Error".equals(matcher.group(3))) {
priority = Priority.HIGH;
}
else if ("Fatal error".equals(matcher.group(3))) {
priority = Priority.HIGH;
}
else {
return FALSE_POSITIVE;

priority = determinePriority(matcher.group(GROUP_NUMBER));
return composeWarning(matcher, priority);
}

private Warning composeWarning(final Matcher matcher, final Priority priority) {
String message = matcher.group(7);

if( matcher.group(3) == null ) {
// createWarning( filename, line number, error number (Pe177), message, priority )
return createWarning(matcher.group(8), 0, matcher.group(6), message, priority);
}
String message = normalizeWhitespaceInMessage(matcher.group(5));
return createWarning(matcher.group(1), getLineNumber(matcher.group(2)), matcher.group(4), message, priority);
// createWarning( filename, line number, error number (Pe177), message, priority )
return createWarning(matcher.group(3), getLineNumber(matcher.group(4)), matcher.group(6), message, priority);
}

private String normalizeWhitespaceInMessage(final String message) {
return message.replaceAll("\\s+", " ");

private Priority determinePriority(final String message) {
// for "Fatal error", "Fatal Error", "Error" and "error" and "warning"
if (message.toLowerCase().contains("error")) {
return Priority.HIGH;
} else if (message.toLowerCase().contains("warning")) {
return Priority.NORMAL;
} else {
return Priority.LOW;
}
}
}

0 comments on commit c234b94

Please sign in to comment.