本文整理了Java中org.sonar.api.rules.Rule.setSeverity
方法的一些代码示例,展示了Rule.setSeverity
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rule.setSeverity
方法的具体详情如下:
包路径:org.sonar.api.rules.Rule
类名称:Rule
方法名:setSeverity
暂无
代码示例来源: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
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
代码示例来源:origin: SonarSource/sonarqube
@Test
public void fail_to_activate_already_activated_rule() {
RulesProfile profile = RulesProfile.create("Default", "java");
Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL);
profile.activateRule(rule, null);
try {
profile.activateRule(rule, null);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(MessageException.class)
.hasMessage("The definition of the profile 'Default' (language 'java') contains multiple occurrences of the 'repo:key1' rule. The plugin which declares this profile should fix this.");
}
}
}
代码示例来源: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 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
private static Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) {
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());
rule.setStatus(ruleAnnotation.status());
rule.setTags(ruleAnnotation.tags());
List<Field> fields = FieldUtils2.getFields(clazz, true);
for (Field field : fields) {
addRuleProperty(rule, field);
}
return rule;
}
代码示例来源: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
.setUpdatedAt(new Date(rule.getUpdatedAt()))
.setRepositoryKey(rule.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(rule.getStatus().name())
.setSystemTags(rule.getSystemTags().toArray(new String[rule.getSystemTags().size()]))
代码示例来源:origin: SonarSource/sonarqube
.setUpdatedAt(new Date(ruleDefinition.getUpdatedAt()))
.setRepositoryKey(ruleDefinition.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(ruleDefinition.getStatus().name())
.setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
代码示例来源:origin: octo-technology/sonar-objective-c
final String severity = line.substring("Severity: ".length());
rule.setSeverity(RulePriority.values()[Integer.valueOf(severity)]);
} else {
if (inDescription) {
代码示例来源:origin: org.codehaus.sonar/sonar-deprecated
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
代码示例来源:origin: octo-technology/sonar-objective-c
private void recordViolation(final org.sonar.api.resources.File resource,
final SMInputCursor line) throws XMLStreamException {
final Rule rule = Rule.create();
final Violation violation = Violation.create(rule, resource);
// PMD Priorities are 1, 2, 3, 4, 5 RulePriority[0] is INFO
rule.setSeverity(RulePriority.values()[PMD_MINIMUM_PRIORITY
- Integer.valueOf(line.getAttrValue("priority"))]);
rule.setKey(line.getAttrValue("rule"));
rule.setRepositoryKey(OCLintRuleRepository.REPOSITORY_KEY);
violation.setLineId(Integer.valueOf(line.getAttrValue("beginline")));
violation.setMessage(line.getElemStringValue());
foundViolations.add(violation);
}
代码示例来源:origin: org.codehaus.sonar-plugins/sonar-web-plugin
public static Rule createRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation, @Nullable RuleTags 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;
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api
private static Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) {
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());
rule.setStatus(ruleAnnotation.status());
rule.setTags(ruleAnnotation.tags());
List<Field> fields = FieldUtils2.getFields(clazz, true);
for (Field field : fields) {
addRuleProperty(rule, field);
}
return rule;
}
代码示例来源:origin: org.codehaus.sonar/sonar-deprecated
private Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) {
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());
rule.setStatus(ruleAnnotation.status());
rule.setTags(ruleAnnotation.tags());
List<Field> fields = FieldUtils2.getFields(clazz, true);
for (Field field : fields) {
addRuleProperty(rule, field);
}
return rule;
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
.setUpdatedAt(new Date(rule.getUpdatedAt()))
.setRepositoryKey(rule.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(rule.getStatus().name())
.setSystemTags(rule.getSystemTags().toArray(new String[rule.getSystemTags().size()]))
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
.setUpdatedAt(new Date(ruleDefinition.getUpdatedAt()))
.setRepositoryKey(ruleDefinition.getRepositoryKey())
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(ruleDefinition.getStatus().name())
.setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
代码示例来源:origin: fabriciocolombo/sonar-delphi
private static Rule createRepositoryRule(DelphiRule fRule) {
RulePriority priority = severityFromLevel(fRule.getPriority());
Rule rule = Rule.create(DelphiPmdConstants.REPOSITORY_KEY, fRule.getName(), fRule.getMessage()).setSeverity(
priority);
rule.setDescription(fRule.getDescription());
rule.setTags(fRule.getTags());
rule.setConfigKey(fRule.getClazz());
List<RuleParam> ruleParams = new ArrayList<RuleParam>();
if (fRule.getProperties() != null) {
for (Property property : fRule.getProperties()) {
RuleParam param = rule.createParameter()
.setKey(property.getName())
.setDescription(property.getName())
.setType("s");
if (NumberUtils.isNumber(property.getValue())) {
param.setType("i");
}
param.setDefaultValue(property.getValue());
ruleParams.add(param);
}
}
rule.setParams(ruleParams);
return rule;
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
代码示例来源:origin: SonarSource/sonarlint-core
private static Rule toRuleNotNull(RulesDefinition.Rule ruleDef) {
Rule rule = Rule.create(ruleDef.repository().key(), ruleDef.key())
.setName(ruleDef.name())
.setSeverity(RulePriority.valueOf(ruleDef.severity()))
.setLanguage(ruleDef.repository().language())
.setIsTemplate(ruleDef.template())
.setConfigKey(ruleDef.internalKey());
for (Param param : ruleDef.params()) {
rule.createParameter(param.key()).setDefaultValue(param.defaultValue()).setDescription(param.description());
}
return rule;
}
内容来源于网络,如有侵权,请联系作者删除!