use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class RegisterQualityProfiles method start.
@Override
public void start() {
List<BuiltInQProfile> builtInQProfiles = builtInQProfileRepository.get();
if (builtInQProfiles.isEmpty()) {
return;
}
Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register quality profiles");
try (DbSession dbSession = dbClient.openSession(false);
DbSession batchDbSession = dbClient.openSession(true)) {
long startDate = system2.now();
Map<QProfileName, RulesProfileDto> persistedRuleProfiles = loadPersistedProfiles(dbSession);
Multimap<QProfileName, ActiveRuleChange> changedProfiles = ArrayListMultimap.create();
builtInQProfiles.forEach(builtIn -> {
RulesProfileDto ruleProfile = persistedRuleProfiles.get(builtIn.getQProfileName());
if (ruleProfile == null) {
create(dbSession, batchDbSession, builtIn);
} else {
List<ActiveRuleChange> changes = update(dbSession, builtIn, ruleProfile);
changedProfiles.putAll(builtIn.getQProfileName(), changes.stream().filter(change -> {
String inheritance = change.getActiveRule().getInheritance();
return inheritance == null || NONE.name().equals(inheritance);
}).collect(MoreCollectors.toList()));
}
});
if (!changedProfiles.isEmpty()) {
long endDate = system2.now();
builtInQualityProfilesNotification.onChange(changedProfiles, startDate, endDate);
}
ensureBuiltInDefaultQPContainsRules(dbSession);
}
profiler.stopDebug();
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class QProfileCopier method prepareTarget.
private QProfileDto prepareTarget(DbSession dbSession, QProfileDto sourceProfile, String toName) {
verify(sourceProfile.getName(), toName);
QProfileName toProfileName = new QProfileName(sourceProfile.getLanguage(), toName);
QProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, toProfileName.getName(), toProfileName.getLanguage());
if (toProfile == null) {
toProfile = factory.createCustom(dbSession, toProfileName, sourceProfile.getParentKee());
dbSession.commit();
}
return toProfile;
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class QProfileFactoryImplTest method checkAndCreateCustom_throws_BadRequestException_if_name_null.
@Test
public void checkAndCreateCustom_throws_BadRequestException_if_name_null() {
QProfileName name = new QProfileName("xoo", null);
expectBadRequestException(() -> underTest.checkAndCreateCustom(dbSession, name), "quality_profiles.profile_name_cant_be_blank");
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method send_a_single_notification_when_multiple_rules_are_activated.
@Test
public void send_a_single_notification_when_multiple_rules_are_activated() {
String language = newLanguageKey();
RuleDefinitionDto existingRule1 = db.rules().insert(r -> r.setLanguage(language));
RuleDefinitionDto newRule1 = db.rules().insert(r -> r.setLanguage(language));
RulesProfileDto dbProfile1 = insertBuiltInProfile(language);
activateRuleInDb(dbProfile1, existingRule1, MAJOR);
addPluginProfile(dbProfile1, existingRule1, newRule1);
RuleDefinitionDto existingRule2 = db.rules().insert(r -> r.setLanguage(language));
RuleDefinitionDto newRule2 = db.rules().insert(r -> r.setLanguage(language));
RulesProfileDto dbProfile2 = insertBuiltInProfile(language);
activateRuleInDb(dbProfile2, existingRule2, MAJOR);
addPluginProfile(dbProfile2, existingRule2, newRule2);
builtInQProfileRepositoryRule.initialize();
underTest.start();
ArgumentCaptor<Multimap> captor = ArgumentCaptor.forClass(Multimap.class);
verify(builtInQualityProfilesNotification).onChange(captor.capture(), anyLong(), anyLong());
Multimap<QProfileName, ActiveRuleChange> updatedProfiles = captor.getValue();
assertThat(updatedProfiles.keySet()).extracting(QProfileName::getName, QProfileName::getLanguage).containsExactlyInAnyOrder(tuple(dbProfile1.getName(), dbProfile1.getLanguage()), tuple(dbProfile2.getName(), dbProfile2.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(newRule1.getUuid(), ACTIVATED), tuple(newRule2.getUuid(), ACTIVATED));
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method notification_does_not_include_inherited_profiled_when_rule_is_changed.
@Test
public void notification_does_not_include_inherited_profiled_when_rule_is_changed() {
String language = newLanguageKey();
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR));
QProfileDto builtInProfile = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language));
db.qualityProfiles().activateRule(builtInProfile, rule, ar -> ar.setSeverity(Severity.MINOR));
QProfileDto childProfile = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInProfile.getKee()));
db.qualityProfiles().activateRule(childProfile, rule, ar -> ar.setInheritance(ActiveRuleDto.INHERITED).setSeverity(Severity.MINOR));
addPluginProfile(builtInProfile, rule);
builtInQProfileRepositoryRule.initialize();
db.commit();
underTest.start();
ArgumentCaptor<Multimap> captor = ArgumentCaptor.forClass(Multimap.class);
verify(builtInQualityProfilesNotification).onChange(captor.capture(), anyLong(), anyLong());
Multimap<QProfileName, ActiveRuleChange> updatedProfiles = captor.getValue();
assertThat(updatedProfiles.keySet()).extracting(QProfileName::getName, QProfileName::getLanguage).containsExactlyInAnyOrder(tuple(builtInProfile.getName(), builtInProfile.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(rule.getUuid(), UPDATED));
}
Aggregations