当前位置: 首页>>代码示例>>Java>>正文


Java Rule.create方法代码示例

本文整理汇总了Java中org.sonar.api.rules.Rule.create方法的典型用法代码示例。如果您正苦于以下问题:Java Rule.create方法的具体用法?Java Rule.create怎么用?Java Rule.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.sonar.api.rules.Rule的用法示例。


在下文中一共展示了Rule.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCheckstyleConfiguration

import org.sonar.api.rules.Rule; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void getCheckstyleConfiguration() throws Exception {
    fileSystem.setEncoding(StandardCharsets.UTF_8);
    final Settings settings = new Settings(new PropertyDefinitions(
            new CheckstylePlugin().getExtensions()));
    settings.setProperty(CheckstyleConstants.CHECKER_FILTERS_KEY,
            CheckstyleConstants.CHECKER_FILTERS_DEFAULT_VALUE);

    final RulesProfile profile = RulesProfile.create("sonar way", "java");

    final Rule rule = Rule.create("checkstyle", "CheckStyleRule1", "checkstyle rule one");
    rule.setConfigKey("checkstyle/rule1");
    profile.activateRule(rule, null);

    final CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings,
            new CheckstyleProfileExporter(settings), profile, fileSystem);
    final Configuration checkstyleConfiguration = configuration.getCheckstyleConfiguration();
    assertThat(checkstyleConfiguration).isNotNull();
    assertThat(checkstyleConfiguration.getAttribute("charset")).isEqualTo("UTF-8");
    final File xmlFile = new File("checkstyle.xml");
    assertThat(xmlFile.exists()).isTrue();

    FileUtils.forceDelete(xmlFile);
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:26,代码来源:CheckstyleConfigurationTest.java

示例2: createRule

import org.sonar.api.rules.Rule; //导入方法依赖的package包/类
public static Rule createRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation, @Nullable TanaguruRuleTags ruleTagsAnnotation) {
  String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
  String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
  String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null);
  Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
  rule.setDescription(description);
  rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
  rule.setCardinality(ruleAnnotation.cardinality());
  setTags(rule, ruleTagsAnnotation);

  Field[] fields = clazz.getDeclaredFields();
  if (fields != null) {
    for (Field field : fields) {
      addRuleProperty(rule, field);
    }
  }

  return rule;
}
 
开发者ID:Asqatasun,项目名称:Asqatasun-Sonar-Plugin,代码行数:20,代码来源:RuleRepositoryHelper.java

示例3: should_fail_when_incorrect_severity

import org.sonar.api.rules.Rule; //导入方法依赖的package包/类
@Test
public void should_fail_when_incorrect_severity() {
  Settings settings = newCorrectSettings();
  ActiveRule activeRule = new ActiveRule(profile, Rule.create("repositoryKey", "ruleKey"), RulePriority.BLOCKER);
  when(profile.getActiveRules()).thenReturn(Arrays.asList(activeRule));
  when(profile.getName()).thenReturn("profileName");

  thrown.expect(MessageException.class);
  thrown.expectMessage("Rule 'repositoryKey:ruleKey' must be declared with severity INFO");
  new IssuesChecker(settings, profile);
}
 
开发者ID:SonarSource,项目名称:sonar-lits,代码行数:12,代码来源:IssuesCheckerTest.java


注:本文中的org.sonar.api.rules.Rule.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。