Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-72887] Add coverity parser #1040

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package edu.hm.hafner.analysis.parser.violations;

import se.bjurr.violations.lib.parsers.CoverityParser;

/**
* Parses Coverity JSON V7 report files.
*
* @author Jobin Jose
*/
public class CoverityAdapter extends AbstractViolationAdapter {
private static final long serialVersionUID = -8210423965588732109L;

@Override
CoverityParser createParser() {
return new CoverityParser();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edu.hm.hafner.analysis.registry;

import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.parser.violations.CoverityAdapter;

/**
* A descriptor for Coverity.
*
* @author Ullrich Hafner
*/
class CoverityDescriptor extends ParserDescriptor {
private static final String ID = "coverity";
private static final String NAME = "Coverity Scan";

CoverityDescriptor() {
super(ID, NAME);
}

@Override
public IssueParser createParser(final Option... options) {
return new CoverityAdapter();
}

@Override
public String getUrl() {
return "https://scan.coverity.com/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ParserRegistry {
new CodeGeneratorDescriptor(),
new CodeNarcDescriptor(),
new CoolfluxChessccDescriptor(),
new CoverityDescriptor(),
new CpdDescriptor(),
new CppCheckDescriptor(),
new CppLintDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.hm.hafner.analysis.parser.violations;

import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.assertions.SoftAssertions;
import edu.hm.hafner.analysis.registry.AbstractParserTest;

class CoverityAdapterTest extends AbstractParserTest {
CoverityAdapterTest() {
super("coverity.json");
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
softly.assertThat(report).hasSize(1);
var issue = report.get(0);
softly.assertThat(issue)
.hasFileName("C:/Workspace/workspace/Build_jenkins_development/somefile.cs")
.hasCategory("Integer handling issues")
.hasType("constant_expression_result/bit_and_with_zero")
.hasLineStart(79)
.hasSeverity(Severity.WARNING_NORMAL);
softly.assertThat(issue.getMessage()).startsWith("Bitwise-and ('&') operation applied to zero always produces zero.");
}

@Override
protected CoverityAdapter createParser() {
return new CoverityAdapter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ void shouldParseAllIssues() {
void shouldRegisterParser() {
assumeThat(createParser().getClass().getPackageName()).startsWith("edu.hm.hafner.analysis"); // only test our own parsers

Set<Class<?>> parsers = new ParserRegistry().getAllDescriptors()
var parserRegistry = new ParserRegistry();

Set<Class<?>> parsers = parserRegistry.getAllDescriptors()
.stream()
.map(ParserDescriptor::createParser)
.map(IssueParser::getClass)
.collect(Collectors.toSet());

var compositeParsers = new ParserRegistry().getAllDescriptors().stream()
var compositeParsers = parserRegistry.getAllDescriptors().stream()
.filter(descriptor -> descriptor instanceof CompositeParserDescriptor)
.map(descriptor -> (CompositeParserDescriptor) descriptor)
.map(CompositeParserDescriptor::createParsers)
Expand All @@ -99,6 +101,12 @@ void shouldRegisterParser() {
assertThat(parsers)
.as("Every parser should be registered in the ParserRegistry")
.contains(createParser().getClass());

parserRegistry.getAllDescriptors()
.stream()
.map(ParserDescriptor::getUrl)
.forEach(url ->
assertThat(url).matches("https?://.*|^$"));
}

protected void assertThatReportHasSeverities(final Report report, final int expectedSizeError,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"type": "Coverity issues",
"formatVersion": 7,
"suppressedIssueCount": 0,
"issues": [
{
"mergeKey": "884ed7531feed32eb916d9038a3b9bd6",
"occurrenceCountForMK": 1,
"occurrenceNumberInMK": 1,
"referenceOccurrenceCountForMK": null,
"checkerName": "CONSTANT_EXPRESSION_RESULT",
"subcategory": "bit_and_with_zero",
"type": "constant_expression_result",
"subtype": "bit_and_with_zero",
"code-language": "c#",
"extra": "status",
"domain": "STATIC_CS",
"language": "C#",
"mainEventFilePathname": "C:\\Workspace\\workspace\\Build_jenkins_development\\somefile.cs",
"strippedMainEventFilePathname": "\\workspace\\Build_jenkins_development\\Architecture\\somefile.cs",
"mainEventLineNumber": 79,
"properties": {},
"functionDisplayName": "somename",
"functionMangledName": "somename",
"localStatus": null,
"ordered": false,
"events": [
{
"covLStrEventDescription": "{CovLStrv2{{t{{0} is always 0.}{{code{status & System.Printing.PrintJobStatus.None}}}}{t{ This occurs as a value.}}}}",
"eventDescription": "\"status & System.Printing.PrintJobStatus.None\" is always 0. This occurs as a value.",
"eventNumber": 1,
"eventTreePosition": "1",
"eventSet": 0,
"eventTag": "bit_and_with_zero",
"filePathname": "C:\\Workspace\\workspace\\Build_jenkins_development\\somefile.cs",
"strippedFilePathname": "\\workspace\\Build_jenkins_development\\Architecture\\somefile.cs",
"lineNumber": 79,
"main": true,
"moreInformationId": null,
"remediation": false,
"events": null
}
],
"stateOnServer": null,
"checkerProperties": {
"category": "Integer handling issues",
"categoryDescription": "Integer handling issues",
"cweCategory": "569",
"issueKinds": ["QUALITY"],
"eventSetCaptions": [],
"impact": "Medium",
"impactDescription": "Medium",
"subcategoryLocalEffect": "The expression's value is always zero; construct may indicate an inadvertent logic error.",
"subcategoryShortDescription": "Bitwise-and with zero",
"subcategoryLongDescription": "Bitwise-and ('&amp;') operation applied to zero always produces zero"
}
}
],
"desktopAnalysisSettings": null,
"error": null,
"warnings": []
}
Loading