@CheckForNull private static RuleActivation toRuleActivation(ActiveRule activeRule, Map<RuleKey, RuleDefinitionDto> rulesByRuleKey) { RuleKey ruleKey = activeRule.getRule().ruleKey(); RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); if (ruleDefinition == null) { return null; } String severity = activeRule.getSeverity().name(); Map<String, String> params = activeRule.getActiveRuleParams().stream() .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue)); return RuleActivation.create(ruleDefinition.getId(), severity, params); }
@Test public void shouldMatchRule() { RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey(); assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "pmd:IllegalRegexp").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "pmd:*").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse(); }
@Test public void match_rule() { RuleKey rule = Rule.create("checkstyle", "IllegalRegexp", "").ruleKey(); assertThat(new IssuePattern("*", "*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:IllegalRegexp").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "checkstyle:Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "*:*Illegal*").matchRule(rule)).isTrue(); assertThat(new IssuePattern("*", "pmd:IllegalRegexp").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "pmd:*").matchRule(rule)).isFalse(); assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").matchRule(rule)).isFalse(); }
/** * @deprecated since 4.4 use {@link #setRuleKey(org.sonar.api.rule.RuleKey)} */ @Deprecated public RuleMeasure setRule(Rule rule) { this.ruleKey = rule.ruleKey(); return this; }
/** * This constructor is for internal use only. Please use static methods createForXXX(). * @deprecated since 4.4 use {@link #RuleMeasure(Metric, RuleKey, RulePriority, Integer)} */ @Deprecated public RuleMeasure(Metric metric, @Nullable Rule rule, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) { this(metric, rule != null ? rule.ruleKey() : null, rulePriority, ruleCategory); }
public static MeasuresFilter<RuleMeasure> rule(final Metric metric, final Rule rule) { return rule(metric, rule.ruleKey()); }
private void initMaps(ReportRuleKey reportRuleKey) { if (!ruleReportByRuleKey.containsKey(reportRuleKey)) { ruleReportByRuleKey.put(reportRuleKey, new RuleReport(reportRuleKey)); } if (!totalByRuleKey.containsKey(reportRuleKey.getRule().ruleKey().toString())) { totalByRuleKey.put(reportRuleKey.getRule().ruleKey().toString(), new IssueVariation()); } if (!totalBySeverity.containsKey(reportRuleKey.getSeverity().toString())) { totalBySeverity.put(reportRuleKey.getSeverity().toString(), new IssueVariation()); } }
@CheckForNull private static RuleActivation toRuleActivation(ActiveRule activeRule, Map<RuleKey, RuleDefinitionDto> rulesByRuleKey) { RuleKey ruleKey = activeRule.getRule().ruleKey(); RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); if (ruleDefinition == null) { return null; } String severity = activeRule.getSeverity().name(); Map<String, String> params = activeRule.getActiveRuleParams().stream() .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue)); return RuleActivation.create(ruleDefinition.getId(), severity, params); }
private void initMaps(ReportRuleKey reportRuleKey) { if (!ruleReportByRuleKey.containsKey(reportRuleKey)) { ruleReportByRuleKey.put(reportRuleKey, new RuleReport(reportRuleKey)); } if (!totalByRuleKey.containsKey(reportRuleKey.getRule().ruleKey().toString())) { totalByRuleKey.put(reportRuleKey.getRule().ruleKey().toString(), new IssueVariation()); } if (!totalBySeverity.containsKey(reportRuleKey.getSeverity().toString())) { totalBySeverity.put(reportRuleKey.getSeverity().toString(), new IssueVariation()); } }
private void initSetOfDirs(Project project) { dirsWithoutPackageInfo = Sets.newHashSet(); ActiveRule activeRule = rulesProfile.getActiveRule(CheckList.REPOSITORY_KEY, PackageInfoCheck.RULE_KEY); if (activeRule != null) { CodeVisitor check = checkInstanceOf(activeRule.getRule().ruleKey()); if (check != null) { Set<File> dirs = ((PackageInfoCheck) check).getDirectoriesWithoutPackageFile(); for (File dir : dirs) { dirsWithoutPackageInfo.add(Directory.fromIOFile(dir, project)); } } } } }
public void addIssue(Issue issue, Rule rule, RulePriority severity) { ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); initMaps(reportRuleKey); ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis(); total.incrementCountInCurrentAnalysis(); totalByRuleKey.get(rule.ruleKey().toString()).incrementCountInCurrentAnalysis(); totalBySeverity.get(severity.toString()).incrementCountInCurrentAnalysis(); if (issue.isNew()) { total.incrementNewIssuesCount(); ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount(); totalByRuleKey.get(rule.ruleKey().toString()).incrementNewIssuesCount(); totalBySeverity.get(severity.toString()).incrementNewIssuesCount(); } }
public void addResolvedIssue(Issue issue, Rule rule, RulePriority severity) { ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); initMaps(reportRuleKey); total.incrementResolvedIssuesCount(); ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementResolvedIssuesCount(); totalByRuleKey.get(rule.ruleKey().toString()).incrementResolvedIssuesCount(); totalBySeverity.get(severity.toString()).incrementResolvedIssuesCount(); }
public void addResolvedIssue(Issue issue, Rule rule, RulePriority severity) { ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); initMaps(reportRuleKey); total.incrementResolvedIssuesCount(); ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementResolvedIssuesCount(); totalByRuleKey.get(rule.ruleKey().toString()).incrementResolvedIssuesCount(); totalBySeverity.get(severity.toString()).incrementResolvedIssuesCount(); }
public void addIssue(Issue issue, Rule rule, RulePriority severity) { ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); initMaps(reportRuleKey); ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis(); total.incrementCountInCurrentAnalysis(); totalByRuleKey.get(rule.ruleKey().toString()).incrementCountInCurrentAnalysis(); totalBySeverity.get(severity.toString()).incrementCountInCurrentAnalysis(); if (issue.isNew()) { total.incrementNewIssuesCount(); ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount(); totalByRuleKey.get(rule.ruleKey().toString()).incrementNewIssuesCount(); totalBySeverity.get(severity.toString()).incrementNewIssuesCount(); } }
@VisibleForTesting protected void saveIssue(XmlSourceCode sourceCode) { for (XmlIssue xmlIssue : sourceCode.getXmlIssues()) { Issuable issuable = resourcePerspectives.as(Issuable.class, sourceCode.getSonarFile()); issuable.addIssue( issuable.newIssueBuilder() .ruleKey(xmlIssue.getRule().ruleKey()) .line(xmlIssue.getLine()) .message(xmlIssue.getMessage()) .build()); } }
@Override public void addError(AuditEvent event) { String ruleKey = getRuleKey(event); if (ruleKey != null) { String message = getMessage(event); // In Checkstyle 5.5 exceptions are reported as an events from TreeWalker if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) { LOG.warn(event.getFileName() + ": " + message); } initResource(event); Issuable issuable = perspectives.as(Issuable.class, File.create(currentResource.relativePath())); Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey); if (rule != null && issuable != null) { IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(message) .line(getLineId(event)); issuable.addIssue(issueBuilder.build()); } } }
public void saveViolation(RuleViolation pmdViolation) { InputFile inputFile = findResourceFor(pmdViolation); if (inputFile == null) { // Save violations only for existing resources return; } Issuable issuable = perspectives.as(Issuable.class, inputFile); Rule rule = findRuleFor(pmdViolation); if (issuable == null || rule == null) { // Save violations only for enabled rules return; } IssueBuilder issueBuilder = issuable.newIssueBuilder() .ruleKey(rule.ruleKey()) .message(pmdViolation.getDescription()) .line(pmdViolation.getBeginLine()); issuable.addIssue(issueBuilder.build()); }