use of org.sonar.api.batch.fs.internal.DefaultInputComponent in project sonarqube by SonarSource.
the class ModuleIssues method initAndAddIssue.
public boolean initAndAddIssue(Issue issue) {
DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent();
Rule rule = validateRule(issue);
ActiveRule activeRule = activeRules.find(issue.ruleKey());
if (activeRule == null) {
// rule does not exist or is not enabled -> ignore the issue
return false;
}
String primaryMessage = Strings.isNullOrEmpty(issue.primaryLocation().message()) ? rule.name() : issue.primaryLocation().message();
org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRule.severity());
ScannerReport.Issue.Builder builder = ScannerReport.Issue.newBuilder();
ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
// non-null fields
builder.setSeverity(severity);
builder.setRuleRepository(issue.ruleKey().repository());
builder.setRuleKey(issue.ruleKey().rule());
builder.setMsg(primaryMessage);
locationBuilder.setMsg(primaryMessage);
locationBuilder.setComponentRef(inputComponent.batchId());
TextRange primaryTextRange = issue.primaryLocation().textRange();
if (primaryTextRange != null) {
builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
}
Double gap = issue.gap();
if (gap != null) {
builder.setGap(gap);
}
applyFlows(builder, locationBuilder, textRangeBuilder, issue);
ScannerReport.Issue rawIssue = builder.build();
if (filters.accept(inputComponent.key(), rawIssue)) {
write(inputComponent.batchId(), rawIssue);
return true;
}
return false;
}
use of org.sonar.api.batch.fs.internal.DefaultInputComponent in project sonarqube by SonarSource.
the class IssueTransition method execute.
public void execute() {
if (localIssueTracking != null) {
localIssueTracking.init();
}
ScannerReportReader reader = new ScannerReportReader(reportPublisher.getReportDir());
int nbComponents = inputComponentStore.all().size();
if (nbComponents == 0) {
return;
}
ProgressReport progressReport = new ProgressReport("issue-tracking-report", TimeUnit.SECONDS.toMillis(10));
progressReport.start("Performing issue tracking");
int count = 0;
try {
for (InputComponent component : inputComponentStore.all()) {
trackIssues(reader, (DefaultInputComponent) component);
count++;
progressReport.message(count + "/" + nbComponents + " components tracked");
}
} finally {
progressReport.stop(count + "/" + nbComponents + " components tracked");
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputComponent in project sonarqube by SonarSource.
the class TestExecutionAndCoveragePublisher method publish.
@Override
public void publish(ScannerReportWriter writer) {
final ScannerReport.Test.Builder testBuilder = ScannerReport.Test.newBuilder();
final ScannerReport.CoverageDetail.Builder builder = ScannerReport.CoverageDetail.newBuilder();
final ScannerReport.CoverageDetail.CoveredFile.Builder coveredBuilder = ScannerReport.CoverageDetail.CoveredFile.newBuilder();
for (final InputComponent c : componentStore.all()) {
DefaultInputComponent component = (DefaultInputComponent) c;
final MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, component);
if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) {
continue;
}
final Set<String> testNamesWithCoverage = new HashSet<>();
writer.writeTests(component.batchId(), StreamSupport.stream(testPlan.testCases().spliterator(), false).map(testCase -> toProtobufTest(testBuilder, testNamesWithCoverage, testCase)).collect(toList()));
writer.writeCoverageDetails(component.batchId(), testNamesWithCoverage.stream().map(testName -> toProtobufCoverageDetails(builder, coveredBuilder, testPlan, testName)).collect(toList()));
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputComponent in project sonarqube by SonarSource.
the class TestExecutionAndCoveragePublisher method toProtobufCoverageDetails.
private CoverageDetail toProtobufCoverageDetails(final ScannerReport.CoverageDetail.Builder builder, final ScannerReport.CoverageDetail.CoveredFile.Builder coveredBuilder, final MutableTestPlan testPlan, String testName) {
// Take first test with provided name
MutableTestCase testCase = testPlan.testCasesByName(testName).iterator().next();
builder.clear();
builder.setTestName(testName);
for (CoverageBlock block : testCase.coverageBlocks()) {
coveredBuilder.clear();
DefaultInputComponent c = (DefaultInputComponent) componentStore.getByKey(((DefaultTestable) block.testable()).inputFile().key());
coveredBuilder.setFileRef(c.batchId());
for (int line : block.lines()) {
coveredBuilder.addCoveredLine(line);
}
builder.addCoveredFile(coveredBuilder.build());
}
return builder.build();
}
use of org.sonar.api.batch.fs.internal.DefaultInputComponent in project sonarqube by SonarSource.
the class DefaultComponentTreeTest method test.
@Test
public void test() {
DefaultInputComponent root = new DefaultInputModule("root");
DefaultInputComponent mod1 = new DefaultInputModule("mod1");
DefaultInputComponent mod2 = new DefaultInputModule("mod2");
DefaultInputComponent mod3 = new DefaultInputModule("mod3");
DefaultInputComponent mod4 = new DefaultInputModule("mod4");
tree.index(mod1, root);
tree.index(mod2, mod1);
tree.index(mod3, root);
tree.index(mod4, root);
assertThat(tree.getChildren(root)).containsOnly(mod1, mod3, mod4);
assertThat(tree.getChildren(mod4)).isEmpty();
assertThat(tree.getChildren(mod1)).containsOnly(mod2);
assertThat(tree.getParent(mod4)).isEqualTo(root);
assertThat(tree.getParent(mod2)).isEqualTo(mod1);
assertThat(tree.getParent(mod1)).isEqualTo(root);
assertThat(tree.getParent(root)).isNull();
}
Aggregations