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

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

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

Rule.getKey介绍

暂无

代码示例

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

/**
 * @return the key of the active rule
 */
public String getRuleKey() {
 return rule.getKey();
}

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

@Override
public boolean equals(Object obj) {
 if (!(obj instanceof Rule)) {
  return false;
 }
 if (this == obj) {
  return true;
 }
 Rule other = (Rule) obj;
 return new EqualsBuilder()
  .append(pluginName, other.getRepositoryKey())
  .append(key, other.getKey())
  .isEquals();
}

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

/**
 * Note: disabled rules are excluded.
 */
@CheckForNull
public ActiveRule getActiveRule(Rule rule) {
 return getActiveRule(rule.getRepositoryKey(), rule.getKey());
}

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

@CheckForNull
private String ruleDescription(String repositoryKey, org.sonar.api.rules.Rule rule) {
 String description = i18n.getDescription(repositoryKey, rule.getKey());
 if (StringUtils.isNotBlank(description)) {
  return description;
 }
 return StringUtils.defaultIfBlank(rule.getDescription(), null);
}

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

/**
 * @since 3.6
 */
public RuleKey ruleKey() {
 return RuleKey.of(getRepositoryKey(), getKey());
}

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

@CheckForNull
private String ruleName(String repositoryKey, org.sonar.api.rules.Rule rule) {
 String name = i18n.getName(repositoryKey, rule.getKey());
 if (StringUtils.isNotBlank(name)) {
  return name;
 }
 return StringUtils.defaultIfBlank(rule.getName(), null);
}

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

@Override
@CheckForNull
public String getName(Rule rule) {
 String name = message(rule.getRepositoryKey(), rule.getKey(), NAME_SUFFIX);
 return name != null ? name : rule.getName();
}

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

/**
 * @param optionalSeverity if null, then the default rule severity is used
 */
public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) {
 if (activeRules.stream().anyMatch(ar -> ar.getRule().equals(rule))) {
  throw MessageException.of(String.format(
   "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.",
   getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey()));
 }
 ActiveRule activeRule = new ActiveRule(this, rule, optionalSeverity);
 activeRules.add(activeRule);
 return activeRule;
}

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

@Test
public void rule_without_key() {
 List<Rule> rules = parseAnnotatedClass(RuleWithoutKey.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo(RuleWithoutKey.class.getCanonicalName());
 assertThat(rule.getName()).isEqualTo("foo");
 assertThat(rule.getDescription()).isNull();
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
}

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

@Test
public void overridden_rule() {
 List<Rule> rules = parseAnnotatedClass(OverridingRule.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo("overriding_foo");
 assertThat(rule.getName()).isEqualTo("Overriding Foo");
 assertThat(rule.getDescription()).isNull();
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 assertThat(rule.getParams()).hasSize(2);
}

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

@Test
public void rule_without_name_nor_description() {
 List<Rule> rules = parseAnnotatedClass(RuleWithoutNameNorDescription.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo("foo");
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 assertThat(rule.getName()).isNull();
 assertThat(rule.getDescription()).isNull();
}

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

if (Strings.isNullOrEmpty(rule.getKey())) {
 throw new SonarException("Node <key> is missing in <rule>");

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

private static RuleKey toRuleKey(Rule rule) {
 return RuleKey.of(rule.getRepositoryKey(), rule.getKey());
}

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

@Test
public void rule_with_property() {
 List<Rule> rules = parseAnnotatedClass(RuleWithProperty.class);
 assertThat(rules).hasSize(1);
 Rule rule = rules.get(0);
 assertThat(rule.getKey()).isEqualTo("foo");
 assertThat(rule.getName()).isEqualTo("bar");
 assertThat(rule.getDescription()).isEqualTo("Foo Bar");
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY);
 assertThat(rule.getParams()).hasSize(1);
 RuleParam prop = rule.getParam("property");
 assertThat(prop.getKey()).isEqualTo("property");
 assertThat(prop.getDescription()).isEqualTo("Ignore ?");
 assertThat(prop.getDefaultValue()).isEqualTo("false");
 assertThat(prop.getType()).isEqualTo(PropertyType.STRING.name());
}

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

private void verifyRule(Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) {
  assertThat(rule).isNotNull();

  assertThat(rule.getName()).isEqualTo(ruleDefinition.getName());
  assertThat(rule.getLanguage()).isEqualTo(ruleDefinition.getLanguage());
  assertThat(rule.getKey()).isEqualTo(ruleDefinition.getRuleKey());
  assertThat(rule.getConfigKey()).isEqualTo(ruleDefinition.getConfigKey());
  assertThat(rule.isTemplate()).isEqualTo(ruleDefinition.isTemplate());
  assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDefinition.getCreatedAt());
  assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt());
  assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey());
  assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
  assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().stream().toArray(String[]::new));
  assertThat(rule.getTags()).isEmpty();
  assertThat(rule.getId()).isEqualTo(ruleDefinition.getId());
  assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription());

  assertThat(rule.getParams()).hasSize(1);
  org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next();
  assertThat(param.getRule()).isSameAs(rule);
  assertThat(param.getKey()).isEqualTo(ruleParam.getName());
  assertThat(param.getDescription()).isEqualTo(ruleParam.getDescription());
  assertThat(param.getType()).isEqualTo(ruleParam.getType());
  assertThat(param.getDefaultValue()).isEqualTo(ruleParam.getDefaultValue());
 }
}

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

