use of org.sonar.server.qualityprofile.builtin.BuiltInQProfile 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.BuiltInQProfile in project sonarqube by SonarSource.
the class RegisterQualityProfilesTest method persist_built_in_profiles_that_are_not_persisted_yet.
@Test
public void persist_built_in_profiles_that_are_not_persisted_yet() {
BuiltInQProfile builtInQProfile = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, "Sonar way");
builtInQProfileRepositoryRule.initialize();
underTest.start();
assertThat(insert.callLogs).containsExactly(builtInQProfile);
assertThat(update.callLogs).isEmpty();
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Register profile foo/Sonar way");
}
use of org.sonar.server.qualityprofile.builtin.BuiltInQProfile in project sonarqube by SonarSource.
the class RegisterQualityProfilesTest method dont_persist_built_in_profiles_that_are_already_persisted.
@Test
public void dont_persist_built_in_profiles_that_are_already_persisted() {
String name = "doh";
BuiltInQProfile persistedBuiltIn = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, name, true);
BuiltInQProfile nonPersistedBuiltIn = builtInQProfileRepositoryRule.add(BAR_LANGUAGE, name, true);
builtInQProfileRepositoryRule.initialize();
insertRulesProfile(persistedBuiltIn);
underTest.start();
assertThat(insert.callLogs).containsExactly(nonPersistedBuiltIn);
assertThat(update.callLogs).containsExactly(persistedBuiltIn);
}
use of org.sonar.server.qualityprofile.builtin.BuiltInQProfile in project sonarqube by SonarSource.
the class RegisterQualityProfilesTest method update_built_in_profile_if_it_already_exists.
@Test
public void update_built_in_profile_if_it_already_exists() {
RulesProfileDto ruleProfile = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Sonar way").setLanguage(FOO_LANGUAGE.getKey()));
db.getDbClient().qualityProfileDao().insert(db.getSession(), ruleProfile);
db.commit();
BuiltInQProfile builtIn = builtInQProfileRepositoryRule.add(FOO_LANGUAGE, ruleProfile.getName(), false);
builtInQProfileRepositoryRule.initialize();
underTest.start();
assertThat(insert.callLogs).isEmpty();
assertThat(update.callLogs).containsExactly(builtIn);
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Update profile foo/Sonar way");
}
Aggregations