]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15511 Update api/system/upgrades to add latest LTS information
authorMathieu Suen <mathieu.suen@sonarsource.com>
Thu, 14 Oct 2021 09:49:43 +0000 (11:49 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 21 Oct 2021 20:04:01 +0000 (20:04 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java

index 303053e19619c983db296c1f99f11e63e042aec3..6f937d847b2223c0b4042494bbac41a46f23a99b 100644 (file)
@@ -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> 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());
     }
 
index 9630bd63d5c41218db8ae87730aa389bdc8f4857..79f1df9dc2a93186702a73276161a4c467971743 100644 (file)
@@ -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();