use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarqube by SonarSource.
the class ActiveRulesProvider method load.
private static DefaultActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) {
Collection<String> qProfileKeys = getKeys(qProfiles);
Set<RuleKey> loadedRulesKey = new HashSet<>();
ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (String qProfileKey : qProfileKeys) {
Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey);
for (LoadedActiveRule r : qProfileRules) {
if (!loadedRulesKey.contains(r.getRuleKey())) {
loadedRulesKey.add(r.getRuleKey());
builder.addRule(transform(r, qProfileKey, r.getDeprecatedKeys()));
}
}
}
return builder.build();
}
use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarqube by SonarSource.
the class ActiveRulesProvider method transform.
private static ActiveRules transform(Collection<LoadedActiveRule> loadedRules) {
ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (LoadedActiveRule activeRule : loadedRules) {
NewActiveRule newActiveRule = builder.create(activeRule.getRuleKey());
newActiveRule.setName(activeRule.getName());
newActiveRule.setSeverity(activeRule.getSeverity());
newActiveRule.setCreatedAt(activeRule.getCreatedAt());
newActiveRule.setLanguage(activeRule.getLanguage());
newActiveRule.setInternalKey(activeRule.getInternalKey());
newActiveRule.setTemplateRuleKey(activeRule.getTemplateRuleKey());
// load parameters
if (activeRule.getParams() != null) {
for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) {
newActiveRule.setParam(params.getKey(), params.getValue());
}
}
newActiveRule.activate();
}
return builder.build();
}
use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder 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.batch.rule.internal.ActiveRulesBuilder 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.batch.rule.internal.ActiveRulesBuilder 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