@Test
public void should_success_finder_wrap() {
 // has Id
 assertThat(underTest.findById(rule1.getId()).getId()).isEqualTo(rule1.getId());
 // should_find_by_id
 assertThat(underTest.findById(rule3.getId()).getConfigKey()).isEqualTo("Checker/Treewalker/AnnotationUseStyleCheck");
 // should_not_find_disabled_rule_by_id
 assertThat(underTest.findById(rule2.getId())).isNull();
 // should_find_by_key
 Rule rule = underTest.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck");
 assertThat(rule).isNotNull();
 assertThat(rule.getKey()).isEqualTo(("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"));
 assertThat(rule.isEnabled()).isTrue();
 // find_should_return_null_if_no_results
 assertThat(underTest.findByKey("checkstyle", "unknown")).isNull();
 assertThat(underTest.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown"))).isNull();
 // find_repository_rules
 assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2);
 // find_all_enabled
 assertThat(underTest.findAll(RuleQuery.create())).extracting("id").containsOnly(rule1.getId(), rule3.getId(), rule4.getId());
 assertThat(underTest.findAll(RuleQuery.create())).hasSize(3);
 // do_not_find_disabled_rules
 assertThat(underTest.findByKey("checkstyle", "DisabledCheck")).isNull();
 // do_not_find_unknown_rules
 assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"))).isEmpty();
}

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

RulesDefinition.NewRule newRule = newRepository.createRule(rule.getKey());
newRule.setName(ruleName(repository.getKey(), rule));
newRule.setHtmlDescription(ruleDescription(repository.getKey(), rule));
 RulesDefinition.NewParam newParam = newRule.createParam(param.getKey());
 newParam.setDefaultValue(param.getDefaultValue());
 newParam.setDescription(paramDescription(repository.getKey(), rule.getKey(), param));
 newParam.setType(RuleParamType.parse(param.getType()));
updateRuleDebtDefinitions(newRule, repository.getKey(), rule.getKey(), ruleDebts);

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

/**
 * @return the key of the active rule
 */
public String getRuleKey() {
 return rule.getKey();
}

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

/**
 * Note: disabled rules are excluded.
 */
@CheckForNull
public ActiveRule getActiveRule(Rule rule) {
 return getActiveRule(rule.getRepositoryKey(), rule.getKey());
}

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

/**
 * @since 3.6
 */
public RuleKey ruleKey() {
 return RuleKey.of(getRepositoryKey(), getKey());
}

相关文章