Search in sources :

Example 1 with ServerInfoStore

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

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

the class ProjectStorageUpdateExecutorTests method setUp.

public void setUp(@Nullable String organizationKey, Path tempDir) throws IOException {
    Files.createDirectory(tempDir);
    mockServer.addResponseFromResource(getQualityProfileUrl(organizationKey), "/update/qualityprofiles_project.pb");
    mockServer.addProtobufResponse("/api/settings/values.protobuf?component=" + URLEncoder.encode(MODULE_KEY_WITH_BRANCH, StandardCharsets.UTF_8), ValuesWsResponse.newBuilder().build());
    var response = ValuesWsResponse.newBuilder().addSettings(Setting.newBuilder().setKey("sonar.qualitygate").setValue("1").setInherited(true)).addSettings(Setting.newBuilder().setKey("sonar.core.version").setValue("6.7.1.23")).addSettings(Setting.newBuilder().setKey("sonar.java.someProp").setValue("foo")).build();
    mockServer.addProtobufResponse("/api/settings/values.protobufcomponent=" + MODULE_KEY_WITH_BRANCH_URLENCODED, response);
    var serverInfoStore = new ServerInfoStore(new StorageFolder.Default(tempDir));
    serverInfoStore.store(new ServerInfo("", "", ""));
    Map<String, String> modulesPath = new HashMap<>();
    modulesPath.put(MODULE_KEY_WITH_BRANCH, "");
    modulesPath.put(MODULE_KEY_WITH_BRANCH + "child1", "child 1");
    when(moduleHierarchy.fetchModuleHierarchy(eq(serverApiHelper), eq(MODULE_KEY_WITH_BRANCH), any(ProgressMonitor.class))).thenReturn(modulesPath);
    when(issueStoreFactory.apply(any(Path.class))).thenReturn(issueStore);
    projectConfigurationDownloader = new ProjectConfigurationDownloader(moduleHierarchy);
    underTest = new ProjectStorageUpdateExecutor(projectStoragePaths, projectConfigurationDownloader, projectFileListDownloader, serverIssueUpdater);
}
Also used : ServerInfoStore(org.sonarsource.sonarlint.core.container.storage.ServerInfoStore) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) Path(java.nio.file.Path) HashMap(java.util.HashMap) ServerInfo(org.sonarsource.sonarlint.core.serverapi.system.ServerInfo) ProjectConfigurationDownloader(org.sonarsource.sonarlint.core.container.connected.update.ProjectConfigurationDownloader) StorageFolder(org.sonarsource.sonarlint.core.container.storage.StorageFolder)

Aggregations

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