SONAR-22914 Add a Sensor to import FOSSA results
This commit is contained in:
parent
574637dc96
commit
55dfebf3ec
|
|
@ -44,6 +44,7 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
|
||||||
private RuleType type;
|
private RuleType type;
|
||||||
private String engineId;
|
private String engineId;
|
||||||
private String ruleId;
|
private String ruleId;
|
||||||
|
private String cveId;
|
||||||
private Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts = new EnumMap<>(SoftwareQuality.class);
|
private Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts = new EnumMap<>(SoftwareQuality.class);
|
||||||
private CleanCodeAttribute cleanCodeAttribute;
|
private CleanCodeAttribute cleanCodeAttribute;
|
||||||
|
|
||||||
|
|
@ -84,6 +85,10 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
|
||||||
return ruleId;
|
return ruleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String cveId() {
|
||||||
|
return cveId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Severity severity() {
|
public Severity severity() {
|
||||||
return this.severity;
|
return this.severity;
|
||||||
|
|
@ -131,6 +136,11 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NewExternalIssue cveId(String cveId) {
|
||||||
|
this.cveId = cveId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultExternalIssue forRule(RuleKey ruleKey) {
|
public DefaultExternalIssue forRule(RuleKey ruleKey) {
|
||||||
this.engineId = ruleKey.repository();
|
this.engineId = ruleKey.repository();
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import org.sonar.api.batch.sensor.issue.Issue;
|
||||||
import org.sonar.api.batch.sensor.issue.Issue.Flow;
|
import org.sonar.api.batch.sensor.issue.Issue.Flow;
|
||||||
import org.sonar.api.batch.sensor.issue.MessageFormatting;
|
import org.sonar.api.batch.sensor.issue.MessageFormatting;
|
||||||
import org.sonar.api.batch.sensor.issue.NewIssue.FlowType;
|
import org.sonar.api.batch.sensor.issue.NewIssue.FlowType;
|
||||||
|
import org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue;
|
||||||
import org.sonar.api.batch.sensor.issue.internal.DefaultIssueFlow;
|
import org.sonar.api.batch.sensor.issue.internal.DefaultIssueFlow;
|
||||||
import org.sonar.api.issue.impact.SoftwareQuality;
|
import org.sonar.api.issue.impact.SoftwareQuality;
|
||||||
import org.sonar.api.rules.CleanCodeAttribute;
|
import org.sonar.api.rules.CleanCodeAttribute;
|
||||||
|
|
@ -176,7 +177,11 @@ public class IssuePublisher {
|
||||||
locationBuilder.setComponentRef(componentRef);
|
locationBuilder.setComponentRef(componentRef);
|
||||||
TextRange primaryTextRange = issue.primaryLocation().textRange();
|
TextRange primaryTextRange = issue.primaryLocation().textRange();
|
||||||
|
|
||||||
//nullable fields
|
// nullable fields
|
||||||
|
var cveId = ((DefaultExternalIssue) issue).cveId();
|
||||||
|
if (cveId != null) {
|
||||||
|
builder.setCveId(cveId);
|
||||||
|
}
|
||||||
CleanCodeAttribute cleanCodeAttribute = issue.cleanCodeAttribute();
|
CleanCodeAttribute cleanCodeAttribute = issue.cleanCodeAttribute();
|
||||||
if (cleanCodeAttribute != null) {
|
if (cleanCodeAttribute != null) {
|
||||||
builder.setCleanCodeAttribute(cleanCodeAttribute.name());
|
builder.setCleanCodeAttribute(cleanCodeAttribute.name());
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,10 @@ public class AnalysisResult implements AnalysisObserver {
|
||||||
return readFromReport(ScannerReportReader::readAdHocRules);
|
return readFromReport(ScannerReportReader::readAdHocRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ScannerReport.Cve> cves() {
|
||||||
|
return readFromReport(ScannerReportReader::readCves);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private <G> List<G> readFromReport(InputComponent component, BiFunction<ScannerReportReader, Integer, CloseableIterator<G>> readerMethod) {
|
private <G> List<G> readFromReport(InputComponent component, BiFunction<ScannerReportReader, Integer, CloseableIterator<G>> readerMethod) {
|
||||||
int ref = ((DefaultInputComponent) component).scannerId();
|
int ref = ((DefaultInputComponent) component).scannerId();
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ message ExternalIssue {
|
||||||
repeated MessageFormatting msgFormatting = 9;
|
repeated MessageFormatting msgFormatting = 9;
|
||||||
repeated Impact impacts = 10;
|
repeated Impact impacts = 10;
|
||||||
optional string cleanCodeAttribute = 11;
|
optional string cleanCodeAttribute = 11;
|
||||||
|
optional string cve_id = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AdHocRule {
|
message AdHocRule {
|
||||||
|
|
@ -234,8 +234,8 @@ message Cve {
|
||||||
string cve_id = 1;
|
string cve_id = 1;
|
||||||
string description = 2;
|
string description = 2;
|
||||||
float cvss_score = 3;
|
float cvss_score = 3;
|
||||||
float epss_score = 4;
|
optional float epss_score = 4;
|
||||||
float epss_percentile = 5;
|
optional float epss_percentile = 5;
|
||||||
int64 published_date = 6;
|
int64 published_date = 6;
|
||||||
int64 last_modified_date = 7;
|
int64 last_modified_date = 7;
|
||||||
repeated string cwe = 8;
|
repeated string cwe = 8;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue