本文整理汇总了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);
}
示例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;
}
示例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);
}