diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2022-10-07 14:38:14 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-10 20:03:09 +0000 |
commit | 00dda5a5d8089e9ff7f8c4d011a16f425cd6bf7b (patch) | |
tree | 7a4e680e6e38aa56e316281dc1ef7b94b4bafbed /server | |
parent | d17f1fa0ac2b38f1e94f2e7e5d72f9a747062c8b (diff) | |
download | sonarqube-00dda5a5d8089e9ff7f8c4d011a16f425cd6bf7b.tar.gz sonarqube-00dda5a5d8089e9ff7f8c4d011a16f425cd6bf7b.zip |
SONAR-17440 Unset built-in flag and rename Quality Profile in case plugin which introduced it has been removed
Diffstat (limited to 'server')
5 files changed, 31 insertions, 33 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java index f6133648150..7d2d4c1838b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java @@ -81,10 +81,6 @@ public class QualityProfileDao implements Dao { return mapper(dbSession).selectBuiltInRuleProfilesWithActiveRules(); } - public List<QProfileDto> selectBuiltInRuleProfilesWithoutActiveRules(DbSession dbSession) { - return mapper(dbSession).selectBuiltInProfilesWithoutActiveRules(); - } - @CheckForNull public RulesProfileDto selectRuleProfile(DbSession dbSession, String ruleProfileUuid) { return mapper(dbSession).selectRuleProfile(ruleProfileUuid); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java index 1c2fb6417d3..27fc6f28def 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java @@ -44,8 +44,6 @@ public interface QualityProfileMapper { List<RulesProfileDto> selectBuiltInRuleProfilesWithActiveRules(); - List<QProfileDto> selectBuiltInProfilesWithoutActiveRules(); - @CheckForNull RulesProfileDto selectRuleProfile(@Param("uuid") String ruleProfileUuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index 8f4ae191e5e..fdcd8dc0b56 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -147,7 +147,8 @@ INNER JOIN default_qprofiles dp ON dp.qprofile_uuid = oqp.uuid WHERE rp.is_built_in = ${_true} - AND rp.language IN <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach> + AND rp.language IN <foreach collection="languages" open="(" close=")" item="language" + separator=",">#{language, jdbcType=VARCHAR}</foreach> AND NOT EXISTS ( SELECT 1 FROM active_rules ar INNER JOIN rules r ON r.uuid = ar.rule_uuid AND r.status <> 'REMOVED' @@ -155,21 +156,6 @@ ) </select> - <select id="selectBuiltInProfilesWithoutActiveRules" parameterType="map" - resultType="org.sonar.db.qualityprofile.QProfileDto"> - SELECT - <include refid="qProfileColumns"/> - FROM org_qprofiles oqp - INNER JOIN rules_profiles rp ON oqp.rules_profile_uuid = rp.uuid - WHERE - rp.is_built_in = ${_true} - AND NOT EXISTS ( - SELECT 1 FROM active_rules ar - INNER JOIN rules r ON r.uuid = ar.rule_uuid AND r.status <> 'REMOVED' - WHERE profile_uuid = rp.uuid - ) - </select> - <select id="selectDefaultProfiles" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto"> select <include refid="qProfileColumns"/> @@ -177,7 +163,8 @@ inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid where - dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach> + dp.language in <foreach collection="languages" open="(" close=")" item="language" + separator=",">#{language, jdbcType=VARCHAR}</foreach> and rp.language = dp.language </select> @@ -218,7 +205,8 @@ inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid where rp.name = #{name, jdbcType=VARCHAR} - and rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach> + and rp.language in <foreach collection="languages" open="(" close=")" item="language" + separator=",">#{language, jdbcType=VARCHAR}</foreach> </select> <select id="selectByUuid" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto"> @@ -290,7 +278,8 @@ inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid where - rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach> + rp.language in <foreach collection="languages" open="(" close=")" item="language" + separator=",">#{language, jdbcType=VARCHAR}</foreach> and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR} </select> diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java index f8b9ea4f442..e4a1ba8e2ba 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java @@ -211,12 +211,12 @@ public class RegisterQualityProfiles implements Startable { var languages = pluginsBuiltInQProfiles.stream().map(QProfileName::getLanguage).collect(Collectors.toSet()); - dbClient.qualityProfileDao().selectBuiltInRuleProfilesWithoutActiveRules(dbSession) + dbClient.qualityProfileDao().selectBuiltInRuleProfiles(dbSession) .forEach(qProfileDto -> { var dbProfileName = QProfileName.createFor(qProfileDto.getLanguage(), qProfileDto.getName()); // Built-in Quality Profile can be a leftover from plugin which has been removed - // Rename Quality Profile and unset built-in flag allowing empty Quality Profile for existing languages to be removed + // Rename Quality Profile and unset built-in flag allowing Quality Profile for existing languages to be removed // Quality Profiles for languages not existing anymore are marked as 'REMOVED' and won't be seen in UI if (!pluginsBuiltInQProfiles.contains(dbProfileName) && languages.contains(qProfileDto.getLanguage())) { String oldName = qProfileDto.getName(); @@ -237,9 +237,9 @@ public class RegisterQualityProfiles implements Startable { /** * Abbreviate Quality Profile name if it will be too long with prefix and append suffix */ - private String generateNewProfileName(QProfileDto qProfileDto) { + private String generateNewProfileName(RulesProfileDto qProfileDto) { var shortName = StringUtils.abbreviate(qProfileDto.getName(), 40); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssZ") + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd yyyy 'at' hh:mm:ss a") .withLocale(Locale.getDefault()) .withZone(ZoneId.systemDefault()); var now = formatter.format(Instant.ofEpochMilli(system2.now())); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java index 6236b55e6e0..57401460905 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java @@ -183,7 +183,8 @@ public class RegisterQualityProfilesTest { RulesProfileDto ruleProfileWithoutRule = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Foo way").setLanguage(FOO_LANGUAGE.getKey())); RulesProfileDto ruleProfileLongNameWithoutRule = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("That's a very very very very very very " + "very very very very long name").setLanguage(FOO_LANGUAGE.getKey())); - RulesProfileDto ruleProfileWithOneRule = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Foo way 2").setLanguage(FOO_LANGUAGE.getKey())); + RulesProfileDto ruleProfileWithOneRuleToBeRenamed = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Foo way 2").setLanguage(FOO_LANGUAGE.getKey())); + RulesProfileDto ruleProfileWithOneRule = newRuleProfileDto(rp -> rp.setIsBuiltIn(true).setName("Foo way 3").setLanguage(FOO_LANGUAGE.getKey())); QProfileDto qProfileWithoutRule = newQualityProfileDto() .setIsBuiltIn(true) @@ -203,9 +204,16 @@ public class RegisterQualityProfilesTest { .setLanguage(FOO_LANGUAGE.getKey()) .setRulesProfileUuid(ruleProfileWithOneRule.getUuid()); - db.qualityProfiles().insert(qProfileWithoutRule, qProfileWithOneRule, qProfileLongNameWithoutRule); + QProfileDto qProfileWithOneRuleToBeRenamed = newQualityProfileDto() + .setIsBuiltIn(true) + .setName(ruleProfileWithOneRuleToBeRenamed.getName()) + .setLanguage(FOO_LANGUAGE.getKey()) + .setRulesProfileUuid(ruleProfileWithOneRuleToBeRenamed.getUuid()); + + db.qualityProfiles().insert(qProfileWithoutRule, qProfileWithOneRule, qProfileLongNameWithoutRule, qProfileWithOneRuleToBeRenamed); RuleDto ruleDto = db.rules().insert(); db.qualityProfiles().activateRule(qProfileWithOneRule, ruleDto); + db.qualityProfiles().activateRule(qProfileWithOneRuleToBeRenamed, ruleDto); db.commit(); // adding only one profile as the other does not exist in plugins @@ -214,7 +222,7 @@ public class RegisterQualityProfilesTest { underTest.start(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssZ") + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd yyyy 'at' hh:mm:ss a") .withLocale(Locale.getDefault()) .withZone(ZoneId.systemDefault()); @@ -226,7 +234,10 @@ public class RegisterQualityProfilesTest { qProfileWithoutRule.getName(), qProfileWithoutRule.getLanguage(), qProfileWithoutRule.getName() + expectedSuffix), format("Quality profile [%s] for language [%s] is no longer built-in and has been renamed to [%s] " + "since it does not have any active rules.", - qProfileLongNameWithoutRule.getName(), qProfileLongNameWithoutRule.getLanguage(), "That's a very very very very very ver..." + expectedSuffix)); + qProfileLongNameWithoutRule.getName(), qProfileLongNameWithoutRule.getLanguage(), "That's a very very very very very ver..." + expectedSuffix), + format("Quality profile [%s] for language [%s] is no longer built-in and has been renamed to [%s] " + + "since it does not have any active rules.", + qProfileWithOneRuleToBeRenamed.getName(), qProfileWithOneRuleToBeRenamed.getLanguage(), qProfileWithOneRuleToBeRenamed.getName() + expectedSuffix)); assertThat(dbClient.qualityProfileDao().selectByUuid(db.getSession(), qProfileWithoutRule.getKee())) .extracting(QProfileDto::isBuiltIn, QProfileDto::getName) @@ -236,6 +247,10 @@ public class RegisterQualityProfilesTest { .extracting(QProfileDto::isBuiltIn, QProfileDto::getName) .containsExactly(false, "That's a very very very very very ver..." + expectedSuffix); + assertThat(dbClient.qualityProfileDao().selectByUuid(db.getSession(), qProfileWithOneRuleToBeRenamed.getKee())) + .extracting(QProfileDto::isBuiltIn, QProfileDto::getName) + .containsExactly(false, qProfileWithOneRuleToBeRenamed.getName() + expectedSuffix); + // the other profile did not change assertThat(dbClient.qualityProfileDao().selectByUuid(db.getSession(), qProfileWithOneRule.getKee())) .extracting(QProfileDto::isBuiltIn, QProfileDto::getName) |