From 8ce408e17dd34e2401bd34394d5b21e8b790f836 Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Thu, 14 Oct 2021 11:49:43 +0200 Subject: [PATCH] SONAR-15511 Update api/system/upgrades to add latest LTS information --- .../java/org/sonar/server/platform/ws/UpgradesAction.java | 8 ++++++++ .../server/platform/ws/example-upgrades_plugins.json | 1 + .../org/sonar/server/platform/ws/UpgradesActionTest.java | 3 +++ 3 files changed, 12 insertions(+) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java index 303053e1961..6f937d847b2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java @@ -32,6 +32,7 @@ import org.sonar.updatecenter.common.Plugin; import org.sonar.updatecenter.common.Release; import org.sonar.updatecenter.common.SonarUpdate; import org.sonar.updatecenter.common.UpdateCenter; +import org.sonar.updatecenter.common.Version; import static org.apache.commons.lang.StringUtils.isNotBlank; import static org.sonar.server.plugins.edition.EditionBundledPlugins.isEditionBundled; @@ -44,6 +45,7 @@ public class UpgradesAction implements SystemWsAction { private static final boolean DO_NOT_FORCE_REFRESH = false; private static final String ARRAY_UPGRADES = "upgrades"; + private static final String PROPERTY_UPDATE_CENTER_LTS = "latestLTS"; private static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh"; private static final String PROPERTY_VERSION = "version"; private static final String PROPERTY_DESCRIPTION = "description"; @@ -111,6 +113,12 @@ public class UpgradesAction implements SystemWsAction { Optional updateCenter = updateCenterFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH); writeUpgrades(jsonWriter, updateCenter); if (updateCenter.isPresent()) { + Release ltsRelease = updateCenter.get().getSonar().getLtsRelease(); + if (ltsRelease != null) { + Version ltsVersion = ltsRelease.getVersion(); + String latestLTS = String.format("%s.%s", ltsVersion.getMajor(), ltsVersion.getMinor()); + jsonWriter.prop(PROPERTY_UPDATE_CENTER_LTS, latestLTS); + } jsonWriter.propDateTime(PROPERTY_UPDATE_CENTER_REFRESH, updateCenter.get().getDate()); } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json index 7364af7a584..ca6d5df8f4a 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json @@ -36,5 +36,6 @@ } } ], + "latestLTS": "8.9", "updateCenterRefresh": "2015-04-24T16:08:36+0200" } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java index 9630bd63d5c..79f1df9dc2a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java @@ -48,6 +48,7 @@ public class UpgradesActionTest { private UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class); private UpdateCenter updateCenter = mock(UpdateCenter.class); + private Sonar sonar = mock(Sonar.class); private UpgradesAction underTest = new UpgradesAction(updateCenterFactory); private WsActionTester tester = new WsActionTester(underTest); @@ -90,6 +91,7 @@ public class UpgradesActionTest { @Before public void wireMocks() { when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter)); + when(updateCenter.getSonar()).thenReturn(sonar); when(updateCenter.getDate()).thenReturn(DateUtils.parseDateTime("2015-04-24T16:08:36+0200")); } @@ -124,6 +126,7 @@ public class UpgradesActionTest { @Test public void verify_JSON_response_against_example() { SonarUpdate sonarUpdate = createSonar_51_update(); + when(sonar.getLtsRelease()).thenReturn(new Release(sonar, Version.create("8.9.2"))); when(updateCenter.findSonarUpdates()).thenReturn(of(sonarUpdate)); TestResponse response = tester.newRequest().execute(); -- 2.39.5