Search in sources :

Example 1 with ServerVersionAndStatusChecker

use of org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker in project sonarlint-core by SonarSource.

the class GlobalStorageUpdateExecutor method update.

public void update(ServerApiHelper serverApiHelper, ProgressMonitor progress) {
    Path temp;
    try {
        temp = Files.createTempDirectory("sonarlint-global-storage");
    } catch (IOException e) {
        throw new IllegalStateException("Unable to create temp directory", e);
    }
    try {
        StorageFolder storageFolder = new StorageFolder.Default(temp);
        var serverInfoStore = new ServerInfoStore(storageFolder);
        var serverProjectsStore = new ServerProjectsStore(storageFolder);
        var storageStatusStore = new StorageStatusStore(storageFolder);
        progress.setProgressAndCheckCancel("Checking server version and status", 0.1f);
        var serverStatus = new ServerVersionAndStatusChecker(serverApiHelper).checkVersionAndStatus();
        serverInfoStore.store(serverStatus);
        progress.setProgressAndCheckCancel("Fetching list of projects", 0.8f);
        var projectListDownloader = new ProjectListDownloader(serverApiHelper, serverProjectsStore);
        projectListDownloader.fetch(progress.subProgress(0.8f, 1.0f, "Fetching list of projects"));
        progress.setProgressAndCheckCancel("Finalizing...", 1.0f);
        progress.executeNonCancelableSection(() -> {
            var storageStatus = StorageStatus.newBuilder().setStorageVersion(ProjectStoragePaths.STORAGE_VERSION).setSonarlintCoreVersion(VersionUtils.getLibraryVersion()).setUpdateTimestamp(new Date().getTime()).build();
            storageStatusStore.store(storageStatus);
            serverStorage.replaceStorageWith(temp);
        });
    } finally {
        org.apache.commons.io.FileUtils.deleteQuietly(temp.toFile());
    }
}
Also used : Path(java.nio.file.Path) ServerInfoStore(org.sonarsource.sonarlint.core.container.storage.ServerInfoStore) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) StorageStatusStore(org.sonarsource.sonarlint.core.container.storage.StorageStatusStore) ServerProjectsStore(org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore) IOException(java.io.IOException) ProjectListDownloader(org.sonarsource.sonarlint.core.container.connected.update.ProjectListDownloader) Date(java.util.Date) StorageFolder(org.sonarsource.sonarlint.core.container.storage.StorageFolder)

Example 2 with ServerVersionAndStatusChecker

use of org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker in project sonarlint-core by SonarSource.

the class ConnectionValidator method validateConnection.

public CompletableFuture<ValidationResult> validateConnection() {
    var serverChecker = new ServerVersionAndStatusChecker(helper);
    var authChecker = new AuthenticationChecker(helper);
    return serverChecker.checkVersionAndStatusAsync().thenApply(check -> {
        var validateCredentials = authChecker.validateCredentials();
        var organizationKey = helper.getOrganizationKey();
        if (validateCredentials.success() && organizationKey.isPresent()) {
            var organization = new ServerApi(helper).organization().fetchOrganization(organizationKey.get(), new ProgressMonitor(null));
            if (organization.isEmpty()) {
                return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey.get());
            }
        }
        return validateCredentials;
    }).exceptionally(e -> new DefaultValidationResult(false, e.getCause().getMessage()));
}
Also used : AuthenticationChecker(org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) ServerOrganization(org.sonarsource.sonarlint.core.serverapi.organization.ServerOrganization) ValidationResult(org.sonarsource.sonarlint.core.serverapi.system.ValidationResult) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) DefaultValidationResult(org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) AuthenticationChecker(org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker) DefaultValidationResult(org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi)

Aggregations

ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)1 ProjectListDownloader (org.sonarsource.sonarlint.core.container.connected.update.ProjectListDownloader)1 ServerInfoStore (org.sonarsource.sonarlint.core.container.storage.ServerInfoStore)1 ServerProjectsStore (org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore)1 StorageFolder (org.sonarsource.sonarlint.core.container.storage.StorageFolder)1 StorageStatusStore (org.sonarsource.sonarlint.core.container.storage.StorageStatusStore)1 ServerApi (org.sonarsource.sonarlint.core.serverapi.ServerApi)1 ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)1 AuthenticationChecker (org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker)1 ServerOrganization (org.sonarsource.sonarlint.core.serverapi.organization.ServerOrganization)1 DefaultValidationResult (org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult)1 ValidationResult (org.sonarsource.sonarlint.core.serverapi.system.ValidationResult)1