Search in sources :

Example 1 with ServerInfos

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");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) StorageStatus(org.sonarsource.sonarlint.core.proto.Sonarlint.StorageStatus) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) Test(org.junit.Test)

Example 2 with ServerInfos

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;
}
Also used : SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Example 3 with ServerInfos

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;
    }
}
Also used : Path(java.nio.file.Path) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) StorageStatus(org.sonarsource.sonarlint.core.proto.Sonarlint.StorageStatus) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) Date(java.util.Date)

Example 4 with ServerInfos

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 &lt; 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;
}
Also used : Version(org.sonarsource.sonarlint.core.plugin.Version) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Example 5 with ServerInfos

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);
            }
        }
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Aggregations

ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)8 Version (org.sonarsource.sonarlint.core.plugin.Version)3 SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)2 UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)2 StorageStatus (org.sonarsource.sonarlint.core.proto.Sonarlint.StorageStatus)2 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)2 WsResponse (org.sonarsource.sonarlint.core.util.ws.WsResponse)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 Test (org.junit.Test)1 ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)1 AuthenticationChecker (org.sonarsource.sonarlint.core.container.connected.validate.AuthenticationChecker)1 DefaultValidationResult (org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult)1 ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker)1