aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java19
2 files changed, 23 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java
index 7ca47ae787a..fc3482a2006 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java
@@ -27,19 +27,20 @@ import org.sonar.batch.cache.WSLoader.LoadStrategy;
import org.sonar.home.cache.PersistentCache;
public class AnalysisWSLoaderProvider extends ProviderAdapter {
+ static final String SONAR_USE_WS_CACHE = "sonar.useWsCache";
private WSLoader wsLoader;
- public WSLoader provide(AnalysisMode mode, PersistentCache cache, BatchWsClient client) {
+ public WSLoader provide(AnalysisMode mode, PersistentCache cache, BatchWsClient client, AnalysisProperties props) {
if (wsLoader == null) {
// recreate cache directory if needed for this analysis
cache.reconfigure();
- wsLoader = new WSLoader(getStrategy(mode), cache, client);
+ wsLoader = new WSLoader(getStrategy(mode, props), cache, client);
}
return wsLoader;
}
- private static LoadStrategy getStrategy(AnalysisMode mode) {
- if (mode.isIssues()) {
+ private static LoadStrategy getStrategy(AnalysisMode mode, AnalysisProperties props) {
+ if (mode.isIssues() && "true".equals(props.property(SONAR_USE_WS_CACHE))) {
return LoadStrategy.CACHE_ONLY;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java
index b175faa6bc6..5aa31bd64d5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.analysis;
+import com.google.common.collect.ImmutableMap;
+import org.assertj.core.util.Maps;
import org.junit.Test;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.batch.bootstrap.BatchWsClient;
@@ -28,6 +30,7 @@ import org.sonar.home.cache.PersistentCache;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class AnalysisWSLoaderProviderTest {
@@ -39,7 +42,21 @@ public class AnalysisWSLoaderProviderTest {
@Test
public void testDefault() {
- WSLoader loader = underTest.provide(mode, cache, wsClient);
+ WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap()));
assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
}
+
+ @Test
+ public void no_cache_by_default_in_issues_mode() {
+ when(mode.isIssues()).thenReturn(true);
+ WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap()));
+ assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
+ }
+
+ @Test
+ public void enable_cache_in_issues_mode() {
+ when(mode.isIssues()).thenReturn(true);
+ WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(ImmutableMap.of(AnalysisWSLoaderProvider.SONAR_USE_WS_CACHE, "true")));
+ assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_ONLY);
+ }
}