Browse Source

SONAR-20773 Update the update-center URL

tags/10.5.0.89998
Eric Giffon 2 months ago
parent
commit
f26bae81f1

+ 7
- 5
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java View File

@@ -38,21 +38,21 @@ import org.sonar.updatecenter.common.UpdateCenterDeserializer;
import org.sonar.updatecenter.common.UpdateCenterDeserializer.Mode;

/**
* HTTP client to load data from the remote update center hosted at https://update.sonarsource.org.
* HTTP client to load data from the remote update center hosted at https://downloads.sonarsource.com/?prefix=sonarqube/update
*
* @since 2.4
*/
@Properties({
@Property(
key = UpdateCenterClient.URL_PROPERTY,
defaultValue = "https://update.sonarsource.org/update-center.properties",
defaultValue = UpdateCenterClient.URL_DEFAULT_VALUE,
name = "Update Center URL",
category = "Update Center",
// hidden from UI
global = false),
@Property(
key = UpdateCenterClient.CACHE_TTL_PROPERTY,
defaultValue = "3600000",
defaultValue = UpdateCenterClient.CACHE_TTL_DEFAULT_VALUE,
name = "Update Center cache time-to-live in milliseconds",
category = "Update Center",
// hidden from UI
@@ -61,8 +61,10 @@ import org.sonar.updatecenter.common.UpdateCenterDeserializer.Mode;
public class UpdateCenterClient {

private static final Logger LOG = LoggerFactory.getLogger(UpdateCenterClient.class);
public static final String URL_PROPERTY = "sonar.updatecenter.url";
public static final String CACHE_TTL_PROPERTY = "sonar.updatecenter.cache.ttl";
static final String URL_PROPERTY = "sonar.updatecenter.url";
static final String URL_DEFAULT_VALUE = "https://downloads.sonarsource.com/sonarqube/update/update-center.properties";
static final String CACHE_TTL_PROPERTY = "sonar.updatecenter.cache.ttl";
static final String CACHE_TTL_DEFAULT_VALUE = "3600000";

private final long periodInMilliseconds;


+ 9
- 10
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java View File

@@ -38,11 +38,10 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.server.plugins.UpdateCenterClient.*;

public class UpdateCenterClientTest {

private static final String BASE_URL = "https://update.sonarsource.org";
private static final String DEFAULT_CACHE_TTL = "3600000";
private UriReader reader = mock(UriReader.class);
private MapSettings settings = new MapSettings();
private UpdateCenterClient underTest;
@@ -50,17 +49,17 @@ public class UpdateCenterClientTest {
@Before
public void startServer() throws Exception {
reader = mock(UriReader.class);
settings.setProperty(UpdateCenterClient.URL_PROPERTY, BASE_URL);
settings.setProperty(URL_PROPERTY, URL_DEFAULT_VALUE);
settings.setProperty(ProcessProperties.Property.SONAR_UPDATECENTER_ACTIVATE.getKey(), true);
settings.setProperty(UpdateCenterClient.CACHE_TTL_PROPERTY, DEFAULT_CACHE_TTL);
settings.setProperty(CACHE_TTL_PROPERTY, CACHE_TTL_DEFAULT_VALUE);
underTest = new UpdateCenterClient(reader, settings.asConfig());
}

@Test
public void downloadUpdateCenter() throws URISyntaxException {
when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("publicVersions=2.2,2.3");
when(reader.readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8)).thenReturn("publicVersions=2.2,2.3");
UpdateCenter plugins = underTest.getUpdateCenter().get();
verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
verify(reader, times(1)).readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8);
assertThat(plugins.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3"));
assertThat(underTest.getLastRefreshDate()).isNotNull();
}
@@ -78,22 +77,22 @@ public class UpdateCenterClientTest {

@Test
public void cache_data() throws Exception {
when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
when(reader.readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");

underTest.getUpdateCenter();
underTest.getUpdateCenter();

verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
verify(reader, times(1)).readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8);
}

@Test
public void forceRefresh() throws Exception {
when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
when(reader.readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");

underTest.getUpdateCenter();
underTest.getUpdateCenter(true);

verify(reader, times(2)).readString(new URI(BASE_URL), StandardCharsets.UTF_8);
verify(reader, times(2)).readString(new URI(URL_DEFAULT_VALUE), StandardCharsets.UTF_8);
}

@Test

+ 1
- 1
sonar-application/src/main/assembly/conf/sonar.properties View File

@@ -297,7 +297,7 @@
#--------------------------------------------------------------------------------------------------
# UPDATE CENTER

# Update Center requires an internet connection to request https://update.sonarsource.org
# Update Center requires an internet connection to request https://downloads.sonarsource.com/?prefix=sonarqube/update
# It is enabled by default.
#sonar.updatecenter.activate=true


Loading…
Cancel
Save