use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method addPluginProfile.
private void addPluginProfile(RulesProfileDto dbProfile, RuleDefinitionDto... dbRules) {
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(dbProfile.getName(), dbProfile.getLanguage());
Arrays.stream(dbRules).forEach(dbRule -> newQp.activateRule(dbRule.getRepositoryKey(), dbRule.getRuleKey()).overrideSeverity(Severity.MAJOR));
newQp.done();
List<BuiltInActiveRule> rules = context.profile(dbProfile.getLanguage(), dbProfile.getName()).rules();
BuiltInQProfile.ActiveRule[] activeRules = toActiveRules(rules, dbRules);
builtInQProfileRepositoryRule.add(newLanguage(dbProfile.getLanguage()), dbProfile.getName(), false, activeRules);
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method addPluginProfile.
private void addPluginProfile(QProfileDto profile, RuleDefinitionDto... dbRules) {
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage());
Arrays.stream(dbRules).forEach(dbRule -> newQp.activateRule(dbRule.getRepositoryKey(), dbRule.getRuleKey()).overrideSeverity(Severity.MAJOR));
newQp.done();
BuiltInQProfile.ActiveRule[] activeRules = toActiveRules(context.profile(profile.getLanguage(), profile.getName()).rules(), dbRules);
builtInQProfileRepositoryRule.add(newLanguage(profile.getLanguage()), profile.getName(), false, activeRules);
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQProfileUpdateImplTest method do_not_load_descendants_if_no_changes.
@Test
public void do_not_load_descendants_if_no_changes() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo"));
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true));
QProfileDto childProfile = createChildProfile(profile);
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage());
newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey());
newQp.done();
// first run
BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile(profile.getLanguage(), profile.getName()), rule);
List<ActiveRuleChange> changes = underTest.update(db.getSession(), builtIn, RulesProfileDto.from(profile));
assertThat(changes).hasSize(2).extracting(ActiveRuleChange::getType).containsOnly(ActiveRuleChange.Type.ACTIVATED);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(persistedProfile.getLanguage()));
// second run, without any input changes
RuleActivator ruleActivatorWithoutDescendants = new RuleActivator(system2, db.getDbClient(), typeValidations, userSession) {
@Override
DescendantProfilesSupplier createDescendantProfilesSupplier(DbSession dbSession) {
return (profiles, ruleIds) -> {
throw new IllegalStateException("BOOM - descendants should not be loaded");
};
}
};
changes = new BuiltInQProfileUpdateImpl(db.getDbClient(), ruleActivatorWithoutDescendants, activeRuleIndexer, qualityProfileChangeEventService).update(db.getSession(), builtIn, RulesProfileDto.from(profile));
assertThat(changes).isEmpty();
verifyNoMoreInteractions(qualityProfileChangeEventService);
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQProfileUpdateImplTest method activate_rule_on_built_in_profile_resets_severity_to_default_if_not_overridden.
// SONAR-10473
@Test
public void activate_rule_on_built_in_profile_resets_severity_to_default_if_not_overridden() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setSeverity(Severity.MAJOR).setLanguage("xoo"));
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo");
newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey());
newQp.done();
BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile("xoo", "Sonar way"), rule);
underTest.update(db.getSession(), builtIn, persistedProfile);
List<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
assertThatRuleIsNewlyActivated(activeRules, rule, MAJOR);
// emulate an upgrade of analyzer that changes the default severity of the rule
rule.setSeverity(Severity.MINOR);
db.rules().update(rule);
List<ActiveRuleChange> changes = underTest.update(db.getSession(), builtIn, persistedProfile);
activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
assertThatRuleIsNewlyActivated(activeRules, rule, MINOR);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(persistedProfile.getLanguage()));
}
use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.
the class BuiltInQProfileUpdateImplTest method activate_deactivate_and_update_three_rules_at_the_same_time.
@Test
public void activate_deactivate_and_update_three_rules_at_the_same_time() {
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo"));
RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo"));
RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("xoo"));
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo");
newQp.activateRule(rule1.getRepositoryKey(), rule1.getRuleKey()).overrideSeverity(Severity.CRITICAL);
newQp.activateRule(rule2.getRepositoryKey(), rule2.getRuleKey()).overrideSeverity(Severity.MAJOR);
newQp.done();
BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile("xoo", "Sonar way"), rule1, rule2);
// rule1 must be updated (blocker to critical)
// rule2 must be activated
// rule3 must be deactivated
activateRuleInDb(persistedProfile, rule1, BLOCKER);
activateRuleInDb(persistedProfile, rule3, BLOCKER);
List<ActiveRuleChange> changes = underTest.update(db.getSession(), builtIn, persistedProfile);
List<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
assertThat(activeRules).hasSize(2);
assertThatRuleIsUpdated(activeRules, rule1, CRITICAL);
assertThatRuleIsNewlyActivated(activeRules, rule2, MAJOR);
assertThatRuleIsDeactivated(activeRules, rule3);
assertThatProfileIsMarkedAsUpdated(persistedProfile);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(persistedProfile.getLanguage()));
}
Aggregations