org.sonar.api.rules.Rule.ruleKey()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.sonar.api.rules.Rule.ruleKey方法的一些代码示例,展示了Rule.ruleKey的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rule.ruleKey方法的具体详情如下:
包路径:org.sonar.api.rules.Rule
类名称:Rule
方法名:ruleKey

Rule.ruleKey介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

@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);
}

代码示例来源:origin: SonarSource/sonarqube

@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();
}

代码示例来源:origin: SonarSource/sonarqube

@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();
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

/**
 * @deprecated since 4.4 use {@link #setRuleKey(org.sonar.api.rule.RuleKey)}
 */
@Deprecated
public RuleMeasure setRule(Rule rule) {
 this.ruleKey = rule.ruleKey();
 return this;
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

/**
 * 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);
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

public static MeasuresFilter<RuleMeasure> rule(final Metric metric, final Rule rule) {
 return rule(metric, rule.ruleKey());
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-issues-report-plugin

@Override
public int compareTo(ReportRuleKey o) {
 if (severity == o.getSeverity()) {
  return getRule().ruleKey().toString().compareTo(o.getRule().ruleKey().toString());
 }
 return o.getSeverity().compareTo(severity);
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-issues-report-plugin

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());
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

@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);
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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());
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-java-plugin

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));
    }
   }
  }
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@Override
public int compareTo(ReportRuleKey o) {
 if (severity == o.getSeverity()) {
  return getRule().ruleKey().toString().compareTo(o.getRule().ruleKey().toString());
 }
 return o.getSeverity().compareTo(severity);
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-issues-report-plugin

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();
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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();
}

代码示例来源:origin: org.codehaus.sonar-plugins/sonar-issues-report-plugin

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();
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

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();
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.xml/sonar-xml-plugin

@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());
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-checkstyle-plugin

@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());
  }
 }
}

代码示例来源:origin: mrprince/sonar-p3c-pmd

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());
}

相关文章