]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10313 remove useless RuleActivationContext#rulesByKey
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 5 Feb 2018 14:33:22 +0000 (15:33 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 8 Feb 2018 12:41:00 +0000 (13:41 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java

index b4c30a654aff35bdc437951bd1ec0347cbad2b22..170a6456e5e5bc9ba3ec804759277c017fe6fb71 100644 (file)
@@ -113,7 +113,7 @@ public class QProfileTreeImpl implements QProfileTree {
         changes.addAll(ruleActivator.deactivate(dbSession, context, activeRule.getRuleId(), true));
 
       } else if (ActiveRuleDto.OVERRIDES.equals(activeRule.getInheritance())) {
-        context.reset(activeRule.getRuleKey());
+        context.reset(activeRule.getRuleId());
         activeRule.setInheritance(null);
         activeRule.setUpdatedAt(system2.now());
         db.activeRuleDao().update(dbSession, activeRule);
index 0d5b78a76dbaf815344b4fdd4f21cecc4e73bc6c..86d19dc9cc0619d1f453ed018fc9d8982f49cc0d 100644 (file)
@@ -65,7 +65,6 @@ class RuleActivationContext {
   private final List<QProfileDto> builtInAliases = new ArrayList<>();
 
   // the rules
-  private final Map<RuleKey, RuleWrapper> rulesByKey;
   private final Map<Integer, RuleWrapper> rulesById;
   private final Map<ActiveRuleKey, ActiveRuleWrapper> activeRulesByKey;
 
@@ -85,12 +84,10 @@ class RuleActivationContext {
     this.date = builder.date;
 
     // rules
-    this.rulesByKey = Maps.newHashMapWithExpectedSize(builder.rules.size());
     this.rulesById = Maps.newHashMapWithExpectedSize(builder.rules.size());
     ListMultimap<Integer, RuleParamDto> paramsByRuleId = builder.ruleParams.stream().collect(index(RuleParamDto::getRuleId));
     for (RuleDefinitionDto rule : builder.rules) {
       RuleWrapper wrapper = new RuleWrapper(rule, paramsByRuleId.get(rule.getId()));
-      rulesByKey.put(rule.getKey(), wrapper);
       rulesById.put(rule.getId(), wrapper);
     }
 
@@ -169,19 +166,9 @@ class RuleActivationContext {
       .collect(Collectors.toList());
   }
 
-  /**
-   * Resets cursor to base profile and selects the rule with specified key.
-   */
-  void reset(RuleKey ruleKey) {
-    this.cascading = false;
-    doSwitch(this.baseProfile, this.baseRulesProfile, ruleKey);
-  }
-
-  public void reset(Integer ruleId) {
+  public void reset(int ruleId) {
     this.cascading = false;
-    RuleWrapper ruleWrapper = rulesById.get(ruleId);
-    checkRequest(ruleWrapper != null, "Rule not found: %s", ruleId);
-    doSwitch(this.baseProfile, this.baseRulesProfile, ruleWrapper.get().getKey());
+    doSwitch(this.baseProfile, this.baseRulesProfile, ruleId);
   }
 
   /**
@@ -190,20 +177,21 @@ class RuleActivationContext {
   void switchToChild(QProfileDto to) {
     checkState(!to.isBuiltIn());
     requireNonNull(this.currentRule, "can not switch profile if rule is not set");
-    RuleKey ruleKey = this.currentRule.get().getKey();
+    RuleDefinitionDto rule = this.currentRule.get();
 
     QProfileDto qp = requireNonNull(this.profilesByUuid.get(to.getKee()), () -> "No profile with uuid " + to.getKee());
     RulesProfileDto rulesProfile = RulesProfileDto.from(qp);
 
     this.cascading = true;
-    doSwitch(qp, rulesProfile, ruleKey);
+    doSwitch(qp, rulesProfile, rule.getId());
   }
 
-  private void doSwitch(@Nullable QProfileDto qp, RulesProfileDto rulesProfile, RuleKey ruleKey) {
-    this.currentRule = rulesByKey.get(ruleKey);
-    checkRequest(this.currentRule != null, "Rule not found: %s", ruleKey);
+  private void doSwitch(@Nullable QProfileDto qp, RulesProfileDto rulesProfile, int ruleId) {
+    this.currentRule = rulesById.get(ruleId);
+    checkRequest(this.currentRule != null, "Rule not found: %s", ruleId);
+    RuleKey ruleKey = currentRule.get().getKey();
     checkRequest(rulesProfile.getLanguage().equals(currentRule.get().getLanguage()),
-      "%s rule %s cannot be activated on %s profile %s", currentRule.get().getLanguage(), currentRule.get().getKey(), rulesProfile.getLanguage(), rulesProfile.getName());
+      "%s rule %s cannot be activated on %s profile %s", currentRule.get().getLanguage(), ruleKey, rulesProfile.getLanguage(), rulesProfile.getName());
     this.currentRulesProfile = rulesProfile;
     this.currentProfile = qp;
     this.currentActiveRule = this.activeRulesByKey.get(ActiveRuleKey.of(rulesProfile, ruleKey));