use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class LoadQualityProfilesStep method convert.
private static ActiveRule convert(ScannerReport.ActiveRule input) {
RuleKey key = RuleKey.of(input.getRuleRepository(), input.getRuleKey());
Map<String, String> params = new HashMap<>(input.getParamsByKey());
return new ActiveRule(key, input.getSeverity().name(), params, input.getCreatedAt());
}
use of org.sonar.api.rule.RuleKey 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.api.rule.RuleKey in project sonarqube by SonarSource.
the class QProfileBackuper method parseRuleActivations.
private List<RuleActivation> parseRuleActivations(SMInputCursor rulesCursor) throws XMLStreamException {
List<RuleActivation> activations = Lists.newArrayList();
Set<RuleKey> activatedKeys = Sets.newHashSet();
List<RuleKey> duplicatedKeys = Lists.newArrayList();
while (rulesCursor.getNext() != null) {
SMInputCursor ruleCursor = rulesCursor.childElementCursor();
String repositoryKey = null;
String key = null;
String severity = null;
Map<String, String> parameters = Maps.newHashMap();
while (ruleCursor.getNext() != null) {
String nodeName = ruleCursor.getLocalName();
if (StringUtils.equals("repositoryKey", nodeName)) {
repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false));
} else if (StringUtils.equals("key", nodeName)) {
key = StringUtils.trim(ruleCursor.collectDescendantText(false));
} else if (StringUtils.equals("priority", nodeName)) {
severity = StringUtils.trim(ruleCursor.collectDescendantText(false));
} else if (StringUtils.equals("parameters", nodeName)) {
SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter");
readParameters(propsCursor, parameters);
}
}
RuleKey ruleKey = RuleKey.of(repositoryKey, key);
if (activatedKeys.contains(ruleKey)) {
duplicatedKeys.add(ruleKey);
}
activatedKeys.add(ruleKey);
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(severity);
activation.setParameters(parameters);
activations.add(activation);
}
if (!duplicatedKeys.isEmpty()) {
throw new IllegalArgumentException("The quality profile cannot be restored as it contains duplicates for the following rules: " + RULE_KEY_JOINER.join(duplicatedKeys));
}
return activations;
}
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;
}
Aggregations