Search in sources :

Example 1 with TempFolder

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

the class GlobalTempFolderProviderTest method createTempFolderDefault.

@Test
public void createTempFolderDefault() throws Exception {
    System2 system = mock(System2.class);
    tempFolderProvider = new GlobalTempFolderProvider(system);
    File userHome = temp.newFolder();
    when(system.envVariable("SONAR_USER_HOME")).thenReturn(null);
    when(system.property("user.home")).thenReturn(userHome.getAbsolutePath().toString());
    // if nothing is defined, it will be in {user.home}/.sonar/.sonartmp
    File defaultSonarHome = new File(userHome.getAbsolutePath(), ".sonar");
    File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
    try {
        TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(Collections.<String, String>emptyMap()));
        tempFolder.newDir();
        tempFolder.newFile();
        assertThat(getCreatedTempDir(workingDir)).exists();
        assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
    } finally {
        FileUtils.deleteQuietly(workingDir);
    }
}
Also used : GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) GlobalTempFolderProvider(org.sonar.scanner.bootstrap.GlobalTempFolderProvider) TempFolder(org.sonar.api.utils.TempFolder) System2(org.sonar.api.utils.System2) File(java.io.File) Test(org.junit.Test)

Example 2 with TempFolder

use of org.sonar.api.utils.TempFolder in project sonarqube 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, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
    TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
    tempFolder.newDir();
    tempFolder.newFile();
    assertThat(getCreatedTempDir(workingDir)).exists();
    assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
    FileUtils.deleteQuietly(sonarHome);
}
Also used : GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Example 3 with TempFolder

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

the class AnalysisTempFolderProviderTest method createTempFolder.

@Test
public void createTempFolder() throws IOException {
    File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME);
    TempFolder tempFolder = tempFolderProvider.provide(projectReactor);
    tempFolder.newDir();
    tempFolder.newFile();
    assertThat(defaultDir).exists();
    assertThat(defaultDir.list()).hasSize(2);
}
Also used : TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Example 4 with TempFolder

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

the class TempFolderProviderTest 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 : TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Example 5 with TempFolder

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

the class TempFolderProviderTest method existing_temp_dir.

@Test
public void existing_temp_dir() throws Exception {
    ServerFileSystem fs = mock(ServerFileSystem.class);
    File tmpDir = temp.newFolder();
    when(fs.getTempDir()).thenReturn(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 : TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)14 TempFolder (org.sonar.api.utils.TempFolder)14 Test (org.junit.Test)13 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