Search in sources :

Example 1 with GlobalProperties

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

use of org.sonar.scanner.bootstrap.GlobalProperties in project sonarqube by SonarSource.

the class GlobalTempFolderProviderTest method cleanUpOld.

@Test
public void cleanUpOld() throws IOException {
    long creationTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(100);
    File workingDir = temp.newFolder();
    for (int i = 0; i < 3; i++) {
        File tmp = new File(workingDir, ".sonartmp_" + i);
        tmp.mkdirs();
        setFileCreationDate(tmp, creationTime);
    }
    tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
    // this also checks that all other temps were deleted
    assertThat(getCreatedTempDir(workingDir)).exists();
    FileUtils.deleteQuietly(workingDir);
}
Also used : GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) File(java.io.File) Test(org.junit.Test)

Example 3 with GlobalProperties

use of org.sonar.scanner.bootstrap.GlobalProperties 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 4 with GlobalProperties

use of org.sonar.scanner.bootstrap.GlobalProperties in project sonarqube by SonarSource.

the class DefaultAnalysisModeTest method scan_all.

@Test
public void scan_all() {
    Map<String, String> props = new HashMap<>();
    props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
    GlobalProperties globalProps = new GlobalProperties(props);
    AnalysisProperties analysisProps = new AnalysisProperties(new HashMap<String, String>());
    DefaultAnalysisMode mode = new DefaultAnalysisMode(globalProps, analysisProps);
    assertThat(mode.scanAllFiles()).isFalse();
    props.put("sonar.scanAllFiles", "true");
    analysisProps = new AnalysisProperties(props);
    mode = new DefaultAnalysisMode(globalProps, analysisProps);
    assertThat(mode.scanAllFiles()).isTrue();
    props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH);
    analysisProps = new AnalysisProperties(props);
    mode = new DefaultAnalysisMode(globalProps, analysisProps);
    assertThat(mode.scanAllFiles()).isTrue();
}
Also used : GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) HashMap(java.util.HashMap) AnalysisProperties(org.sonar.scanner.analysis.AnalysisProperties) DefaultAnalysisMode(org.sonar.scanner.analysis.DefaultAnalysisMode) Test(org.junit.Test)

Example 5 with GlobalProperties

use of org.sonar.scanner.bootstrap.GlobalProperties in project sonarqube by SonarSource.

the class DefaultAnalysisModeTest method createMode.

private static DefaultAnalysisMode createMode(@Nullable String bootstrapMode, @Nullable String analysisMode) {
    Map<String, String> bootstrapMap = new HashMap<>();
    Map<String, String> analysisMap = new HashMap<>();
    if (bootstrapMode != null) {
        bootstrapMap.put(CoreProperties.ANALYSIS_MODE, bootstrapMode);
    }
    if (analysisMode != null) {
        analysisMap.put(CoreProperties.ANALYSIS_MODE, analysisMode);
    }
    return new DefaultAnalysisMode(new GlobalProperties(bootstrapMap), new AnalysisProperties(analysisMap));
}
Also used : GlobalProperties(org.sonar.scanner.bootstrap.GlobalProperties) HashMap(java.util.HashMap) AnalysisProperties(org.sonar.scanner.analysis.AnalysisProperties) DefaultAnalysisMode(org.sonar.scanner.analysis.DefaultAnalysisMode)

Aggregations

GlobalProperties (org.sonar.scanner.bootstrap.GlobalProperties)10 Test (org.junit.Test)7 File (java.io.File)5 TempFolder (org.sonar.api.utils.TempFolder)4 HashMap (java.util.HashMap)3 DefaultAnalysisMode (org.sonar.scanner.analysis.DefaultAnalysisMode)3 AnalysisProperties (org.sonar.scanner.analysis.AnalysisProperties)2 GlobalMode (org.sonar.scanner.bootstrap.GlobalMode)2 Before (org.junit.Before)1 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)1 System2 (org.sonar.api.utils.System2)1 GlobalSettings (org.sonar.scanner.bootstrap.GlobalSettings)1 GlobalTempFolderProvider (org.sonar.scanner.bootstrap.GlobalTempFolderProvider)1