aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.gradle2
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java13
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ActiveVersionEvaluator.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ActiveVersionEvaluatorTest.java15
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java8
7 files changed, 35 insertions, 16 deletions
diff --git a/build.gradle b/build.gradle
index a3f86cb4bc6..301c95821b3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -477,7 +477,7 @@ subprojects {
exclude 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
}
dependency 'com.sonarsource.pdfreport:security-report-pdf-generation:2.0.0.165'
- dependency 'org.sonarsource.update-center:sonar-update-center-common:1.32.0.2441'
+ dependency 'org.sonarsource.update-center:sonar-update-center-common:1.34.0.2766'
dependency("org.springframework:spring-context:${springVersion}") {
exclude 'commons-logging:commons-logging'
}
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java
index 48561139088..a1259e43d78 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java
@@ -30,9 +30,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.Properties;
import org.sonar.api.Property;
+import org.sonar.api.SonarEdition;
import org.sonar.api.config.Configuration;
+import org.sonar.api.internal.MetadataLoader;
+import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.process.ProcessProperties;
+import org.sonar.updatecenter.common.Product;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.UpdateCenterDeserializer;
import org.sonar.updatecenter.common.UpdateCenterDeserializer.Mode;
@@ -67,6 +71,7 @@ public class UpdateCenterClient {
static final String CACHE_TTL_DEFAULT_VALUE = "3600000";
private final long periodInMilliseconds;
+ private final Product product;
private final URI uri;
private final UriReader uriReader;
@@ -74,11 +79,14 @@ public class UpdateCenterClient {
private UpdateCenter pluginCenter = null;
private long lastRefreshDate = 0;
+
public UpdateCenterClient(UriReader uriReader, Configuration config) throws URISyntaxException {
this.uriReader = uriReader;
this.uri = new URI(config.get(URL_PROPERTY).get());
this.isActivated = config.getBoolean(ProcessProperties.Property.SONAR_UPDATECENTER_ACTIVATE.getKey()).get();
this.periodInMilliseconds = Long.parseLong(config.get(CACHE_TTL_PROPERTY).get());
+ this.product = MetadataLoader.loadEdition(System2.INSTANCE) == SonarEdition.COMMUNITY ?
+ Product.SONARQUBE_COMMUNITY_BUILD : Product.SONARQUBE_SERVER;
LOG.info("Update center: {}", uriReader.description(uri));
}
@@ -114,8 +122,9 @@ public class UpdateCenterClient {
java.util.Properties properties = new java.util.Properties();
input = IOUtils.toInputStream(content, StandardCharsets.UTF_8);
properties.load(input);
- return new UpdateCenterDeserializer(Mode.PROD, true).fromProperties(properties);
-
+ UpdateCenter updateCenter = new UpdateCenterDeserializer(Mode.PROD, true).fromProperties(properties);
+ updateCenter.setInstalledSonarProduct(product);
+ return updateCenter;
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Fail to connect to update center", e);
return null;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ActiveVersionEvaluator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ActiveVersionEvaluator.java
index f6e7d5a9298..fae0633163c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ActiveVersionEvaluator.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ActiveVersionEvaluator.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.SortedSet;
import org.sonar.api.utils.System2;
import org.sonar.core.platform.SonarQubeVersion;
+import org.sonar.updatecenter.common.Product;
import org.sonar.updatecenter.common.Release;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.Version;
@@ -45,11 +46,14 @@ public class ActiveVersionEvaluator {
public boolean evaluateIfActiveVersion(UpdateCenter updateCenter) {
Version installedVersion = Version.create(sonarQubeVersion.get().toString());
+ if (updateCenter.getInstalledSonarProduct() == Product.SONARQUBE_COMMUNITY_BUILD) {
+ return true;
+ }
if (compareWithoutPatchVersion(installedVersion, updateCenter.getSonar().getLtaVersion().getVersion()) == 0) {
return true;
}
- SortedSet<Release> allReleases = updateCenter.getSonar().getAllReleases();
+ SortedSet<Release> allReleases = updateCenter.getSonar().getAllReleases(updateCenter.getInstalledSonarProduct());
if (compareWithoutPatchVersion(installedVersion, updateCenter.getSonar().getPastLtaVersion().getVersion()) == 0) {
Release initialLtaRelease = findInitialVersionOfMajorRelease(allReleases, updateCenter.getSonar().getLtaVersion().getVersion());
Date initialLtaReleaseDate = initialLtaRelease.getDate();
@@ -77,7 +81,8 @@ public class ActiveVersionEvaluator {
.filter(release -> release.getVersion().getMajor().equals(referenceVersion.getMajor())
&& release.getVersion().getMinor().equals(referenceVersion.getMinor()))
.min(Comparator.comparing(r -> Integer.parseInt(r.getVersion().getPatch())))
- .orElseThrow(() -> new IllegalStateException("Unable to find initial major release for version " + referenceVersion + " in releases"));
+ .orElseThrow(() -> new IllegalStateException("Unable to find initial major release for version " + referenceVersion + " in releases"
+ ));
}
private static Release findPreviousReleaseIgnoringPatch(SortedSet<Release> releases) {
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 e66308cefbc..7a5a0d38efa 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
@@ -57,6 +57,7 @@ public class UpgradesAction implements SystemWsAction {
private static final String PROPERTY_DEVELOPER_DOWNLOAD_URL = "downloadDeveloperUrl";
private static final String PROPERTY_ENTERPRISE_DOWNLOAD_URL = "downloadEnterpriseUrl";
private static final String PROPERTY_DATACENTER_DOWNLOAD_URL = "downloadDatacenterUrl";
+ private static final String PROPERTY_PRODUCT = "product";
private static final String OBJECT_PLUGINS = "plugins";
private static final String ARRAY_REQUIRE_UPDATE = "requireUpdate";
private static final String ARRAY_INCOMPATIBLE = "incompatible";
@@ -89,6 +90,7 @@ public class UpgradesAction implements SystemWsAction {
jsonWriter.prop(PROPERTY_DEVELOPER_DOWNLOAD_URL, release.getDownloadUrl(Release.Edition.DEVELOPER));
jsonWriter.prop(PROPERTY_ENTERPRISE_DOWNLOAD_URL, release.getDownloadUrl(Release.Edition.ENTERPRISE));
jsonWriter.prop(PROPERTY_DATACENTER_DOWNLOAD_URL, release.getDownloadUrl(Release.Edition.DATACENTER));
+ jsonWriter.prop(PROPERTY_PRODUCT, release.getProduct().name());
}
@Override
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 44795b2dee5..b70a0c194b1 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
@@ -1,7 +1,7 @@
{
"upgrades": [
{
- "version": "5.1 (build 5498)",
+ "version": "2025.1 (build 5498)",
"description": "New overall layout, merge Issues Drilldown [...]",
"releaseDate": "2015-04-02",
"changeLogUrl": "http://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=11694&version=20666",
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ActiveVersionEvaluatorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ActiveVersionEvaluatorTest.java
index 2781e1b5078..d6d507e6b28 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ActiveVersionEvaluatorTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ActiveVersionEvaluatorTest.java
@@ -34,6 +34,7 @@ import org.sonar.updatecenter.common.Version;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.Version.parse;
@@ -56,7 +57,7 @@ class ActiveVersionEvaluatorTest {
@Test
void evaluateIfActiveVersion_whenInstalledVersionIsLatestLta_shouldReturnActiveVersion() {
- when(updateCenter.getSonar().getAllReleases()).thenReturn(getReleases());
+ when(updateCenter.getSonar().getAllReleases(any())).thenReturn(getReleases());
when(sonarQubeVersion.get()).thenReturn(parse("9.9.2"));
assertThat(underTest.evaluateIfActiveVersion(updateCenter)).isTrue();
@@ -71,7 +72,7 @@ class ActiveVersionEvaluatorTest {
when(sonarQubeVersion.get()).thenReturn(parse("8.9.5"));
SortedSet<Release> releases = getReleases();
releases.stream().filter(r -> r.getVersion().equals(Version.create("9.9"))).findFirst().get().setDate(calendar.getTime());
- when(sonar.getAllReleases()).thenReturn(releases);
+ when(sonar.getAllReleases(any())).thenReturn(releases);
assertThat(underTest.evaluateIfActiveVersion(updateCenter)).isTrue();
}
@@ -87,7 +88,7 @@ class ActiveVersionEvaluatorTest {
when(sonarQubeVersion.get()).thenReturn(parse("8.9.5"));
SortedSet<Release> releases = getReleases();
releases.stream().filter(r -> r.getVersion().equals(Version.create("9.9"))).findFirst().get().setDate(calendar.getTime());
- when(sonar.getAllReleases()).thenReturn(releases);
+ when(sonar.getAllReleases(any())).thenReturn(releases);
assertThat(underTest.evaluateIfActiveVersion(updateCenter)).isFalse();
}
@@ -97,7 +98,7 @@ class ActiveVersionEvaluatorTest {
when(sonarQubeVersion.get()).thenReturn(parse("8.9.5"));
SortedSet<Release> releases = getReleases();
- when(sonar.getAllReleases()).thenReturn(releases);
+ when(sonar.getAllReleases(any())).thenReturn(releases);
assertThatThrownBy(() -> underTest.evaluateIfActiveVersion(updateCenter))
.isInstanceOf(IllegalStateException.class)
@@ -110,7 +111,7 @@ class ActiveVersionEvaluatorTest {
when(sonarQubeVersion.get()).thenReturn(parse("10.4.1"));
TreeSet<Release> releases = new TreeSet<>();
releases.add(new Release(sonar, Version.create("10.4.1")));
- when(sonar.getAllReleases()).thenReturn(releases);
+ when(sonar.getAllReleases(any())).thenReturn(releases);
assertThatThrownBy(() -> underTest.evaluateIfActiveVersion(updateCenter))
.isInstanceOf(IllegalStateException.class)
@@ -120,7 +121,7 @@ class ActiveVersionEvaluatorTest {
@Test
void evaluateIfActiveVersion_whenInstalledVersionIsLatestMinusOne_shouldReturnVersionIsActive() {
when(sonarQubeVersion.get()).thenReturn(parse("10.9"));
- when(updateCenter.getSonar().getAllReleases()).thenReturn(getReleases());
+ when(updateCenter.getSonar().getAllReleases(any())).thenReturn(getReleases());
assertThat(underTest.evaluateIfActiveVersion(updateCenter)).isTrue();
}
@@ -128,7 +129,7 @@ class ActiveVersionEvaluatorTest {
@Test
void evaluateIfActiveVersion_whenInstalledVersionIsSnapshot_shouldReturnVersionIsActive() {
when(sonarQubeVersion.get()).thenReturn(parse("10.11-SNAPSHOT"));
- when(updateCenter.getSonar().getAllReleases()).thenReturn(getReleases());
+ when(updateCenter.getSonar().getAllReleases(any())).thenReturn(getReleases());
assertThat(underTest.evaluateIfActiveVersion(updateCenter)).isTrue();
}
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 656135d4f6d..17a9e0c3b76 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
@@ -30,6 +30,7 @@ import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import org.sonar.updatecenter.common.Plugin;
+import org.sonar.updatecenter.common.Product;
import org.sonar.updatecenter.common.Release;
import org.sonar.updatecenter.common.Sonar;
import org.sonar.updatecenter.common.SonarUpdate;
@@ -61,7 +62,7 @@ class UpgradesActionTest {
private final WsActionTester tester = new WsActionTester(underTest);
- private static SonarUpdate createSonar_51_update() {
+ private static SonarUpdate createSonar_20251_update() {
Plugin brandingPlugin = Plugin.factory("branding")
.setCategory("Integration")
.setName("Branding")
@@ -84,9 +85,10 @@ class UpgradesActionTest {
.setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf")
.setIssueTrackerUrl("http://jira.sonarsource.com/browse/VIEWS");
- Release release = new Release(new Sonar(), Version.create("5.1.0.5498"))
+ Release release = new Release(new Sonar(), Version.create("2025.1.0.5498"))
.setDate(DateUtils.parseDate("2015-04-02"))
.setDescription("New overall layout, merge Issues Drilldown [...]")
+ .setProduct(Product.SONARQUBE_SERVER)
.setDownloadUrl("http://dist.sonar.codehaus.org/sonarqube-5.1.zip")
.setChangelogUrl("http://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=11694&version=20666");
SonarUpdate sonarUpdate = new SonarUpdate(release);
@@ -139,7 +141,7 @@ class UpgradesActionTest {
@Test
void verify_JSON_response_against_example() {
- SonarUpdate sonarUpdate = createSonar_51_update();
+ SonarUpdate sonarUpdate = createSonar_20251_update();
when(sonarQubeVersion.get()).thenReturn(parse("8.9.0"));
when(sonar.getLtsRelease()).thenReturn(new Release(sonar, Version.create("8.9.2")));
when(sonar.getLtaVersion()).thenReturn(new Release(sonar, Version.create("8.9.2")));