private static ScannerReport.Flow moveFlow(ScannerReport.Component root, ScannerReport.Component component, ScannerReport.Flow flow) { return ScannerReport.Flow.newBuilder() .addAllLocation(flow.getLocationList().stream() .map(location -> moveLocation(root, component, location)) .collect(Collectors.toList())) .build(); } }
assertThat(issue.getType()).isEqualTo(IssueType.BUG); assertThat(issue.hasTextRange()).isFalse(); assertThat(issue.getFlow(0).getLocationCount()).isOne(); assertThat(issue.getFlow(0).getLocation(0).getTextRange().getStartLine()).isOne(); assertThat(issue.getFlow(1).getLocationCount()).isOne(); assertThat(issue.getFlow(1).getLocation(0).getTextRange().getStartLine()).isEqualTo(3);
if (flow.getLocationCount() > 0) { DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder(); for (ScannerReport.IssueLocation location : flow.getLocationList()) { convertLocation(location).ifPresent(dbFlowBuilder::addLocation);
if (flow.getLocationCount() > 0) { DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder(); for (ScannerReport.IssueLocation location : flow.getLocationList()) { convertLocation(location).ifPresent(dbFlowBuilder::addLocation);
private static void applyFlows(Consumer<ScannerReport.Flow> consumer, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Collection<Flow> flows) { ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder(); for (Flow flow : flows) { if (flow.locations().isEmpty()) { return; } flowBuilder.clear(); for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) { int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).scannerId(); locationBuilder.clear(); locationBuilder.setComponentRef(locationComponentRef); String message = location.message(); if (message != null) { locationBuilder.setMsg(message); } TextRange textRange = location.textRange(); if (textRange != null) { locationBuilder.setTextRange(toProtobufTextRange(textRangeBuilder, textRange)); } flowBuilder.addLocation(locationBuilder.build()); } consumer.accept(flowBuilder.build()); } }
.setSeverity(Constants.Severity.BLOCKER) .setGap(3.14) .addFlow(ScannerReport.Flow.newBuilder() .addLocation(ScannerReport.IssueLocation.newBuilder() .setComponentRef(FILE_REF)
if (flow.getLocationCount() > 0) { DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder(); for (ScannerReport.IssueLocation location : flow.getLocationList()) { convertLocation(location).ifPresent(dbFlowBuilder::addLocation);
if (flow.getLocationCount() > 0) { DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder(); for (ScannerReport.IssueLocation location : flow.getLocationList()) { convertLocation(location).ifPresent(dbFlowBuilder::addLocation);
private static void applyFlows(Consumer<ScannerReport.Flow> consumer, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Collection<Flow> flows) { ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder(); for (Flow flow : flows) { if (flow.locations().isEmpty()) { return; } flowBuilder.clear(); for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) { int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).scannerId(); locationBuilder.clear(); locationBuilder.setComponentRef(locationComponentRef); String message = location.message(); if (message != null) { locationBuilder.setMsg(message); } TextRange textRange = location.textRange(); if (textRange != null) { locationBuilder.setTextRange(toProtobufTextRange(textRangeBuilder, textRange)); } flowBuilder.addLocation(locationBuilder.build()); } consumer.accept(flowBuilder.build()); } }
@Test public void testFlowWithSingleLocation() throws Exception { List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiple.xoo")); assertThat(issues).hasSize(1); Issue issue = issues.get(0); assertThat(issue.getMsg()).isEqualTo("Primary location"); assertThat(issue.getTextRange().getStartLine()).isEqualTo(6); assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23); assertThat(issue.getTextRange().getEndLine()).isEqualTo(6); assertThat(issue.getTextRange().getEndOffset()).isEqualTo(50); assertThat(issue.getFlowList()).hasSize(1); Flow flow = issue.getFlow(0); assertThat(flow.getLocationList()).hasSize(1); IssueLocation additionalLocation = flow.getLocation(0); assertThat(additionalLocation.getMsg()).isEqualTo("Flow step #1"); assertThat(additionalLocation.getTextRange().getStartLine()).isEqualTo(7); assertThat(additionalLocation.getTextRange().getStartOffset()).isEqualTo(26); assertThat(additionalLocation.getTextRange().getEndLine()).isEqualTo(7); assertThat(additionalLocation.getTextRange().getEndOffset()).isEqualTo(53); }
@Test public void testFlowsWithMultipleElements() throws Exception { List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/WithFlow.xoo")); assertThat(issues).hasSize(1); Issue issue = issues.get(0); assertThat(issue.getFlowList()).hasSize(1); Flow flow = issue.getFlow(0); assertThat(flow.getLocationList()).hasSize(2); // TODO more assertions } }