aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorOrlovAlexander <35396155+OrlovAlexander85@users.noreply.github.com>2024-04-09 15:22:11 +0200
committersonartech <sonartech@sonarsource.com>2024-04-10 20:02:53 +0000
commit791659dd5e60709f28f9afa7983cee5375acb136 (patch)
tree23a8152c5ab1e21edb5c4cacfac1d5e99ec2e24f /server
parentf5dd75ab4b842eb2a5280411cfaceb0c09eea57d (diff)
downloadsonarqube-791659dd5e60709f28f9afa7983cee5375acb136.tar.gz
sonarqube-791659dd5e60709f28f9afa7983cee5375acb136.zip
SONAR-22018 introduce version EOL to properties, and update GlobalAction
Diffstat (limited to 'server')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java11
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json1
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java23
3 files changed, 32 insertions, 3 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
index 1f4f1007ee3..fb4959fff8b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
@@ -28,9 +28,11 @@ import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypes;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService.NewController;
+import org.sonar.api.utils.System2;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.page.Page;
import org.sonar.core.platform.PlatformEditionProvider;
@@ -47,6 +49,7 @@ import org.sonar.server.user.UserSession;
import static org.sonar.api.CoreProperties.DEVELOPER_AGGREGATED_INFO_DISABLED;
import static org.sonar.api.CoreProperties.RATING_GRID;
+import static org.sonar.api.internal.MetadataLoader.loadSqVersionEol;
import static org.sonar.core.config.WebConstants.SONAR_LF_ENABLE_GRAVATAR;
import static org.sonar.core.config.WebConstants.SONAR_LF_GRAVATAR_SERVER_URL;
import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_URL;
@@ -112,7 +115,8 @@ public class GlobalAction implements NavigationWsAction, Startable {
.setHandler(this)
.setInternal(true)
.setResponseExample(getClass().getResource("global-example.json"))
- .setSince("5.2");
+ .setSince("5.2")
+ .setChangelog(new Change("9.9.5", "Field 'versionEOL' added, to indicate the end of support of installed version."));
}
@Override
@@ -125,6 +129,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
writeDeprecatedLogoProperties(json);
writeQualifiers(json);
writeVersion(json);
+ writeVersionEol(json);
writeDatabaseProduction(json);
writeInstanceUsesDefaultAdminCredentials(json);
editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
@@ -175,6 +180,10 @@ public class GlobalAction implements NavigationWsAction, Startable {
json.prop("version", displayVersion);
}
+ private void writeVersionEol(JsonWriter json) {
+ json.prop("versionEOL", loadSqVersionEol(System2.INSTANCE));
+ }
+
private void writeDatabaseProduction(JsonWriter json) {
json.prop("productionDatabase", !dbClient.getDatabase().getDialect().getId().equals(H2.ID));
}
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json
index a1619ee69fd..ec6d8c052c5 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json
@@ -24,6 +24,7 @@
"POL"
],
"version": "6.2",
+ "versionEOL": "2025-01-01",
"productionDatabase": true,
"canAdmin": false,
"standalone": true,
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
index 19a79bf4ec5..c0f77e2a7ea 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
@@ -19,10 +19,13 @@
*/
package org.sonar.server.ui.ws;
+import java.util.Objects;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
+import org.mockito.MockedStatic;
+import org.sonar.api.internal.MetadataLoader;
import org.sonar.api.platform.Server;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypeTree;
@@ -50,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import static org.sonar.test.JsonAssert.assertJson;
@@ -185,6 +189,15 @@ public class GlobalActionTest {
}
@Test
+ public void execute_shouldReturnVersionEol() {
+ init();
+ try (MockedStatic<MetadataLoader> mocked = mockStatic(MetadataLoader.class)) {
+ mocked.when(() -> MetadataLoader.loadSqVersionEol(any())).thenReturn("2025-01-01");
+ assertThat(call()).contains("\"versionEOL\":\"2025-01-01\"");
+ }
+ }
+
+ @Test
public void functional_version_when_4_digits() {
init();
when(server.getVersion()).thenReturn("6.3.1.1234");
@@ -283,8 +296,14 @@ public class GlobalActionTest {
when(nodeInformation.isStandalone()).thenReturn(true);
when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
- String result = call();
- assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
+
+ try (MockedStatic<MetadataLoader> mocked = mockStatic(MetadataLoader.class)) {
+ mocked.when(() -> MetadataLoader.loadSqVersionEol(any())).thenReturn("2025-01-01");
+
+ String result = call();
+
+ assertJson(result).isSimilarTo(Objects.requireNonNull(ws.getDef().responseExampleAsString()));
+ }
}
@Test