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);
}
}
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);
}
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);
}
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();
}
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));
}
Aggregations