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

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

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

Rule.create介绍

[英]Create with all required fields
[中]使用所有必填字段创建

代码示例

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

@Override
 public RulesProfile createProfile(ValidationMessages validation) {
  final RulesProfile profile = RulesProfile.create("Sonar way", Xoo.KEY);

  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.INFO);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY), RulePriority.CRITICAL);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY), RulePriority.CRITICAL);

  return profile;
 }
}

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

@Override
 public List<Rule> createRules() {
  Rule rule = Rule.create("checkstyle", "ConstantName");
  rule.createParameter("format");
  return Arrays.asList(rule);
 }
}

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

@Override
 public RulesProfile createProfile(ValidationMessages messages) {
  RulesProfile profile = RulesProfile.create("Sonar way", Xoo2.KEY);

  profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);
  profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.MINOR);

  return profile;
 }
}

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

public Rule answer(InvocationOnMock iom) throws Throwable {
  Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
  rule.createParameter("format");
  rule.createParameter("message");
  return rule;
 }
});

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

@Override
 public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
  RulesProfile rulesProfile = RulesProfile.create();
  rulesProfile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.CRITICAL);
  return rulesProfile;
 }
}

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

@Override
 public List<Rule> createRules() {
  Rule rule = Rule.create("checkstyle", "ConstantName", "Constant Name");
  rule.setDescription("Checks that constant names conform to the specified format");
  rule.setConfigKey("Checker/TreeWalker/ConstantName");
  rule.setSeverity(RulePriority.BLOCKER);
  rule.setStatus(Rule.STATUS_BETA);
  rule.setTags(new String[] {"style", "clumsy"});
  rule.createParameter("format").setDescription("Regular expression").setDefaultValue("A-Z").setType("REGULAR_EXPRESSION");
  return Arrays.asList(rule);
 }
}

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

@Override
 public RulesProfile createProfile(ValidationMessages validation) {
  final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY);
  profile.setDefaultProfile(true);

  profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);

  return profile;
 }
}

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

@Override
 public RulesProfile createProfile(ValidationMessages messages) {
  RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY);
  profile.setDefaultProfile(true);

  // so UGLY
  profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR);

  return profile;
 }
}

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

@Test
public void should_set_valid_status() {
 Rule rule = Rule.create().setStatus(Rule.STATUS_DEPRECATED);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_DEPRECATED);
 rule = Rule.create().setStatus(Rule.STATUS_REMOVED);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_REMOVED);
 rule = Rule.create().setStatus(Rule.STATUS_BETA);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_BETA);
 rule = Rule.create().setStatus(Rule.STATUS_READY);
 assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY);
}

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

@Override
 public RulesProfile createProfile(ValidationMessages validation) {
  RulesProfile profile1 = RulesProfile.create("Profile 1", "xoo");
  profile1.activateRule(Rule.create("repo1", "defaultSeverity"), null);
  profile1.activateRule(Rule.create("repo1", "overrideSeverity"), RulePriority.CRITICAL);
  Rule ruleWithParam = Rule.create("repo1", "overrideParam");
  ruleWithParam.setParams(Arrays.asList(new RuleParam(ruleWithParam, "param", "", "")));
  ActiveRule arWithParam = profile1.activateRule(ruleWithParam, null);
  arWithParam.setParameter("param", "value");
  return profile1;
 }
}

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

@Test
public void default_priority_is_major() {
 Rule rule = Rule.create();
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 rule = new Rule("name", "key");
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
 rule.setSeverity(RulePriority.BLOCKER);
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER);
 rule.setSeverity(null);
 assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
}

代码示例来源: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 searchRulesByConfigKey() {
 RulesProfile profile = RulesProfile.create();
 profile.activateRule(Rule.create("repo", "key1", "name1"), null);
 profile.activateRule(Rule.create("repo", "key2", "name2").setConfigKey("config2"), null);
 assertThat(profile.getActiveRuleByConfigKey("repo", "unknown")).isNull();
 assertThat(profile.getActiveRuleByConfigKey("repo", "config2").getRuleKey()).isEqualTo("key2");
}

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

@Test
public void activateRuleWithDefaultPriority() {
 RulesProfile profile = RulesProfile.create();
 Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
 profile.activateRule(rule, null);
 assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.CRITICAL);
}

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

@Test
public void activateRuleWithSpecificPriority() {
 RulesProfile profile = RulesProfile.create();
 Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
 profile.activateRule(rule, RulePriority.MINOR);
 assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR);
}

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

@Test
public void exportProfile() throws IOException, SAXException {
 Writer writer = new StringWriter();
 RulesProfile profile = RulesProfile.create("sonar way", "java");
 profile.activateRule(Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"), RulePriority.BLOCKER);
 new XMLProfileSerializer().write(profile, writer);
 assertSimilarXml("exportProfile.xml", writer.toString());
}

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

@Override
 public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
  RulesProfile rulesProfile = RulesProfile.create();
  rulesProfile.activateRule(Rule.create(rule.getRepositoryKey(), rule.getRuleKey()), RulePriority.CRITICAL);
  return rulesProfile;
 }
}

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

@Test
public void description_should_be_cleaned() {
 Rule rule = Rule.create().setDescription("    my description         ");
 Assert.assertEquals("my description", rule.getDescription());
 rule.setDescription(null);
 assertThat(rule.getDescription()).isNull();
}

相关文章