forked from jenkinsci/analysis-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IarParser.java
67 lines (58 loc) · 2.23 KB
/
IarParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package edu.hm.hafner.analysis.parser;
import java.util.Optional;
import java.util.regex.Matcher;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.RegexpLineParser;
import edu.hm.hafner.analysis.Severity;
/**
* A parser for the IAR C/C++ compiler warnings. Note, that since release 4.1 this parser requires that IAR compilers
* are started with option '----no_wrap_diagnostics'. Then the IAR compilers will create single-line warnings.
*
* @author Claus Klein
* @author Ullrich Hafner
* @author Jon Ware
*/
public class IarParser extends RegexpLineParser {
private static final long serialVersionUID = 7695540852439013425L;
static final String IAR_WARNING_PATTERN = ANT_TASK
+ "(?:\"?(.*?)\"?[\\(,](\\d+)\\)?\\s+(?::\\s)?)?(Error|Remark|Warning|Fatal [Ee]rror)\\[(\\w+)\\]: (.*)$";
/**
* Creates a new instance of {@link IarParser}.
*/
public IarParser() {
super(IAR_WARNING_PATTERN);
}
@Override
protected boolean isLineInteresting(final String line) {
return line.contains("Warning") || line.contains("rror") || line.contains("Remark");
}
@Override
protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder) {
return builder.setSeverity(mapPriority(matcher))
.setMessage(normalizeWhitespaceInMessage(matcher.group(5)))
.setFileName(matcher.group(1))
.setLineStart(matcher.group(2))
.setCategory(matcher.group(4))
.buildOptional();
}
private Severity mapPriority(final Matcher matcher) {
Severity priority;
if ("Remark".equalsIgnoreCase(matcher.group(3))) {
priority = Severity.WARNING_LOW;
}
else if ("Error".equalsIgnoreCase(matcher.group(3))) {
priority = Severity.WARNING_HIGH;
}
else if ("Fatal error".equalsIgnoreCase(matcher.group(3))) {
priority = Severity.WARNING_HIGH;
}
else {
priority = Severity.WARNING_NORMAL;
}
return priority;
}
private String normalizeWhitespaceInMessage(final String message) {
return message.replaceAll("\\s+", " ");
}
}