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

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

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

Rule.getName介绍

暂无

代码示例

代码示例来源: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

@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

@Test
public void should_remove_new_line_characters_in_name_with_first_constructor() {
 Rule rule;
 for (String example : getExamplesContainingNewLineCharacter()) {
  rule = new Rule(null, null).setName(example);
  assertThat(rule.getName()).isEqualTo("test");
 }
}

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

@Test
public void should_remove_new_line_characters_in_name_with_setter() {
 Rule rule = Rule.create();
 for (String example : getExamplesContainingNewLineCharacter()) {
  rule.setName(example);
  assertThat(rule.getName()).isEqualTo("test");
 }
}

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

@Test
public void should_remove_new_line_characters_in_name_with_second_constructor() {
 Rule rule;
 for (String example : getExamplesContainingNewLineCharacter()) {
  rule = new Rule(null, null).setName(example);
  assertThat(rule.getName()).isEqualTo("test");
 }
}

代码示例来源: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: org.codehaus.sonar/sonar-batch

@CheckForNull
private String nameFromDB(RuleKey ruleKey) {
 Rule r = ruleFinder.findByKey(ruleKey);
 return r != null ? r.getName() : null;
}

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

@CheckForNull
private String nameFromDB(RuleKey ruleKey) {
 Rule r = ruleFinder.findByKey(ruleKey);
 return r != null ? r.getName() : null;
}

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

@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: org.sonarsource.sonarqube/sonar-core

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

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

public String nameForHTML(Rule rule) {
 String name = nameFromDB(RuleKey.of(rule.getRepositoryKey(), rule.getKey()));
 return StringEscapeUtils.escapeHtml(name != null ? name : rule.getName());
}

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

public String nameForHTML(Rule rule) {
 String name = nameFromDB(RuleKey.of(rule.getRepositoryKey(), rule.getKey()));
 return StringEscapeUtils.escapeHtml(name != null ? name : rule.getName());
}

代码示例来源:origin: spotbugs/sonar-findbugs

private void activateRulesByCategory(RulesProfile profile, FindBugsFilter filter, ValidationMessages messages) {
 for (Map.Entry<String, String> categoryLevel : filter.getCategoryLevels(new FindbugsLevelUtils()).entrySet()) {
  boolean someRulesHaveBeenActivated = false;
  String sonarCateg = FindbugsCategory.findbugsToSonar(categoryLevel.getKey());
  for (Rule rule : rules()) {
   if (sonarCateg != null && rule.getName().startsWith(sonarCateg)) {
    someRulesHaveBeenActivated = true;
    profile.activateRule(rule, getPriorityFromSeverity(categoryLevel.getValue()));
   }
  }
  if (!someRulesHaveBeenActivated) {
   messages.addWarningText("Unable to find any rules associated to category  : '" + categoryLevel.getKey() + "'");
  }
 }
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

static Ruleset buildRulesetFromActiveProfile(List<ActiveRule> activeRules) {
 Ruleset ruleset = new Ruleset();
 for (ActiveRule activeRule : activeRules) {
  if (activeRule.getRule().getRepositoryKey().equals(DelphiPmdConstants.REPOSITORY_KEY)) {
   String key = activeRule.getRule().getKey();
   String priority = severityToLevel(activeRule.getPriority());
   List<Property> properties = new ArrayList<Property>();
   DelphiRule delphiRule = new DelphiRule(activeRule.getConfigKey(), priority);
   delphiRule.setName(key);
   for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
    properties.add(new Property(activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue()));
   }
   delphiRule.setProperties(properties);
   delphiRule.setMessage(activeRule.getRule().getName());
   ruleset.addRule(delphiRule);
  }
 }
 return ruleset;
}

代码示例来源:origin: SonarSource/sonarlint-core

private static void registerProfile(ActiveRulesBuilder builder, String language, Map.Entry<String, Collection<RulesProfile>> entry) {
 for (RulesProfile rp : entry.getValue()) {
  for (ActiveRule ar : rp.getActiveRules()) {
   Builder newAr = new NewActiveRule.Builder()
    .setRuleKey(RuleKey.of(ar.getRepositoryKey(), ar.getRuleKey()))
    .setLanguage(language)
    .setName(ar.getRule().getName())
    .setSeverity(ar.getSeverity().name())
    .setInternalKey(ar.getConfigKey());
   for (ActiveRuleParam param : ar.getActiveRuleParams()) {
    newAr.setParam(param.getKey(), param.getValue());
   }
   builder.addRule(newAr.build());
  }
 }
}

代码示例来源:origin: fabriciocolombo/sonar-delphi

@Override
public void define(Context context) {
 NewRepository repository = context
  .createRepository(DelphiPmdConstants.REPOSITORY_KEY, DelphiLanguage.KEY)
  .setName(DelphiPmdConstants.REPOSITORY_NAME);
 List<org.sonar.api.rules.Rule> rules = DelphiRulesUtils.getInitialReferential();
 // TODO Review
 // https://github.com/SonarCommunity/sonar-pmd/blob/master/src/main/java/org/sonar/plugins/pmd/PmdRulesDefinition.java
 for (org.sonar.api.rules.Rule rule : rules) {
  NewRule newRule = repository.createRule(rule.getKey())
   .setName(rule.getName())
   .setHtmlDescription(rule.getDescription())
   .setInternalKey(rule.getConfigKey())
   .setSeverity(rule.getSeverity().name());
  for (RuleParam param : rule.getParams()) {
   newRule.createParam(param.getKey())
    .setDefaultValue(param.getDefaultValue())
    .setType(RuleParamType.parse(param.getType()))
    .setDescription(param.getDescription());
  }
 }
 SqaleXmlLoader.load(repository, "/org/sonar/plugins/delphi/sqale/delphi-model.xml");
 repository.done();
}

相关文章