Search in sources :

Example 11 with TempFolder

use of org.sonar.api.utils.TempFolder in project sonarlint-core by SonarSource.

the class GlobalTempFolderProviderTests method createTempFolderProps.

@Test
void createTempFolderProps() throws Exception {
    TempFolder tempFolder = tempFolderProvider.provide(AnalysisEngineConfiguration.builder().setWorkDir(workingDir).build());
    tempFolder.newDir();
    tempFolder.newFile();
    assertThat(getCreatedTempDir(workingDir)).exists();
    assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
    FileUtils.deleteQuietly(workingDir.toFile());
}
Also used : TempFolder(org.sonar.api.utils.TempFolder) Test(org.junit.jupiter.api.Test)

Example 12 with TempFolder

use of org.sonar.api.utils.TempFolder in project sonarlint-core by SonarSource.

the class ModuleStorageUpdateExecutorTest method module_update.

@Test
public void module_update() throws Exception {
    File destDir = temp.newFolder();
    QProfiles.Builder builder = QProfiles.newBuilder();
    builder.putQprofilesByKey("cs-sonar-way-58886", QProfiles.QProfile.newBuilder().build());
    builder.putQprofilesByKey("java-empty-74333", QProfiles.QProfile.newBuilder().build());
    builder.putQprofilesByKey("js-sonar-way-60746", QProfiles.QProfile.newBuilder().build());
    builder.putQprofilesByKey("xoo2-basic-34035", QProfiles.QProfile.newBuilder().build());
    when(storageReader.readQProfiles()).thenReturn(builder.build());
    when(storagePaths.getModuleStorageRoot(MODULE_KEY_WITH_BRANCH)).thenReturn(destDir.toPath());
    moduleUpdate = new ModuleStorageUpdateExecutor(storageReader, storagePaths, wsClient, (key) -> Collections.emptyList(), issueStoreFactory, tempFolder, moduleConfigurationDownloader);
    moduleUpdate.update(MODULE_KEY_WITH_BRANCH, new ProgressWrapper(null));
    ModuleConfiguration moduleConfiguration = ProtobufUtil.readFile(destDir.toPath().resolve(StoragePaths.MODULE_CONFIGURATION_PB), ModuleConfiguration.parser());
    assertThat(moduleConfiguration.getQprofilePerLanguage()).containsOnly(entry("cs", "cs-sonar-way-58886"), entry("java", "java-empty-74333"), entry("js", "js-sonar-way-60746"));
    assertThat(moduleConfiguration.getModulePathByKey()).containsOnly(entry(MODULE_KEY_WITH_BRANCH, ""), entry(MODULE_KEY_WITH_BRANCH + "child1", "child 1"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IssueStoreFactory(org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) HashMap(java.util.HashMap) StoragePaths(org.sonarsource.sonarlint.core.container.storage.StoragePaths) Map(java.util.Map) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles) Path(java.nio.file.Path) ExpectedException(org.junit.rules.ExpectedException) ModuleConfigurationDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleConfigurationDownloader) Nullable(javax.annotation.Nullable) Parameterized(org.junit.runners.Parameterized) TempFolder(org.sonar.api.utils.TempFolder) Before(org.junit.Before) IssueStore(org.sonarsource.sonarlint.core.container.connected.IssueStore) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ModuleQualityProfilesDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleQualityProfilesDownloader) IssueDownloader(org.sonarsource.sonarlint.core.container.connected.update.IssueDownloader) SettingsDownloader(org.sonarsource.sonarlint.core.container.connected.update.SettingsDownloader) StorageReader(org.sonarsource.sonarlint.core.container.storage.StorageReader) ProtobufUtilTest.newEmptyStream(org.sonarsource.sonarlint.core.container.storage.ProtobufUtilTest.newEmptyStream) IOException(java.io.IOException) Test(org.junit.Test) WsClientTestUtils(org.sonarsource.sonarlint.core.WsClientTestUtils) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) Mockito.when(org.mockito.Mockito.when) ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) Assertions.entry(org.assertj.core.api.Assertions.entry) File(java.io.File) InMemoryIssueStore(org.sonarsource.sonarlint.core.container.connected.InMemoryIssueStore) Rule(org.junit.Rule) StringUtils(org.sonarsource.sonarlint.core.util.StringUtils) ProtobufUtil(org.sonarsource.sonarlint.core.container.storage.ProtobufUtil) IssueUtils.createFileKey(org.sonarsource.sonarlint.core.container.connected.update.IssueUtils.createFileKey) ModuleHierarchyDownloader(org.sonarsource.sonarlint.core.container.connected.update.ModuleHierarchyDownloader) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) File(java.io.File) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles) Test(org.junit.Test)

