@@ -39,11 +39,11 @@ public class BatchTest { | |||
.addPlugin(ItUtils.xooPlugin()) | |||
.setContext("/") | |||
.addPlugin(ItUtils.pluginArtifact("batch-plugin")) | |||
.addPlugin(ItUtils.pluginArtifact("batch-plugin")) | |||
// Java is only used in convert_library_into_module test | |||
.setOrchestratorProperty("javaVersion", "LATEST_RELEASE").addPlugin("java") | |||
.build(); | |||
.build(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@@ -195,6 +195,25 @@ public class BatchTest { | |||
"sonar.profile was set to 'unknow' but didn't match any profile for any language. Please check your configuration."); | |||
} | |||
@Test | |||
public void should_honor_sonarUserHome() { | |||
File userHome = temp.getRoot(); | |||
orchestrator.getServer().provisionProject("sample", "xoo-sample"); | |||
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); | |||
SonarRunner runner = configureRunner("shared/xoo-sample", | |||
"sonar.verbose", "true"); | |||
runner.setEnvironmentVariable("SONAR_USER_HOME", "/dev/null"); | |||
BuildResult buildResult = orchestrator.executeBuildQuietly(runner); | |||
assertThat(buildResult.getStatus()).isEqualTo(1); | |||
buildResult = scan("shared/xoo-sample", | |||
"sonar.verbose", "true", | |||
"sonar.userHome", userHome.getAbsolutePath()); | |||
assertThat(buildResult.isSuccess()).isTrue(); | |||
} | |||
@Test | |||
public void should_authenticate_when_needed() { | |||
try { | |||
@@ -351,7 +370,7 @@ public class BatchTest { | |||
// message | |||
.contains("Error message from plugin") | |||
// but not stacktrace | |||
// but not stacktrace | |||
.doesNotContain("at com.sonarsource.RaiseMessageException"); | |||
} | |||
@@ -19,13 +19,20 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.junit.Rule; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.home.cache.FileCache; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class FileCacheProviderTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Test | |||
public void provide() { | |||
FileCacheProvider provider = new FileCacheProvider(); | |||
@@ -44,4 +51,15 @@ public class FileCacheProviderTest { | |||
assertThat(cache1).isSameAs(cache2); | |||
} | |||
@Test | |||
public void honor_sonarUserHome() throws IOException { | |||
FileCacheProvider provider = new FileCacheProvider(); | |||
Settings settings = new Settings(); | |||
File f = temp.newFolder(); | |||
settings.appendProperty("sonar.userHome", f.getAbsolutePath()); | |||
FileCache cache = provider.provide(settings); | |||
assertThat(cache.getDir()).isEqualTo(new File(f, "cache")); | |||
} | |||
} |
@@ -20,12 +20,12 @@ | |||
package org.sonar.home.cache; | |||
import java.io.File; | |||
import javax.annotation.Nullable; | |||
public class FileCacheBuilder { | |||
private final Logger logger; | |||
private File userHome; | |||
private Logger logger; | |||
public FileCacheBuilder(Logger logger) { | |||
this.logger = logger; | |||
@@ -43,14 +43,18 @@ public class FileCacheBuilder { | |||
public FileCache build() { | |||
if (userHome == null) { | |||
String path = System.getenv("SONAR_USER_HOME"); | |||
if (path == null) { | |||
// Default | |||
path = System.getProperty("user.home") + File.separator + ".sonar"; | |||
} | |||
userHome = new File(path); | |||
userHome = findHome(); | |||
} | |||
File cacheDir = new File(userHome, "cache"); | |||
return FileCache.create(cacheDir, logger); | |||
} | |||
private File findHome() { | |||
String path = System.getenv("SONAR_USER_HOME"); | |||
if (path == null) { | |||
// Default | |||
path = System.getProperty("user.home") + File.separator + ".sonar"; | |||
} | |||
return new File(path); | |||
} | |||
} |