From: Sébastien Lesaint Date: Mon, 5 Feb 2018 14:33:22 +0000 (+0100) Subject: SONAR-10313 remove useless RuleActivationContext#rulesByKey X-Git-Tag: 7.5~1688 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1496d3fa86bb64f34ba6d53c669a28b7b0280aba;p=sonarqube.git SONAR-10313 remove useless RuleActivationContext#rulesByKey --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java index b4c30a654af..170a6456e5e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileTreeImpl.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java index 0d5b78a76db..86d19dc9cc0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContext.java @@ -65,7 +65,6 @@ class RuleActivationContext { private final List builtInAliases = new ArrayList<>(); // the rules - private final Map rulesByKey; private final Map rulesById; private final Map 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 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));