Search in sources :

Example 1 with GlobalTempFolderProvider

use of org.sonar.scanner.bootstrap.GlobalTempFolderProvider 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)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 System2 (org.sonar.api.utils.System2)1 TempFolder (org.sonar.api.utils.TempFolder)1 GlobalProperties (org.sonar.scanner.bootstrap.GlobalProperties)1 GlobalTempFolderProvider (org.sonar.scanner.bootstrap.GlobalTempFolderProvider)1