Search in sources :

Example 1 with ServerProjectsStore

use of org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore 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 ServerProjectsStore

use of org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore in project sonarlint-core by SonarSource.

the class ProjectListDownloaderTests method update_modules_with_org.

@Test
void update_modules_with_org(@TempDir Path tempDir) {
    var serverProjectsStore = new ServerProjectsStore(new StorageFolder.Default(tempDir));
    mockServer.addResponseFromResource("/api/components/search.protobuf?qualifiers=TRK&organization=myOrg&ps=500&p=1", "/update/searchmodulesp1.pb");
    var moduleListUpdate = new ProjectListDownloader(mockServer.serverApiHelper("myOrg"), serverProjectsStore);
    moduleListUpdate.fetch(new ProgressMonitor(null));
    var moduleList = ProtobufUtil.readFile(tempDir.resolve(ServerProjectsStore.PROJECT_LIST_PB), ProjectList.parser());
    assertThat(moduleList.getProjectsByKeyMap()).hasSize(282);
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerProjectsStore(org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore) StorageFolder(org.sonarsource.sonarlint.core.container.storage.StorageFolder) Test(org.junit.jupiter.api.Test)

Example 3 with ServerProjectsStore

use of org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore in project sonarlint-core by SonarSource.

the class ProjectListDownloaderTests method update_modules.

@Test
void update_modules(@TempDir Path tempDir) {
    var serverProjectsStore = new ServerProjectsStore(new StorageFolder.Default(tempDir));
    mockServer.addResponseFromResource("/api/components/search.protobuf?qualifiers=TRK&ps=500&p=1", "/update/searchmodulesp1.pb");
    var moduleListUpdate = new ProjectListDownloader(mockServer.serverApiHelper(), serverProjectsStore);
    moduleListUpdate.fetch(new ProgressMonitor(null));
    var moduleList = ProtobufUtil.readFile(tempDir.resolve(ServerProjectsStore.PROJECT_LIST_PB), ProjectList.parser());
    assertThat(moduleList.getProjectsByKeyMap()).hasSize(282);
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerProjectsStore(org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore) StorageFolder(org.sonarsource.sonarlint.core.container.storage.StorageFolder) Test(org.junit.jupiter.api.Test)

Aggregations

ServerProjectsStore (org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore)3 StorageFolder (org.sonarsource.sonarlint.core.container.storage.StorageFolder)3 Test (org.junit.jupiter.api.Test)2 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 ProjectListDownloader (org.sonarsource.sonarlint.core.container.connected.update.ProjectListDownloader)1 ServerInfoStore (org.sonarsource.sonarlint.core.container.storage.ServerInfoStore)1 StorageStatusStore (org.sonarsource.sonarlint.core.container.storage.StorageStatusStore)1 ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker)1