private void assertSingleIssue(Set<AnalyzerMessage> issues) { Preconditions.checkState(issues.size() == 1, "A single issue is expected on the file"); AnalyzerMessage issue = Iterables.getFirst(issues, null); assertThat(issue.getLine()).isNull(); assertThat(issue.getMessage()).isEqualTo(expectFileIssue); }
@Override public String toString() { return String.format("'%s' in %s:%d", getMessage(), getFile(), getLine()); } }
@Override public String toString() { return String.format("'%s' in %s:%d", getMessage(), getFile(), getLine()); } }
private static void validateIssue(Multimap<Integer, Map<IssueAttribute, String>> expected, List<Integer> unexpectedLines, AnalyzerMessage issue, @Nullable RemediationFunction remediationFunction) { int line = issue.getLine(); if (expected.containsKey(line)) { Map<IssueAttribute, String> attrs = Iterables.getLast(expected.get(line)); assertEquals(issue.getMessage(), attrs, IssueAttribute.MESSAGE); Double cost = issue.getCost(); if (cost != null) { Preconditions.checkState(remediationFunction != RemediationFunction.CONST, "Rule with constant remediation function shall not provide cost"); assertEquals(Integer.toString(cost.intValue()), attrs, IssueAttribute.EFFORT_TO_FIX); } else if(remediationFunction == RemediationFunction.LINEAR){ Fail.fail("A cost should be provided for a rule with linear remediation function"); } validateAnalyzerMessage(attrs, issue); expected.remove(line, attrs); } else { unexpectedLines.add(line); } }
public JavaIssue addFlow(InputFile file, List<List<AnalyzerMessage>> flows) { for (List<AnalyzerMessage> flow : flows) { newIssue.addFlow(flow.stream() .map(am -> newIssue.newLocation() .on(file) .at(range(file, am.primaryLocation())) .message(am.getMessage())) .collect(Collectors.toList())); } return this; }
public JavaIssue addFlow(InputFile file, List<List<AnalyzerMessage>> flows) { for (List<AnalyzerMessage> flow : flows) { newIssue.addFlow(flow.stream() .map(am -> newIssue.newLocation() .on(file) .at(range(file, am.primaryLocation())) .message(am.getMessage())) .collect(Collectors.toList())); } return this; }
@VisibleForTesting void reportIssueAfterSQ52(AnalyzerMessage analyzerMessage, RuleKey key, InputPath inputPath, Double cost) { JavaIssue issue = JavaIssue.create(context, key, cost); AnalyzerMessage.TextSpan textSpan = analyzerMessage.primaryLocation(); if (textSpan == null) { // either an issue at file or folder level issue.setPrimaryLocationOnFile(inputPath, analyzerMessage.getMessage()); } else { issue.setPrimaryLocation((InputFile) inputPath, analyzerMessage.getMessage(), textSpan.startLine, textSpan.startCharacter, textSpan.endLine, textSpan.endCharacter); } for (AnalyzerMessage location : analyzerMessage.secondaryLocations) { AnalyzerMessage.TextSpan secondarySpan = location.primaryLocation(); issue.addSecondaryLocation( inputFromIOFile(location.getFile()), secondarySpan.startLine, secondarySpan.startCharacter, secondarySpan.endLine, secondarySpan.endCharacter, location.getMessage()); } issue.save(); }
public void reportIssue(AnalyzerMessage analyzerMessage) { JavaCheck check = analyzerMessage.getCheck(); Preconditions.checkNotNull(check); Preconditions.checkNotNull(analyzerMessage.getMessage()); RuleKey key = getRuleKey(check); if (key == null) { return; } File file = analyzerMessage.getFile(); InputPath inputPath = inputPathFromIOFile(file); if (inputPath == null) { return; } Double cost = analyzerMessage.getCost(); reportIssue(analyzerMessage, key, inputPath, cost); }
@VisibleForTesting void reportIssue(AnalyzerMessage analyzerMessage, RuleKey key, InputPath inputPath, Double cost) { Preconditions.checkNotNull(context); JavaIssue issue = JavaIssue.create(context, key, cost); AnalyzerMessage.TextSpan textSpan = analyzerMessage.primaryLocation(); if (textSpan == null) { // either an issue at file or folder level issue.setPrimaryLocationOnFile(inputPath, analyzerMessage.getMessage()); } else { if (!textSpan.onLine()) { Preconditions.checkState(!textSpan.isEmpty(), "Issue location should not be empty"); } issue.setPrimaryLocation((InputFile) inputPath, analyzerMessage.getMessage(), textSpan.startLine, textSpan.startCharacter, textSpan.endLine, textSpan.endCharacter); } issue.addFlow(inputFromIOFile(analyzerMessage.getFile()), analyzerMessage.flows).save(); }
@VisibleForTesting void reportIssue(AnalyzerMessage analyzerMessage, RuleKey key, InputPath inputPath, Double cost) { Preconditions.checkNotNull(context); JavaIssue issue = JavaIssue.create(context, key, cost); AnalyzerMessage.TextSpan textSpan = analyzerMessage.primaryLocation(); if (textSpan == null) { // either an issue at file or folder level issue.setPrimaryLocationOnFile(inputPath, analyzerMessage.getMessage()); } else { if (!textSpan.onLine()) { Preconditions.checkState(!textSpan.isEmpty(), "Issue location should not be empty"); } issue.setPrimaryLocation((InputFile) inputPath, analyzerMessage.getMessage(), textSpan.startLine, textSpan.startCharacter, textSpan.endLine, textSpan.endCharacter); } issue.addFlow(inputFromIOFile(analyzerMessage.getFile()), analyzerMessage.flows).save(); }
public void reportIssue(AnalyzerMessage analyzerMessage) { JavaCheck check = analyzerMessage.getCheck(); Preconditions.checkNotNull(check); Preconditions.checkNotNull(analyzerMessage.getMessage()); RuleKey key = getRuleKey(check); if (key == null) { return; } File file = analyzerMessage.getFile(); InputPath inputPath = inputPathFromIOFile(file); if (inputPath == null) { return; } Double cost = analyzerMessage.getCost(); reportIssue(analyzerMessage, key, inputPath, cost); }
public void reportIssue(AnalyzerMessage analyzerMessage) { JavaCheck check = analyzerMessage.getCheck(); Preconditions.checkNotNull(check); Preconditions.checkNotNull(analyzerMessage.getMessage()); RuleKey key = getRuleKey(check); if (key == null) { return; } File file = analyzerMessage.getFile(); InputPath inputPath = inputPathFromIOFile(file); if (inputPath == null) { return; } Double cost = analyzerMessage.getCost(); assertEffortToFixIsNotRequired(check, cost); if (IS_SONARQUBE_52) { reportIssueAfterSQ52(analyzerMessage, key, inputPath, cost); } else { reportIssueBeforeSQ52(inputPath, key, cost, analyzerMessage.getMessage(), analyzerMessage.getLine()); } }