use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.
the class GlobalStorageUpdateExecutorTest method testUpdate.
@Test
public void testUpdate() throws Exception {
globalUpdate.update(new ProgressWrapper(null));
StorageStatus updateStatus = ProtobufUtil.readFile(destDir.toPath().resolve(StoragePaths.STORAGE_STATUS_PB), StorageStatus.parser());
assertThat(updateStatus.getClientUserAgent()).isEqualTo("UT");
assertThat(updateStatus.getSonarlintCoreVersion()).isEqualTo(VersionUtils.getLibraryVersion());
assertThat(updateStatus.getUpdateTimestamp()).isNotEqualTo(0);
ServerInfos serverInfos = ProtobufUtil.readFile(destDir.toPath().resolve(StoragePaths.SERVER_INFO_PB), ServerInfos.parser());
assertThat(serverInfos.getId()).isEqualTo("20160308094653");
assertThat(serverInfos.getVersion()).isEqualTo("5.6-SNAPSHOT");
}
use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.
the class GlobalStorageUpdateChecker method checkForUpdate.
public StorageUpdateCheckResult checkForUpdate(ProgressWrapper progress) {
DefaultStorageUpdateCheckResult result = new DefaultStorageUpdateCheckResult();
progress.setProgressAndCheckCancel("Checking server version and status", 0.1f);
ServerInfos serverStatus = statusChecker.checkVersionAndStatus();
// Currently with don't check server version change since it is unlikely to have impact on SL
progress.setProgressAndCheckCancel("Checking global properties", 0.3f);
globalSettingsUpdateChecker.checkForUpdates(serverStatus.getVersion(), result);
progress.setProgressAndCheckCancel("Checking plugins", 0.5f);
List<SonarAnalyzer> pluginList = pluginListDownloader.downloadPluginList(serverStatus.getVersion());
pluginsUpdateChecker.checkForUpdates(result, pluginList);
progress.setProgressAndCheckCancel("Checking quality profiles", 0.7f);
qualityProfilesUpdateChecker.checkForUpdates(result);
progress.setProgressAndCheckCancel("Done", 1.0f);
return result;
}
use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.
the class GlobalStorageUpdateExecutor method update.
public List<SonarAnalyzer> update(ProgressWrapper progress) {
Path temp = tempFolder.newDir().toPath();
try {
progress.setProgressAndCheckCancel("Checking server version and status", 0.1f);
ServerInfos serverStatus = statusChecker.checkVersionAndStatus();
progress.setProgressAndCheckCancel("Fetching list of analyzers", 0.12f);
List<SonarAnalyzer> analyzers = pluginListDownloader.downloadPluginList(serverStatus.getVersion());
ProtobufUtil.writeToFile(serverStatus, temp.resolve(StoragePaths.SERVER_INFO_PB));
progress.setProgressAndCheckCancel("Fetching global properties", 0.15f);
globalSettingsDownloader.fetchGlobalSettingsTo(serverStatus.getVersion(), temp);
progress.setProgressAndCheckCancel("Fetching analyzers", 0.25f);
pluginReferenceDownloader.fetchPluginsTo(temp, analyzers);
progress.setProgressAndCheckCancel("Fetching rules", 0.4f);
rulesDownloader.fetchRulesTo(temp, progress.subProgress(0.4f, 0.6f, "Fetching rules"));
progress.setProgressAndCheckCancel("Fetching quality profiles", 0.6f);
qualityProfilesDownloader.fetchQualityProfilesTo(temp);
progress.setProgressAndCheckCancel("Fetching list of modules", 0.8f);
moduleListDownloader.fetchModulesListTo(temp, serverStatus.getVersion(), progress.subProgress(0.8f, 1.0f, "Fetching list of modules"));
progress.startNonCancelableSection();
progress.setProgressAndCheckCancel("Finalizing...", 1.0f);
StorageStatus storageStatus = StorageStatus.newBuilder().setStorageVersion(StoragePaths.STORAGE_VERSION).setClientUserAgent(wsClient.getUserAgent()).setSonarlintCoreVersion(VersionUtils.getLibraryVersion()).setUpdateTimestamp(new Date().getTime()).build();
ProtobufUtil.writeToFile(storageStatus, temp.resolve(StoragePaths.STORAGE_STATUS_PB));
Path dest = storageManager.getGlobalStorageRoot();
FileUtils.deleteRecursively(dest);
FileUtils.mkdirs(dest.getParent());
FileUtils.moveDir(temp, dest);
return analyzers;
} catch (RuntimeException e) {
try {
FileUtils.deleteRecursively(temp);
} catch (RuntimeException ignore) {
// ignore because we want to throw original exception
}
throw e;
}
}
use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.
the class ServerVersionAndStatusChecker method checkVersionAndStatus.
/**
* Checks SonarQube version against a provided minimum version
* @return ServerInfos
* @throws UnsupportedServerException if version < minimum supported version
* @throws IllegalStateException If server is not ready
*/
public ServerInfos checkVersionAndStatus(String minVersion) {
ServerInfos serverStatus = fetchServerInfos();
if (!"UP".equals(serverStatus.getStatus())) {
throw new IllegalStateException(serverNotReady(serverStatus));
}
Version serverVersion = Version.create(serverStatus.getVersion());
if (serverVersion.compareToIgnoreQualifier(Version.create(minVersion)) < 0) {
throw new UnsupportedServerException(unsupportedVersion(serverStatus, minVersion));
}
return serverStatus;
}
use of org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos in project sonarlint-core by SonarSource.
the class ServerVersionAndStatusChecker method fetchServerInfos.
private ServerInfos fetchServerInfos() {
try (WsResponse response = wsClient.rawGet("api/system/status")) {
if (!response.isSuccessful()) {
if (response.code() == HttpURLConnection.HTTP_NOT_FOUND) {
return tryFromDeprecatedApi(response);
} else {
throw SonarLintWsClient.handleError(response);
}
} else {
String responseStr = response.content();
try {
ServerInfos.Builder builder = ServerInfos.newBuilder();
JsonFormat.parser().merge(responseStr, builder);
return builder.build();
} catch (InvalidProtocolBufferException e) {
throw new IllegalStateException("Unable to parse server infos from: " + StringUtils.abbreviate(responseStr, 100), e);
}
}
}
}
Aggregations