diff options
author | Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> | 2023-10-27 11:26:31 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-11-08 20:02:52 +0000 |
commit | dc731234d9d4dbd24b456b2cdf3dc0386bd29741 (patch) | |
tree | 0f935d3d3c62939604820f39a0cd89cb789afe9b | |
parent | 765dbc083f9e05bafca0c190af018ca1c4dfc8b4 (diff) | |
download | sonarqube-dc731234d9d4dbd24b456b2cdf3dc0386bd29741.tar.gz sonarqube-dc731234d9d4dbd24b456b2cdf3dc0386bd29741.zip |
SONAR-20864 Reset grace period when setting new license.
4 files changed, 28 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java index d9ba1f91ad8..2ce66cddc95 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java @@ -74,4 +74,10 @@ public interface InternalProperties { * @throws IllegalArgumentException if {@code propertyKey} is {@code null} or empty */ void write(String propertyKey, @Nullable String value); + + /** + * Delete the specified property. + * + */ + void delete(String propertyKey); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalPropertiesImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalPropertiesImpl.java index ec7cae9b116..a5304e2b7ca 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalPropertiesImpl.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/property/InternalPropertiesImpl.java @@ -59,6 +59,15 @@ public class InternalPropertiesImpl implements InternalProperties { } } + @Override + public void delete(String propertyKey) { + checkPropertyKey(propertyKey); + try (DbSession dbSession = dbClient.openSession(false)) { + dbClient.internalPropertiesDao().delete(dbSession, propertyKey); + dbSession.commit(); + } + } + private static void checkPropertyKey(@Nullable String propertyKey) { checkArgument(propertyKey != null && !propertyKey.isEmpty(), "property key can't be null nor empty"); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/property/MapInternalProperties.java b/server/sonar-server-common/src/main/java/org/sonar/server/property/MapInternalProperties.java index 353984515d3..5545a9aa98f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/property/MapInternalProperties.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/property/MapInternalProperties.java @@ -44,6 +44,12 @@ public class MapInternalProperties implements InternalProperties { values.put(propertyKey, value); } + @Override + public void delete(String propertyKey) { + checkPropertyKey(propertyKey); + values.remove(propertyKey); + } + private static void checkPropertyKey(@Nullable String propertyKey) { checkArgument(propertyKey != null && !propertyKey.isEmpty(), "property key can't be null nor empty"); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java index da714b78461..5d4715a1098 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java @@ -103,6 +103,13 @@ public class InternalPropertiesImplTest { verify(dbSession).commit(); } + @Test + public void delete_shouldCallDaoAndDeleteProperty() { + underTest.delete(SOME_KEY); + verify(internalPropertiesDao).delete(dbSession, SOME_KEY); + verify(dbSession).commit(); + } + private void expectKeyNullOrEmptyIAE(ThrowingCallable callback) { assertThatThrownBy(callback) .isInstanceOf(IllegalArgumentException.class) |