From: Julien Lancelot Date: Thu, 22 Jun 2017 12:48:27 +0000 (+0200) Subject: SONAR-9442 Exclude inherrited profiles changes in notification X-Git-Tag: 6.5-M2~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c33610d582f8aae9bb456c4afcef31f1be610018;p=sonarqube.git SONAR-9442 Exclude inherrited profiles changes in notification --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java index 50490dc11b6..0f15106cacd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java @@ -34,6 +34,7 @@ import org.sonar.db.DbSession; import org.sonar.db.qualityprofile.RulesProfileDto; import static java.lang.String.format; +import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.NONE; /** * Synchronize Quality profiles during server startup @@ -78,7 +79,9 @@ public class RegisterQualityProfiles { register(dbSession, batchDbSession, builtIn); } else { List changes = update(dbSession, builtIn, ruleProfile); - changedProfiles.putAll(builtIn.getQProfileName(), changes); + changedProfiles.putAll(builtIn.getQProfileName(), changes.stream() + .filter(change -> change.getInheritance() == null || NONE.equals(change.getInheritance())) + .collect(MoreCollectors.toList())); } }); if (!changedProfiles.isEmpty()) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java index e11f76806f9..2bbfb98a9e2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java @@ -34,7 +34,9 @@ import org.sonar.api.utils.log.LogTester; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbTester; +import org.sonar.db.organization.OrganizationDto; import org.sonar.db.qualityprofile.ActiveRuleDto; +import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.qualityprofile.RulesProfileDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; @@ -187,6 +189,35 @@ public class RegisterQualityProfilesNotificationTest { ); } + @Test + public void do_not_include_inherited_quality_profile_changes() { + String language = newLanguageKey(); + + OrganizationDto organization = db.organizations().insert(); + QProfileDto builtInQProfileDto = db.qualityProfiles().insert(organization, orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language)); + QProfileDto customQProfileDto = db.qualityProfiles().insert(organization, orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInQProfileDto.getKee())); + db.commit(); + RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(language)); + + RulesProfile pluginProfile = RulesProfile.create(builtInQProfileDto.getName(), builtInQProfileDto.getLanguage()); + pluginProfile.activateRule(create(newRule.getRepositoryKey(), newRule.getRuleKey()), MAJOR); + builtInQProfileRepositoryRule.add(newLanguage(builtInQProfileDto.getLanguage()), builtInQProfileDto.getName(), false, pluginProfile.getActiveRules().toArray(new ActiveRule[0])); + builtInQProfileRepositoryRule.initialize(); + + underTest.start(); + + ArgumentCaptor captor = ArgumentCaptor.forClass(Multimap.class); + verify(builtInQualityProfilesNotification).send(captor.capture()); + Multimap updatedProfiles = captor.>getValue(); + assertThat(updatedProfiles.keySet()) + .extracting(QProfileName::getName, QProfileName::getLanguage) + .containsExactlyInAnyOrder(tuple(builtInQProfileDto.getName(), builtInQProfileDto.getLanguage())); + assertThat(updatedProfiles.values()) + .extracting(value -> value.getActiveRule().getRuleId(), ActiveRuleChange::getType) + .containsExactlyInAnyOrder(tuple(newRule.getId(), ACTIVATED)); + } + + private void addPluginProfile(RulesProfileDto dbProfile, RuleDefinitionDto... dbRules) { RulesProfile pluginProfile = RulesProfile.create(dbProfile.getName(), dbProfile.getLanguage()); Arrays.stream(dbRules).forEach(dbRule -> pluginProfile.activateRule(create(dbRule.getRepositoryKey(), dbRule.getRuleKey()), MAJOR));