]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9442 Exclude inherrited profiles changes in notification
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 Jun 2017 12:48:27 +0000 (14:48 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 29 Jun 2017 15:23:19 +0000 (17:23 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java

index 50490dc11b6c540b7769a24b25f04f2d60a18ea2..0f15106cacd02a2d0d0c918f1ab238d3531dbf9e 100644 (file)
@@ -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()) {
index e11f76806f90702d25d52a3ddf2253230e53b3c1..2bbfb98a9e2ece61aca418f4a15c1874fd429d6b 100644 (file)
@@ -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));