Example 13 with TempFolder

use of org.sonar.api.utils.TempFolder in project sonarlint-core by SonarSource.

the class GlobalTempFolderProviderTest method createTempFolderProps.

@Test
public void createTempFolderProps() throws Exception {
    File workingDir = temp.newFolder();
    TempFolder tempFolder = tempFolderProvider.provide(StandaloneGlobalConfiguration.builder().setWorkDir(workingDir.toPath()).build());
    tempFolder.newDir();
    tempFolder.newFile();
    assertThat(getCreatedTempDir(workingDir)).exists();
    assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
    FileUtils.deleteQuietly(workingDir);
}
Also used : TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Example 14 with TempFolder

use of org.sonar.api.utils.TempFolder in project sonarlint-core by SonarSource.

the class GlobalTempFolderProviderTest method createTempFolderSonarHome.

@Test
public void createTempFolderSonarHome() throws Exception {
    // with sonar home, it will be in {sonar.home}/.sonartmp
    File sonarHome = temp.newFolder();
    File workingDir = new File(sonarHome, StandaloneGlobalConfiguration.DEFAULT_WORK_DIR).getAbsoluteFile();
    TempFolder tempFolder = tempFolderProvider.provide(StandaloneGlobalConfiguration.builder().setSonarLintUserHome(sonarHome.toPath()).build());
    tempFolder.newDir();
    tempFolder.newFile();
    assertThat(getCreatedTempDir(workingDir)).exists();
    assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
    FileUtils.deleteQuietly(sonarHome);
}
Also used : TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Example 15 with TempFolder

use of org.sonar.api.utils.TempFolder in project sonarqube by SonarSource.

the class ComputationTempFolderProviderTest method create_temp_dir_if_missing.

@Test
public void create_temp_dir_if_missing() throws Exception {
    ServerFileSystem fs = mock(ServerFileSystem.class);
    File tmpDir = temp.newFolder();
    when(fs.getTempDir()).thenReturn(tmpDir);
    FileUtils.forceDelete(tmpDir);
    TempFolder folder = underTest.provide(fs);
    assertThat(folder).isNotNull();
    File newDir = folder.newDir();
    assertThat(newDir).exists().isDirectory();
    assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath());
}
Also used : ServerFileSystem(org.sonar.server.platform.ServerFileSystem) TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Aggregations

TempFolder (org.sonar.api.utils.TempFolder)18 File (java.io.File)17 Test (org.junit.Test)16 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 InMemoryIssueStore (org.sonarsource.sonarlint.core.container.connected.InMemoryIssueStore)5 IssueStoreFactory (org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory)5 ModuleConfigurationDownloader (org.sonarsource.sonarlint.core.container.connected.update.ModuleConfigurationDownloader)5 ModuleHierarchyDownloader (org.sonarsource.sonarlint.core.container.connected.update.ModuleHierarchyDownloader)5 ModuleQualityProfilesDownloader (org.sonarsource.sonarlint.core.container.connected.update.ModuleQualityProfilesDownloader)5 StoragePaths (org.sonarsource.sonarlint.core.container.storage.StoragePaths)5 StorageReader (org.sonarsource.sonarlint.core.container.storage.StorageReader)5 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Map (java.util.Map)4 Nullable (javax.annotation.Nullable)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.entry (org.assertj.core.api.Assertions.entry)4