forked from jenkinsci/analysis-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiCcsParser.java
71 lines (61 loc) · 2.17 KB
/
TiCcsParser.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
68
69
70
package edu.hm.hafner.analysis.parser;
import java.util.Optional;
import java.util.regex.Matcher;
import org.apache.commons.lang3.StringUtils;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpLineParser;
/**
* A parser for the Texas Instruments Code Composer Studio compiler warnings.
*
* @author Jan Linnenkohl
*/
public class TiCcsParser extends RegexpLineParser {
private static final long serialVersionUID = -8253481365175984661L;
private static final String TI_CCS_WARNING_PATTERN = "^((\"(.*)\",\\s*)(line\\s*(\\d+)(\\s*\\(.*\\))?:)?\\s*)?"
+ "(WARNING|ERROR|remark|warning|(fatal\\s*)?error)(!\\s*at line\\s(\\d+))?\\s*([^:]*)\\s*:\\s*(.*)$";
/**
* Creates a new instance of {@link TiCcsParser}.
*/
public TiCcsParser() {
super(TI_CCS_WARNING_PATTERN);
}
@Override
protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder) {
String lineNumber = matcher.group(5);
if (StringUtils.isBlank(lineNumber)) {
lineNumber = matcher.group(10);
}
return builder.setFileName(matcher.group(3))
.setLineStart(lineNumber)
.setCategory(matcher.group(11))
.setMessage(matcher.group(12))
.setSeverity(mapPriority(matcher))
.buildOptional();
}
private Severity mapPriority(final Matcher matcher) {
if (isOfType(matcher, "remark")) {
return Severity.WARNING_LOW;
}
else if (isOfType(matcher, "warning")) {
return Severity.WARNING_NORMAL;
}
else {
return Severity.WARNING_HIGH;
}
}
/**
* Returns whether the warning type is of the specified type.
*
* @param matcher
* the matcher
* @param type
* the type to match with
*
* @return {@code true} if the warning type is of the specified type
*/
private boolean isOfType(final Matcher matcher, final String type) {
return StringUtils.containsIgnoreCase(matcher.group(7), type);
}
}