use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.
the class QProfileExporters method importXml.
private QProfileResult importXml(QualityProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
QProfileResult result = new QProfileResult();
ValidationMessages messages = ValidationMessages.create();
ProfileImporter importer = getProfileImporter(importerKey);
RulesProfile rulesProfile = importer.importProfile(xml, messages);
List<ActiveRuleChange> changes = importProfile(profileDto, rulesProfile, dbSession);
result.addChanges(changes);
processValidationMessages(messages, result);
return result;
}
use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.
the class RulesProfileProvider method select.
private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
RulesProfile deprecatedProfile = new RulesProfile();
deprecatedProfile.setName(qProfile.getName());
deprecatedProfile.setLanguage(qProfile.getLanguage());
for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) {
Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule());
rule.setConfigKey(activeRule.internalKey());
// SONAR-6706
if (activeRule.templateRuleKey() != null) {
rule.setTemplate(Rule.create(activeRule.ruleKey().repository(), activeRule.templateRuleKey()));
}
ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule, RulePriority.valueOf(activeRule.severity()));
for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
rule.createParameter(param.getKey());
deprecatedActiveRule.setParameter(param.getKey(), param.getValue());
}
}
return deprecatedProfile;
}
use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.
the class RulesProfileProviderTest method keep_compatibility_with_single_language_projects.
@Test
public void keep_compatibility_with_single_language_projects() {
settings.setProperty("sonar.language", "java");
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findByLanguage("java")).thenReturn(qProfile);
RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings);
// no merge, directly the old hibernate profile
assertThat(profile).isNotNull();
assertThat(profile.getLanguage()).isEqualTo("java");
assertThat(profile.getName()).isEqualTo("Sonar way");
}
use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.
the class RulesProfileProviderTest method merge_profiles.
@Test
public void merge_profiles() {
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings);
// merge of all profiles
assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class);
assertThat(profile.getLanguage()).isEqualTo("");
assertThat(profile.getName()).isEqualTo("SonarQube");
assertThat(profile.getActiveRules()).isEmpty();
try {
profile.getId();
fail();
} catch (IllegalStateException e) {
// id must not be used at all
}
}
use of org.sonar.api.profiles.RulesProfile in project sonarqube by SonarSource.
the class RulesProfileProviderTest method support_rule_templates.
@Test
public void support_rule_templates() {
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
ActiveRulesBuilder activeRulesBuilder = new ActiveRulesBuilder();
activeRulesBuilder.create(RuleKey.of("java", "S001")).setTemplateRuleKey("T001").setLanguage("java").activate();
RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings);
assertThat(profile.getActiveRule("java", "S001").getRule().getTemplate().getKey()).isEqualTo("T001");
}
Aggregations