use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class QProfileComparison method compareActivationParams.
private void compareActivationParams(DbSession session, ActiveRuleDto leftRule, ActiveRuleDto rightRule, QProfileComparisonResult result) {
RuleKey key = leftRule.getKey().ruleKey();
Map<String, String> leftParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, leftRule.getId()));
Map<String, String> rightParams = paramDtoToMap(dbClient.activeRuleDao().selectParamsByActiveRuleId(session, rightRule.getId()));
if (leftParams.equals(rightParams) && leftRule.getSeverityString().equals(rightRule.getSeverityString())) {
result.same.put(key, leftRule);
} else {
ActiveRuleDiff diff = new ActiveRuleDiff();
diff.leftSeverity = leftRule.getSeverityString();
diff.rightSeverity = rightRule.getSeverityString();
diff.paramDifference = Maps.difference(leftParams, rightParams);
result.modified.put(key, diff);
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleResultSetIterator method read.
@Override
protected RuleDoc read(ResultSet rs) throws SQLException {
RuleDoc doc = new RuleDoc(Maps.<String, Object>newHashMapWithExpectedSize(16));
String ruleKey = rs.getString(1);
String repositoryKey = rs.getString(2);
RuleKey key = RuleKey.of(repositoryKey, ruleKey);
// all the fields must be present, even if value is null
doc.setKey(key.toString());
doc.setRuleKey(ruleKey);
doc.setRepository(repositoryKey);
doc.setName(rs.getString(3));
String description = rs.getString(4);
String descriptionFormat = rs.getString(5);
if (descriptionFormat != null) {
if (RuleDto.Format.HTML.equals(RuleDto.Format.valueOf(descriptionFormat))) {
doc.setHtmlDescription(description);
} else {
doc.setHtmlDescription(description == null ? null : Markdown.convertToHtml(description));
}
}
doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(6)));
doc.setStatus(rs.getString(7));
doc.setIsTemplate(rs.getBoolean(8));
doc.setAllTags(Sets.union(stringTagsToSet(rs.getString(9)), stringTagsToSet(rs.getString(10))));
String templateRuleKey = rs.getString(11);
String templateRepoKey = rs.getString(12);
if (templateRepoKey != null && templateRuleKey != null) {
doc.setTemplateKey(RuleKey.of(templateRepoKey, templateRuleKey).toString());
} else {
doc.setTemplateKey(null);
}
doc.setInternalKey(rs.getString(13));
doc.setLanguage(rs.getString(14));
doc.setType(RuleType.valueOf(rs.getInt(15)));
doc.setCreatedAt(rs.getLong(16));
doc.setUpdatedAt(rs.getLong(17));
return doc;
}
use of org.sonar.api.rule.RuleKey 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.api.rule.RuleKey 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();
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class ActiveRuleResultSetIterator method read.
@Override
protected ActiveRuleDoc read(ResultSet rs) throws SQLException {
RuleKey ruleKey = RuleKey.of(rs.getString(4), rs.getString(3));
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(rs.getString(5), ruleKey);
ActiveRuleDoc doc = new ActiveRuleDoc(activeRuleKey);
// all the fields must be present, even if value is null
doc.setSeverity(SeverityUtil.getSeverityFromOrdinal(rs.getInt(1)));
String inheritance = rs.getString(2);
doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
doc.setCreatedAt(rs.getLong(6));
doc.setUpdatedAt(rs.getLong(7));
return doc;
}
Aggregations