Skip to content

Commit

Permalink
Merge pull request #866 from jenkinsci/polyspace-parser
Browse files Browse the repository at this point in the history
Simplify code of Polyspace parser
  • Loading branch information
uhafner authored Dec 7, 2022
2 parents 82a49aa + 55bd527 commit 80babb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions SUPPORTED-FORMATS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--- DO NOT EDIT -- Generated at 2022-11-30T10:38:50.601440400 - Run the `main` method of `ParserRegistry` to regenerate after changing parsers -- DO NOT EDIT --->
<!--- DO NOT EDIT -- Generated at 2022-12-07T14:58:15.456107 - Run the `main` method of `ParserRegistry` to regenerate after changing parsers -- DO NOT EDIT --->
# Supported Report Formats

The static analysis model supports the following report formats.
Expand Down Expand Up @@ -1549,7 +1549,7 @@ analyze - iccxxxxcompiler_opts cstat2.c</pre></code>For details check the IAR C-
</tr>
<tr>
<td colspan="4">
:bulb: Reads reports of Polyspace Static Analysis Tool by MathWorks. Used for BugFinder and CodeProver result files.<br/>Bugfinder: <a href='https://www.mathworks.com/help/bugfinder/ref/polyspaceresultsexport.html?s_tid=srchtitle_polyspace-results-export_1'> </a>CodeProver: <a href='https://www.mathworks.com/help/codeprover/ref/polyspaceresultsexport.html?s_tid=srchtitle_polyspace-results-export_2'> </a>Report can be generated with command: polyspace-results-export -format csv -results-dir <RESULTS> -output-name <CSVFILE> -key <KEY>
:bulb: Reads reports of Polyspace Static Analysis Tool by MathWorks. Used for <a href='https://www.mathworks.com/help/bugfinder/ref/polyspaceresultsexport.html?s_tid=srchtitle_polyspace-results-export_1'>BugFinder</a> and <a href='https://www.mathworks.com/help/codeprover/ref/polyspaceresultsexport.html?s_tid=srchtitle_polyspace-results-export_2'>CodeProver</a> result files.<br/>Report can be generated with command: polyspace-results-export -format csv -results-dir <RESULTS> -output-name <CSVFILE> -key <KEY>
</td>
</tr>
<tr>
Expand Down
32 changes: 13 additions & 19 deletions src/main/java/edu/hm/hafner/analysis/parser/PolyspaceParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;

import static org.apache.commons.lang3.StringUtils.*;

/**
* A parser for Polyspace Bug Finder and Code Prover results.
* Used for .csv files generated from Bugfinder and CodeProver tools
*
* @author Eva Habeeb
*/
public class PolyspaceParser extends IssueParser {

private static final long serialVersionUID = -1251248150596418714L;

static final int SEVERITY_INDEX = 10;
static final int COLOR_INDEX = 3;
static final int FAMILY_INDEX = 1;
Expand All @@ -35,7 +37,6 @@ public Report parse(final ReaderFactory reader) throws ParsingException {
}

private Report parse(final Stream<String> lines) {

try (IssueBuilder builder = new IssueBuilder()) {
int lineNumber;
int colNumber;
Expand All @@ -61,8 +62,7 @@ private Report parse(final Stream<String> lines) {
}

String[] attributes = line.split("\\t", limit);
if (equalsIgnoreCase(attributes[9], "Unreviewed") || equalsIgnoreCase(attributes[9], "To investigate")
|| equalsIgnoreCase(attributes[9], "To fix") || equalsIgnoreCase(attributes[9], "Other")) {
if (containsAnyIgnoreCase(attributes[9], "Unreviewed", "To investigate", "To fix", "Other")) {
builder.setFileName(attributes[8]);
builder.setCategory(attributes[2]);
builder.setDescription(attributes[1]);
Expand All @@ -82,33 +82,27 @@ private Report parse(final Stream<String> lines) {

@SuppressWarnings({"PMD.UseVarargs", "PMD.CyclomaticComplexity" })
private Severity mapPriority(final String[] attributes) {

Severity priority = Severity.WARNING_NORMAL;

if (equalsIgnoreCase(attributes[SEVERITY_INDEX], "Unset")) {

if (equalsIgnoreCase(attributes[FAMILY_INDEX], "Defect")
|| equalsIgnoreCase(attributes[COLOR_INDEX], "Red")) {
priority = Severity.WARNING_HIGH;
return Severity.WARNING_HIGH;
}
else if (equalsIgnoreCase(attributes[COLOR_INDEX], "Orange")
|| equalsIgnoreCase(attributes[COLOR_INDEX], "Not Applicable")) {
priority = Severity.WARNING_NORMAL;
else if (containsAnyIgnoreCase(attributes[COLOR_INDEX], "Orange", "Not Applicable")) {
return Severity.WARNING_NORMAL;
}
else if (equalsIgnoreCase(attributes[COLOR_INDEX], "Gray")
|| equalsIgnoreCase(attributes[COLOR_INDEX], "Green")) {
priority = Severity.WARNING_LOW;
else if (containsAnyIgnoreCase(attributes[COLOR_INDEX], "Gray", "Green")) {
return Severity.WARNING_LOW;
}
}
else if (equalsIgnoreCase(attributes[SEVERITY_INDEX], "High")) {
priority = Severity.WARNING_HIGH;
return Severity.WARNING_HIGH;
}
else if (equalsIgnoreCase(attributes[SEVERITY_INDEX], "Medium")) {
priority = Severity.WARNING_NORMAL;
return Severity.WARNING_NORMAL;
}
else if (equalsIgnoreCase(attributes[SEVERITY_INDEX], "Low")) {
priority = Severity.WARNING_LOW;
return Severity.WARNING_LOW;
}
return priority;
return Severity.WARNING_NORMAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti

softly.assertThat(report.get(0))
.hasLineStart(222)
.hasMessage(
"Check: Null pointer Impact: High")
.hasMessage("Check: Null pointer Impact: High")
.hasModuleName("calculate()")
.hasCategory("memory")
.hasDescription("Defect")
.hasSeverity(Severity.WARNING_HIGH);
softly.assertThat(report.get(1))
.hasLineStart(276)
.hasDescription("Defect")
.hasMessage(
"Check: Qualifier removed in conversion Impact: Low")
.hasMessage("Check: Qualifier removed in conversion Impact: Low")
.hasCategory("Programming")
.hasSeverity(Severity.WARNING_HIGH);
softly.assertThat(report.get(2))
Expand All @@ -51,8 +49,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti
softly.assertThat(report.get(5))
.hasLineStart(512)
.hasDescription("MISRA C:2012")
.hasMessage(
"Check: 11.1 Conversions shall not be performed between a pointer to a function and any other type. Category: Required")
.hasMessage("Check: 11.1 Conversions shall not be performed between a pointer to a function and any other type. Category: Required")
.hasModuleName("tester()")
.hasSeverity(Severity.WARNING_NORMAL);
}
Expand Down

0 comments on commit 80babb0

Please sign in to comment.