Browse Source

SONARUNNER-91 SonarQube Runner should honor sonar.userHome

tags/2.5-rc1
Duarte Meneses 8 years ago
parent
commit
08e5054fa2

+ 1
- 1
it/src/test/java/com/sonar/runner/it/CacheTest.java View File

@@ -84,7 +84,7 @@ public class CacheTest extends RunnerTestCase {
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");
}
}


+ 6
- 1
sonar-runner-api/src/main/java/org/sonar/runner/impl/IsolatedLauncherFactory.java View File

@@ -20,6 +20,7 @@
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;
@@ -51,6 +52,10 @@ public class IsolatedLauncherFactory {

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

@@ -70,7 +75,7 @@ public class IsolatedLauncherFactory {
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);
}

+ 6
- 2
sonar-runner-api/src/main/java/org/sonar/runner/impl/JarDownloader.java View File

@@ -21,18 +21,22 @@ package org.sonar.runner.impl;

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

+ 13
- 2
sonar-runner-api/src/main/java/org/sonar/runner/impl/Jars.java View File

@@ -23,6 +23,8 @@ import java.io.File;
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;
@@ -36,9 +38,11 @@ class Jars {
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;
}
@@ -53,6 +57,13 @@ class Jars {
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...");

+ 1
- 1
sonar-runner-api/src/main/java/org/sonar/runner/impl/ServerConnection.java View File

@@ -161,7 +161,7 @@ class ServerConnection {
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);

+ 1
- 1
sonar-runner-api/src/test/java/org/sonar/runner/impl/JarDownloaderTest.java View File

@@ -35,7 +35,7 @@ public class JarDownloaderTest {

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() {

+ 12
- 2
sonar-runner-api/src/test/java/org/sonar/runner/impl/JarsTest.java View File

@@ -20,13 +20,15 @@
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;
@@ -38,7 +40,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

public class JarsTest {

ServerConnection connection = mock(ServerConnection.class);
JarExtractor jarExtractor = mock(JarExtractor.class);
FileCache fileCache = mock(FileCache.class);
@@ -66,6 +67,15 @@ public class JarsTest {
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");

Loading…
Cancel
Save