try {
result = orchestrator.executeBuild(build);
} catch (BuildFailureException e) {
- assertThat(e.getResult().getLogs()).contains("Server is not accessible and data is not cached");
+ assertThat(e.getResult().getLogs()).contains("and data is not cached");
}
}
package org.sonar.runner.impl;
import java.io.File;
+import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;
private PersistentCache getCache(Properties props) {
PersistentCacheBuilder builder = new PersistentCacheBuilder(logger);
+ String home = props.getProperty("sonar.userHome");
+ if (home != null) {
+ builder.setSonarHome(Paths.get(home));
+ }
return builder.build();
}
return new SimulatedLauncher(version, logger);
}
ServerConnection serverConnection = ServerConnection.create(props, getCache(props), logger);
- JarDownloader jarDownloader = new JarDownloader(serverConnection, logger);
+ JarDownloader jarDownloader = new JarDownloader(serverConnection, logger, props);
return createLauncher(jarDownloader, rules);
}
import java.io.File;
import java.util.List;
+import java.util.Properties;
+
import org.sonar.home.cache.Logger;
class JarDownloader {
private final ServerConnection serverConnection;
private final Logger logger;
+ private final Properties props;
- JarDownloader(ServerConnection conn, Logger logger) {
+ JarDownloader(ServerConnection conn, Logger logger, Properties props) {
this.serverConnection = conn;
this.logger = logger;
+ this.props = props;
}
List<File> download() {
- return new Jars(serverConnection, new JarExtractor(), logger).download();
+ return new Jars(serverConnection, new JarExtractor(), logger, props).download();
}
}
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
+
import org.sonar.home.cache.FileCache;
import org.sonar.home.cache.FileCacheBuilder;
import org.sonar.home.cache.Logger;
private final JarExtractor jarExtractor;
private final Logger logger;
- Jars(ServerConnection conn, JarExtractor jarExtractor, Logger logger) {
+ Jars(ServerConnection conn, JarExtractor jarExtractor, Logger logger, Properties props) {
this.logger = logger;
- this.fileCache = new FileCacheBuilder(logger).build();
+ this.fileCache = new FileCacheBuilder(logger)
+ .setUserHome(props.getProperty("sonar.userHome"))
+ .build();
this.connection = conn;
this.jarExtractor = jarExtractor;
}
this.jarExtractor = jarExtractor;
}
+ /**
+ * For unit tests
+ */
+ FileCache getFileCache() {
+ return fileCache;
+ }
+
List<File> download() {
List<File> files = new ArrayList<File>();
logger.debug("Extract sonar-runner-batch in temp...");
if (cached != null) {
return cached;
}
- logger.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED + " and had a cache miss", serverUrl));
+ logger.error(MessageFormat.format(SONAR_SERVER_CAN_NOT_BE_REACHED + " and data is not cached", serverUrl));
throw originalException;
} catch (IOException e) {
throw new IllegalStateException("Failed to access cache", e);
ServerConnection serverConnection = mock(ServerConnection.class);
Properties props = new Properties();
- JarDownloader downloader = spy(new JarDownloader(serverConnection, mock(Logger.class)));
+ JarDownloader downloader = spy(new JarDownloader(serverConnection, mock(Logger.class), props));
@Test
public void should_download_jar_files() {
package org.sonar.runner.impl;
import java.io.File;
+import java.io.IOException;
import java.util.List;
+import java.util.Properties;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.home.cache.FileCache;
import org.sonar.home.cache.Logger;
-
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
public class JarsTest {
-
ServerConnection connection = mock(ServerConnection.class);
JarExtractor jarExtractor = mock(JarExtractor.class);
FileCache fileCache = mock(FileCache.class);
verifyNoMoreInteractions(fileCache);
}
+ @Test
+ public void should_honor_sonarUserHome() throws IOException {
+ Properties props = new Properties();
+ File f = temp.newFolder();
+ props.put("sonar.userHome", f.getAbsolutePath());
+ Jars jars = new Jars(connection, jarExtractor, mock(Logger.class), props);
+ assertThat(jars.getFileCache().getDir()).isEqualTo(new File(f, "cache"));
+ }
+
@Test
public void should_fail_to_download_files() throws Exception {
File batchJar = temp.newFile("sonar-runner-batch.jar");