ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder() .setMsg("the message") .setRuleRepository(ruleKey.repository())
@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 add_issue_to_cache() { ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME); activeRulesBuilder.addRule(new NewActiveRule.Builder() .setRuleKey(SQUID_RULE_KEY) .setSeverity(Severity.INFO) .setQProfileKey("qp-1") .build()); initModuleIssues(); DefaultIssue issue = new DefaultIssue(project) .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo")) .forRule(SQUID_RULE_KEY) .overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL); when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true); boolean added = moduleIssues.initAndAddIssue(issue); assertThat(added).isTrue(); ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class); verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), argument.capture()); assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL); }
Loggers.get(getClass()).debug("Ignored issue from analysis report on rule {}:{}", reportIssue.getRuleRepository(), reportIssue.getRuleKey()); continue;
private DefaultIssue toIssue(LineHashSequence lineHashSeq, ScannerReport.Issue reportIssue) { DefaultIssue issue = new DefaultIssue(); init(issue); issue.setRuleKey(RuleKey.of(reportIssue.getRuleRepository(), reportIssue.getRuleKey())); if (reportIssue.hasTextRange()) { int startLine = reportIssue.getTextRange().getStartLine(); issue.setLine(startLine); issue.setChecksum(lineHashSeq.getHashForLine(startLine)); issue.setChecksum(""); if (isNotEmpty(reportIssue.getMsg())) { issue.setMessage(reportIssue.getMsg()); if (reportIssue.getSeverity() != Severity.UNSET_SEVERITY) { issue.setSeverity(reportIssue.getSeverity().name()); if (reportIssue.getGap() != 0) { issue.setGap(reportIssue.getGap()); if (reportIssue.hasTextRange()) { dbLocationsBuilder.setTextRange(convertTextRange(reportIssue.getTextRange())); for (ScannerReport.Flow flow : reportIssue.getFlowList()) { if (flow.getLocationCount() > 0) { DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder();
private static ScannerReport.Issue createReportIssue(Issue issue, int componentRef, String activeRuleSeverity) { String primaryMessage = nullToEmpty(issue.primaryLocation().message()); org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity(); Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRuleSeverity); 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(componentRef); 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::addFlow, locationBuilder, textRangeBuilder, issue.flows()); return builder.build(); }
public static TrackedIssue toTrackedIssue(InputComponent component, ScannerReport.Issue rawIssue, @Nullable SourceHashHolder hashes) { RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); Preconditions.checkNotNull(component.key(), "Component key must be set"); Preconditions.checkNotNull(ruleKey, "Rule key must be set"); TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null); issue.setKey(Uuids.createFast()); issue.setComponentKey(component.key()); issue.setRuleKey(ruleKey); issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null); issue.setSeverity(rawIssue.getSeverity().name()); issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg())); issue.setResolution(null); issue.setStatus(Issue.STATUS_OPEN); issue.setNew(true); if (rawIssue.hasTextRange()) { TextRange r = rawIssue.getTextRange(); issue.setStartLine(r.getStartLine()); issue.setStartLineOffset(r.getStartOffset()); issue.setEndLine(r.getEndLine()); issue.setEndLineOffset(r.getEndOffset()); } return issue; }
private boolean isOnInactiveRule(ScannerReport.Issue reportIssue) { RuleKey ruleKey = RuleKey.of(reportIssue.getRuleRepository(), reportIssue.getRuleKey()); return !activeRulesHolder.get(ruleKey).isPresent(); }
@Override public String message() { return rawIssue.getMsg(); }
@Override public String severity() { return rawIssue.getSeverity().name(); }
@Override public RuleKey ruleKey() { return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); }
public CloseableIterator<ScannerReport.Issue> readComponentIssues(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef); if (fileExists(file)) { return Protobuf.readStream(file, ScannerReport.Issue.parser()); } return emptyCloseableIterator(); }
@Override public TextRange textRange() { if (!rawIssue.hasTextRange()) { return null; } return new DefaultTextRange( new DefaultTextPointer(rawIssue.getTextRange().getStartLine(), rawIssue.getTextRange().getStartOffset()), new DefaultTextPointer(rawIssue.getTextRange().getEndLine(), rawIssue.getTextRange().getEndOffset())); }
private boolean isIssueOnUnsupportedCommonRule(ScannerReport.Issue issue) { // issues on batch common rules are ignored. This feature // is natively supported by compute engine since 5.2. return !issue.getRuleRepository().startsWith(CommonRuleKeys.REPOSITORY_PREFIX); }
@Deprecated @Override public Integer line() { return rawIssue.hasTextRange() ? rawIssue.getTextRange().getStartLine() : null; }
Loggers.get(getClass()).debug("Ignored issue from analysis report on rule {}:{}", reportIssue.getRuleRepository(), reportIssue.getRuleKey()); continue;
ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder() .setTextRange(TextRange.newBuilder().setStartLine(2).build()) .setMsg("the message")
private DefaultIssue toIssue(LineHashSequence lineHashSeq, ScannerReport.Issue reportIssue) { DefaultIssue issue = new DefaultIssue(); init(issue); RuleKey ruleKey = RuleKey.of(reportIssue.getRuleRepository(), reportIssue.getRuleKey()); issue.setRuleKey(ruleKey); if (reportIssue.hasTextRange()) { int startLine = reportIssue.getTextRange().getStartLine(); issue.setLine(startLine); issue.setChecksum(lineHashSeq.getHashForLine(startLine)); if (isNotEmpty(reportIssue.getMsg())) { issue.setMessage(reportIssue.getMsg()); } else { Rule rule = ruleRepository.getByKey(ruleKey); issue.setMessage(rule.getName()); if (reportIssue.getSeverity() != Severity.UNSET_SEVERITY) { issue.setSeverity(reportIssue.getSeverity().name()); if (reportIssue.getGap() != 0) { issue.setGap(reportIssue.getGap()); if (reportIssue.hasTextRange()) { dbLocationsBuilder.setTextRange(convertTextRange(reportIssue.getTextRange())); for (ScannerReport.Flow flow : reportIssue.getFlowList()) { if (flow.getLocationCount() > 0) { DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder();
ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder() .setTextRange(TextRange.newBuilder().setStartLine(2).build()) .setMsg("the message")