diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-06-22 14:48:27 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-06-29 17:23:19 +0200 |
commit | c33610d582f8aae9bb456c4afcef31f1be610018 (patch) | |
tree | b004611209de02f6e3a9337db6f086d7c4e9ef13 | |
parent | 4143e7a864bb46c0539dc416b571344129c7720e (diff) | |
download | sonarqube-c33610d582f8aae9bb456c4afcef31f1be610018.tar.gz sonarqube-c33610d582f8aae9bb456c4afcef31f1be610018.zip |
SONAR-9442 Exclude inherrited profiles changes in notification
2 files changed, 35 insertions, 1 deletions
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<ActiveRuleChange> 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<Multimap> captor = ArgumentCaptor.forClass(Multimap.class); + verify(builtInQualityProfilesNotification).send(captor.capture()); + Multimap<QProfileName, ActiveRuleChange> updatedProfiles = captor.<Multimap<QProfileName, ActiveRuleChange>>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)); |