use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RegisterRules method registerRule.
private void registerRule(RulesDefinition.Rule ruleDef, Map<RuleKey, RuleDto> allRules, DbSession session) {
RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
boolean executeUpdate = false;
if (mergeRule(ruleDef, rule)) {
executeUpdate = true;
}
if (mergeDebtDefinitions(ruleDef, rule)) {
executeUpdate = true;
}
if (mergeTags(ruleDef, rule)) {
executeUpdate = true;
}
if (executeUpdate) {
update(session, rule);
}
mergeParams(ruleDef, rule, session);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class IssuePatternTest method match_rule.
@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();
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method verifyHasActiveRuleInIndex.
private void verifyHasActiveRuleInIndex(ActiveRuleKey activeRuleKey, String expectedSeverity, @Nullable String expectedInheritance) {
// verify es
List<RuleKey> ruleKeys = newArrayList(tester.get(RuleIndex.class).searchAll(new RuleQuery().setKey(activeRuleKey.ruleKey().toString()).setQProfileKey(activeRuleKey.qProfile()).setActivation(true).setInheritance(singleton(expectedInheritance == null ? ActiveRule.Inheritance.NONE.name() : ActiveRule.Inheritance.valueOf(expectedInheritance).name())).setActiveSeverities(singleton(expectedSeverity))));
assertThat(ruleKeys).as("Rule is not activated in index").hasSize(1);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class UpdateActionMediumTest method update_custom_rule.
@Test
public void update_custom_rule() throws Exception {
// Template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
ruleDao.insert(session, templateRule);
RuleParamDto param = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*");
ruleDao.insertRuleParam(session, templateRule, param);
session.commit();
// Custom rule
NewCustomRule newRule = NewCustomRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()).setName("Old custom").setHtmlDescription("Old description").setSeverity(Severity.MINOR).setStatus(RuleStatus.BETA).setParameters(ImmutableMap.of("regex", "a"));
RuleKey customRuleKey = tester.get(RuleCreator.class).create(newRule);
session.clearCache();
WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update").setParam("key", customRuleKey.toString()).setParam("name", "My custom rule").setParam("markdown_description", "Description").setParam("severity", "MAJOR").setParam("status", "BETA").setParam("params", "regex=a.*");
request.execute().assertJson(getClass(), "update_custom_rule.json");
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class OneIssuePerLineSensor method createIssues.
private void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY);
for (int line = 1; line <= file.lines(); line++) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line)).message("This issue is generated on each line")).overrideSeverity(severity != null ? Severity.valueOf(severity) : null);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
} else {
newIssue.effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
}
newIssue.save();
}
}
Aggregations