From: lukasz-jarocki-sonarsource Date: Fri, 8 Dec 2023 06:32:13 +0000 (+0100) Subject: SONAR-21179 Deprecate preventReactivation param X-Git-Tag: 10.4.0.87286~327 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f858d78968e5a82dbfcd494838cf46d4577a2211;p=sonarqube.git SONAR-21179 Deprecate preventReactivation param --- diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/RuleCreator.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/RuleCreator.java index 9fabf677093..853cfd0c984 100644 --- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/RuleCreator.java +++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/RuleCreator.java @@ -91,7 +91,7 @@ public class RuleCreator { validateCustomRule(newRule, dbSession, templateKey); Optional definition = loadRule(dbSession, newRule.ruleKey()); - RuleDto ruleDto = definition.map(d -> updateExistingRule(d, newRule, dbSession)) + RuleDto ruleDto = definition.map(dto -> updateExistingRule(dto, newRule, dbSession)) .orElseGet(() -> createCustomRule(newRule, templateRule, dbSession)); ruleIndexer.commitAndIndex(dbSession, ruleDto.getUuid()); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/RuleUpdaterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/RuleUpdaterIT.java index 46de88eb530..9c6f69672ed 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/RuleUpdaterIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/RuleUpdaterIT.java @@ -59,6 +59,7 @@ import org.sonar.server.rule.index.RuleQuery; import org.sonar.server.tester.UserSessionRule; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; import static org.sonar.api.rule.Severity.CRITICAL; @@ -91,18 +92,19 @@ public class RuleUpdaterIT { private final RuleUpdater underTest = new RuleUpdater(db.getDbClient(), ruleIndexer, uuidFactory, system2); @Test - public void do_not_update_rule_with_removed_status() { + public void do_update_rule_with_removed_status() { db.rules().insert(newRule(RULE_KEY).setStatus(RuleStatus.REMOVED)); dbSession.commit(); - RuleUpdate update = createForPluginRule(RULE_KEY) - .setTags(Sets.newHashSet("java9")); + RuleUpdate update = createForCustomRule(RULE_KEY) + .setTags(Sets.newHashSet("java9")) + .setStatus(RuleStatus.READY); - assertThatThrownBy(() -> { - underTest.update(dbSession, update, userSessionRule); - }) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Rule with REMOVED status cannot be updated: java:S001"); + assertThatNoException().isThrownBy(() -> underTest.update(dbSession, update, userSessionRule)); + RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY); + + assertThat(rule.getTags()).containsOnly("java9"); + assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY); } @Test diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java index 1d0d4a14464..381363c4518 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java @@ -95,11 +95,7 @@ public class RuleUpdater { */ private RuleDto getRuleDto(RuleUpdate change) { try (DbSession dbSession = dbClient.openSession(false)) { - RuleDto rule = dbClient.ruleDao().selectOrFailByKey(dbSession, change.getRuleKey()); - if (RuleStatus.REMOVED == rule.getStatus()) { - throw new IllegalArgumentException("Rule with REMOVED status cannot be updated: " + change.getRuleKey()); - } - return rule; + return dbClient.ruleDao().selectOrFailByKey(dbSession, change.getRuleKey()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java index 121b32594ee..b83a7b36fb3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java @@ -65,10 +65,15 @@ public class CreateAction implements RulesWsAction { private static final String PARAM_CLEAN_CODE_ATTRIBUTE = "cleanCodeAttribute"; public static final String PARAMS = "params"; - public static final String PARAM_PREVENT_REACTIVATION = "preventReactivation"; static final int KEY_MAXIMUM_LENGTH = 200; static final int NAME_MAXIMUM_LENGTH = 200; + /** + * @deprecated since 10.4 + */ + @Deprecated(since = "10.4") + private static final String PARAM_PREVENT_REACTIVATION = "preventReactivation"; + private final DbClient dbClient; private final RuleService ruleService; private final RuleMapper ruleMapper; @@ -96,7 +101,8 @@ public class CreateAction implements RulesWsAction { new Change("10.2", "Add 'impacts', 'cleanCodeAttribute', 'cleanCodeAttributeCategory' fields to the response"), new Change("10.2", "Fields 'type' and 'severity' are deprecated in the response. Use 'impacts' instead."), new Change("10.4", String.format("Add '%s' and '%s' parameters to the request", PARAM_IMPACTS, PARAM_CLEAN_CODE_ATTRIBUTE)), - new Change("10.4", String.format("Parameters '%s' and '%s' are deprecated. Use '%s' instead.", PARAM_TYPE, PARAM_SEVERITY, PARAM_IMPACTS))) + new Change("10.4", String.format("Parameters '%s' and '%s' are deprecated. Use '%s' instead.", PARAM_TYPE, PARAM_SEVERITY, PARAM_IMPACTS)), + new Change("10.4", String.format("Parameter '%s' is deprecated. Use api/rules/update endpoint instead.", PARAM_PREVENT_REACTIVATION))) .setHandler(this); action @@ -146,6 +152,7 @@ public class CreateAction implements RulesWsAction { action .createParam(PARAM_PREVENT_REACTIVATION) + .setDeprecatedSince("10.4") .setBooleanPossibleValues() .setDefaultValue(false) .setDescription("If set to true and if the rule has been deactivated (status 'REMOVED'), a status 409 will be returned"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java index 608d726fd07..8af573cf247 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java @@ -91,7 +91,8 @@ public class UpdateAction implements RulesWsAction { .setDescription("Update an existing rule.
" + "Requires the 'Administer Quality Profiles' permission") .setChangelog( - new Change("10.2", "The field 'severity' and 'type' in the response have been deprecated, use 'impacts' instead.") + new Change("10.2", "The field 'severity' and 'type' in the response have been deprecated, use 'impacts' instead."), + new Change("10.4", "Updating a removed rule is now possible.") ) .setSince("4.4") .setChangelog(