use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class IssueDtoTest method set_rule.
@Test
public void set_rule() {
IssueDto dto = new IssueDto().setKee("100").setRule(new RuleDto().setId(1).setRuleKey("AvoidCycle").setRepositoryKey("squid")).setLanguage("xoo");
assertThat(dto.getRuleId()).isEqualTo(1);
assertThat(dto.getRuleRepo()).isEqualTo("squid");
assertThat(dto.getRule()).isEqualTo("AvoidCycle");
assertThat(dto.getRuleKey().toString()).isEqualTo("squid:AvoidCycle");
assertThat(dto.getLanguage()).isEqualTo("xoo");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleRepositoryImpl method loadRulesFromDb.
private void loadRulesFromDb(DbSession dbSession) {
ImmutableMap.Builder<RuleKey, Rule> rulesByKeyBuilder = ImmutableMap.builder();
ImmutableMap.Builder<Integer, Rule> rulesByIdBuilder = ImmutableMap.builder();
for (RuleDto ruleDto : dbClient.ruleDao().selectAll(dbSession)) {
Rule rule = new RuleImpl(ruleDto);
rulesByKeyBuilder.put(ruleDto.getKey(), rule);
rulesByIdBuilder.put(ruleDto.getId(), rule);
}
this.rulesByKey = rulesByKeyBuilder.build();
this.rulesById = rulesByIdBuilder.build();
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class IssueUpdater method saveIssue.
public void saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
issueStorage.save(session, issue);
Optional<RuleDto> rule = getRuleByKey(session, issue.getRuleKey());
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, issue.projectUuid());
notificationService.scheduleForSending(new IssueChangeNotification().setIssue(issue).setChangeAuthorLogin(context.login()).setRuleName(rule.isPresent() ? rule.get().getName() : null).setProject(project.getKey(), project.name()).setComponent(dbClient.componentDao().selectOrFailByUuid(session, issue.componentUuid())).setComment(comment));
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class ActiveRuleCompleter method writeActiveRules.
private Collection<String> writeActiveRules(DbSession dbSession, SearchResponse.Builder response, RuleQuery query, List<RuleDto> rules) {
Collection<String> qProfileKeys = newHashSet();
Rules.Actives.Builder activesBuilder = response.getActivesBuilder();
String profileKey = query.getQProfileKey();
if (profileKey != null) {
// Load details of active rules on the selected profile
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profileKey);
Map<RuleKey, ActiveRuleDto> activeRuleByRuleKey = from(activeRuleDtos).uniqueIndex(ActiveRuleToRuleKey.INSTANCE);
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = activeRuleDtosToActiveRuleParamDtos(dbSession, activeRuleDtos);
for (RuleDto rule : rules) {
ActiveRuleDto activeRule = activeRuleByRuleKey.get(rule.getKey());
if (activeRule != null) {
qProfileKeys = writeActiveRules(rule.getKey(), singletonList(activeRule), activeRuleParamsByActiveRuleKey, activesBuilder);
}
}
} else {
// Load details of all active rules
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByRuleIds(dbSession, Lists.transform(rules, RuleDto::getId));
Multimap<RuleKey, ActiveRuleDto> activeRulesByRuleKey = from(activeRuleDtos).index(ActiveRuleToRuleKey.INSTANCE);
ListMultimap<ActiveRuleKey, ActiveRuleParamDto> activeRuleParamsByActiveRuleKey = activeRuleDtosToActiveRuleParamDtos(dbSession, activeRuleDtos);
for (RuleDto rule : rules) {
qProfileKeys = writeActiveRules(rule.getKey(), activeRulesByRuleKey.get(rule.getKey()), activeRuleParamsByActiveRuleKey, activesBuilder);
}
}
response.setActives(activesBuilder);
return qProfileKeys;
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRules method start.
@Override
public void start() {
Profiler profiler = Profiler.create(LOG).startInfo("Register rules");
DbSession session = dbClient.openSession(false);
try {
Map<RuleKey, RuleDto> allRules = loadRules(session);
RulesDefinition.Context context = defLoader.load();
for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
if (languages.get(repoDef.language()) != null) {
for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
registerRule(ruleDef, allRules, session);
}
session.commit();
}
}
List<RuleDto> activeRules = processRemainingDbRules(allRules.values(), session);
List<ActiveRuleChange> changes = removeActiveRulesOnStillExistingRepositories(session, activeRules, context);
session.commit();
persistRepositories(session, context.repositories());
ruleIndexer.index();
activeRuleIndexer.index(changes);
profiler.stopDebug();
} finally {
session.close();
}
}
Aggregations