use of org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.
the class SkippedTestRuleTest method issue_if_skipped_tests.
@Test
public void issue_if_skipped_tests() {
activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.emptyMap(), 1_000L, PLUGIN_KEY, QP_KEY));
measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.SKIPPED_TESTS_KEY, Measure.newMeasureBuilder().create(2));
DefaultIssue issue = underTest.processFile(FILE, "java");
assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
assertThat(issue.gap()).isEqualTo(2.0);
assertThat(issue.message()).isEqualTo("Fix or remove skipped unit tests in file \"FooTest.java\".");
}
use of org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.
the class CommonRule method processFile.
@CheckForNull
public DefaultIssue processFile(Component file, String fileLanguage) {
DefaultIssue issue = null;
RuleKey ruleKey = RuleKey.of(commonRepositoryForLang(fileLanguage), key);
Optional<ActiveRule> activeRule = activeRulesHolder.get(ruleKey);
if (activeRule.isPresent()) {
CommonRuleIssue cri = doProcessFile(file, activeRule.get());
if (cri != null) {
issue = new DefaultIssue();
issue.setGap(cri.effortToFix);
issue.setMessage(cri.message);
issue.setRuleKey(ruleKey);
issue.setSeverity(activeRule.get().getSeverity());
issue.setLine(null);
issue.setChecksum("");
issue.setIsFromExternalRuleEngine(false);
}
}
return issue;
}
use of org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.
the class IssueCreationDateCalculator method onIssue.
@Override
public void onIssue(Component component, DefaultIssue issue) {
if (!issue.isNew()) {
return;
}
Optional<Long> lastAnalysisOptional = lastAnalysis();
boolean firstAnalysis = !lastAnalysisOptional.isPresent();
if (firstAnalysis || isNewFile(component)) {
backdateIssue(component, issue);
return;
}
Rule rule = ruleRepository.findByKey(issue.getRuleKey()).orElseThrow(illegalStateException("The rule with key '%s' raised an issue, but no rule with that key was found", issue.getRuleKey()));
if (rule.isExternal()) {
backdateIssue(component, issue);
} else {
// Rule can't be inactive (see contract of IssueVisitor)
ActiveRule activeRule = activeRulesHolder.get(issue.getRuleKey()).get();
if (activeRuleIsNewOrChanged(activeRule, lastAnalysisOptional.get()) || ruleImplementationChanged(activeRule.getRuleKey(), activeRule.getPluginKey(), lastAnalysisOptional.get()) || qualityProfileChanged(activeRule.getQProfileKey())) {
backdateIssue(component, issue);
}
}
}
use of org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.
the class CommentDensityRuleTest method no_issues_if_enough_comments.
@Test
public void no_issues_if_enough_comments() {
activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, ImmutableMap.of(CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY_PROPERTY, "25"), 1_000L, PLUGIN_KEY, QP_KEY));
measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_DENSITY_KEY, Measure.newMeasureBuilder().create(90.0, 1));
DefaultIssue issue = underTest.processFile(FILE, PLUGIN_KEY);
assertThat(issue).isNull();
}
use of org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule in project sonarqube by SonarSource.
the class CommentDensityRuleTest method prepareForIssue.
private void prepareForIssue(String minDensity, ReportComponent file, double commentLineDensity, int commentLines, int ncloc) {
activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, ImmutableMap.of(CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY_PROPERTY, minDensity), 1_000L, PLUGIN_KEY, QP_KEY));
measureRepository.addRawMeasure(file.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_DENSITY_KEY, Measure.newMeasureBuilder().create(commentLineDensity, 1));
measureRepository.addRawMeasure(file.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(commentLines));
measureRepository.addRawMeasure(file.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(ncloc));
}
Aggregations