use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class OneIssueOnDirPerFileSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
InputDir inputDir = context.fileSystem().inputDir(file.file().getParentFile());
if (inputDir != null) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputDir).message("This issue is generated for file " + file.relativePath())).save();
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class ActiveRuleKeyTest method rule_key_can_contain_colons.
@Test
public void rule_key_can_contain_colons() {
RuleKey ruleKey = RuleKey.of("squid", "Key:With:Some::Colons");
ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey);
assertThat(key.qProfile()).isEqualTo("P1");
assertThat(key.ruleKey()).isSameAs(ruleKey);
assertThat(key.toString()).isEqualTo("P1:squid:Key:With:Some::Colons");
}
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;
}
Aggregations