]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16395 Activate Analyzers Cache by default
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 20 May 2022 08:55:22 +0000 (10:55 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 24 May 2022 20:10:13 +0000 (20:10 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoader.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheEnabledTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java

index b93150ae944a768d97731e8370065f5ae3a1e4c8..3333c7673100c598ed44ee749288a3c5d4249b3c 100644 (file)
@@ -30,6 +30,6 @@ public class AnalysisCacheEnabled {
   }
 
   public boolean isEnabled() {
-    return configuration.getBoolean(PROP_KEY).orElse(false);
+    return configuration.getBoolean(PROP_KEY).orElse(true);
   }
 }
index 4832bd774b0f4d5f7673f01264c7c7622ccc9ba0..b44d2dd9cecacb1a62c2e09c01d310b62747fef7 100644 (file)
  */
 package org.sonar.scanner.cache;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.Optional;
-import java.util.zip.InflaterInputStream;
-import org.sonar.api.scanner.fs.InputProject;
-import org.sonar.api.utils.MessageException;
-import org.sonar.core.util.Protobuf;
-import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
 import org.sonar.scanner.protocol.internal.ScannerInternal;
-import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg;
-import org.sonar.scanner.scan.branch.BranchConfiguration;
-import org.sonar.scanner.scan.branch.BranchType;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.HttpException;
-import org.sonarqube.ws.client.WsResponse;
 
-/**
- * Loads plugin cache into the local storage
- */
-public class AnalysisCacheLoader {
-  static final String CONTENT_ENCODING = "Content-Encoding";
-  static final String ACCEPT_ENCODING = "Accept-Encoding";
-  private static final String URL = "api/analysis_cache/get";
-
-  private final DefaultScannerWsClient wsClient;
-  private final InputProject project;
-  private final BranchConfiguration branchConfiguration;
-
-  public AnalysisCacheLoader(DefaultScannerWsClient wsClient, InputProject project, BranchConfiguration branchConfiguration) {
-    this.project = project;
-    this.branchConfiguration = branchConfiguration;
-    this.wsClient = wsClient;
-  }
-
-  public Optional<AnalysisCacheMsg> load() {
-    String url = URL + "?project=" + project.key();
-    if (branchConfiguration.referenceBranchName() != null) {
-      url = url + "&branch=" + branchConfiguration.referenceBranchName();
-    }
-
-    GetRequest request = new GetRequest(url).setHeader(ACCEPT_ENCODING, "gzip");
-
-    try (WsResponse response = wsClient.call(request); InputStream is = response.contentStream()) {
-      Optional<String> contentEncoding = response.header(CONTENT_ENCODING);
-      if (contentEncoding.isPresent() && contentEncoding.get().equals("gzip")) {
-        return Optional.of(decompress(is));
-      } else {
-        return Optional.of(Protobuf.read(is, AnalysisCacheMsg.parser()));
-      }
-    } catch (HttpException e) {
-      if (e.code() == 404) {
-        return Optional.empty();
-      }
-      throw MessageException.of("Failed to download analysis cache: " + DefaultScannerWsClient.createErrorMessage(e));
-    } catch (Exception e) {
-      throw new IllegalStateException("Failed to download analysis cache", e);
-    }
-  }
-
-  private static AnalysisCacheMsg decompress(InputStream is) {
-    try (InflaterInputStream iis = new InflaterInputStream(is)) {
-      return Protobuf.read(iis, ScannerInternal.AnalysisCacheMsg.parser());
-    } catch (IOException e) {
-      throw new IllegalStateException("Failed to decompress analysis cache", e);
-    }
-  }
+public interface AnalysisCacheLoader {
+  Optional<ScannerInternal.AnalysisCacheMsg> load();
 }
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoader.java
new file mode 100644 (file)
index 0000000..7e04a91
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+import java.util.zip.InflaterInputStream;
+import org.sonar.api.scanner.fs.InputProject;
+import org.sonar.api.utils.MessageException;
+import org.sonar.core.util.Protobuf;
+import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
+import org.sonar.scanner.protocol.internal.ScannerInternal;
+import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.HttpException;
+import org.sonarqube.ws.client.WsResponse;
+
+/**
+ * Loads plugin cache into the local storage
+ */
+public class DefaultAnalysisCacheLoader implements AnalysisCacheLoader {
+  static final String CONTENT_ENCODING = "Content-Encoding";
+  static final String ACCEPT_ENCODING = "Accept-Encoding";
+  private static final String URL = "api/analysis_cache/get";
+
+  private final DefaultScannerWsClient wsClient;
+  private final InputProject project;
+  private final BranchConfiguration branchConfiguration;
+
+  public DefaultAnalysisCacheLoader(DefaultScannerWsClient wsClient, InputProject project, BranchConfiguration branchConfiguration) {
+    this.project = project;
+    this.branchConfiguration = branchConfiguration;
+    this.wsClient = wsClient;
+  }
+
+  @Override public Optional<AnalysisCacheMsg> load() {
+    String url = URL + "?project=" + project.key();
+    if (branchConfiguration.referenceBranchName() != null) {
+      url = url + "&branch=" + branchConfiguration.referenceBranchName();
+    }
+
+    GetRequest request = new GetRequest(url).setHeader(ACCEPT_ENCODING, "gzip");
+
+    try (WsResponse response = wsClient.call(request); InputStream is = response.contentStream()) {
+      Optional<String> contentEncoding = response.header(CONTENT_ENCODING);
+      if (contentEncoding.isPresent() && contentEncoding.get().equals("gzip")) {
+        return Optional.of(decompress(is));
+      } else {
+        return Optional.of(Protobuf.read(is, AnalysisCacheMsg.parser()));
+      }
+    } catch (HttpException e) {
+      if (e.code() == 404) {
+        return Optional.empty();
+      }
+      throw MessageException.of("Failed to download analysis cache: " + DefaultScannerWsClient.createErrorMessage(e));
+    } catch (Exception e) {
+      throw new IllegalStateException("Failed to download analysis cache", e);
+    }
+  }
+
+  private static AnalysisCacheMsg decompress(InputStream is) {
+    try (InflaterInputStream iis = new InflaterInputStream(is)) {
+      return Protobuf.read(iis, ScannerInternal.AnalysisCacheMsg.parser());
+    } catch (IOException e) {
+      throw new IllegalStateException("Failed to decompress analysis cache", e);
+    }
+  }
+}
index da491cf9f5ab772da69e6707691485908f781486..aebe65007de36d117d47b26df94bf2f9e147ee57 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.scanner.bootstrap.ExtensionMatcher;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.PostJobExtensionDictionary;
 import org.sonar.scanner.cache.AnalysisCacheEnabled;
-import org.sonar.scanner.cache.AnalysisCacheLoader;
+import org.sonar.scanner.cache.DefaultAnalysisCacheLoader;
 import org.sonar.scanner.cache.AnalysisCacheMemoryStorage;
 import org.sonar.scanner.cache.AnalysisCacheProvider;
 import org.sonar.scanner.ci.CiConfigurationProvider;
@@ -232,7 +232,7 @@ public class SpringProjectScanContainer extends SpringComponentContainer {
       // Plugin cache
       AnalysisCacheProvider.class,
       AnalysisCacheMemoryStorage.class,
-      AnalysisCacheLoader.class,
+      DefaultAnalysisCacheLoader.class,
 
       // Report
       ReferenceBranchSupplier.class,
index a4877298d3eee142c4d02dd5380be6ba4326c3b3..52c0a870f07fe46b2db4bb8c681f2c9432963c12 100644 (file)
@@ -33,13 +33,13 @@ public class AnalysisCacheEnabledTest {
   private final AnalysisCacheEnabled analysisCacheEnabled = new AnalysisCacheEnabled(configuration);
 
   @Test
-  public void disabled_unless_property_set() {
-    assertThat(analysisCacheEnabled.isEnabled()).isFalse();
+  public void enabled_by_default() {
+    assertThat(analysisCacheEnabled.isEnabled()).isTrue();
   }
 
   @Test
-  public void enabled_if_property_set() {
-    when(configuration.getBoolean(PROP_KEY)).thenReturn(Optional.of(true));
-    assertThat(analysisCacheEnabled.isEnabled()).isTrue();
+  public void disabled_if_property_set() {
+    when(configuration.getBoolean(PROP_KEY)).thenReturn(Optional.of(false));
+    assertThat(analysisCacheEnabled.isEnabled()).isFalse();
   }
 }
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java
deleted file mode 100644 (file)
index 393cd5e..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.cache;
-
-import com.google.protobuf.ByteString;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Optional;
-import java.util.zip.DeflaterInputStream;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.sonar.api.scanner.fs.InputProject;
-import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
-import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg;
-import org.sonar.scanner.scan.branch.BranchConfiguration;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.HttpException;
-import org.sonarqube.ws.client.WsResponse;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.sonar.scanner.cache.AnalysisCacheLoader.CONTENT_ENCODING;
-
-public class AnalysisCacheLoaderTest {
-  private final static AnalysisCacheMsg MSG = AnalysisCacheMsg.newBuilder()
-    .putMap("key", ByteString.copyFrom("value", StandardCharsets.UTF_8))
-    .build();
-  private final WsResponse response = mock(WsResponse.class);
-  private final DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
-  private final InputProject project = mock(InputProject.class);
-  private final BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
-  private final AnalysisCacheLoader loader = new AnalysisCacheLoader(wsClient, project, branchConfiguration);
-
-  @Before
-  public void before() {
-    when(project.key()).thenReturn("myproject");
-    when(wsClient.call(any(GetRequest.class))).thenReturn(response);
-  }
-
-  @Test
-  public void loads_content() throws IOException {
-    setResponse(MSG);
-    AnalysisCacheMsg msg = loader.load().get();
-    assertThat(msg).isEqualTo(MSG);
-    assertRequestPath("api/analysis_cache/get?project=myproject");
-  }
-
-  @Test
-  public void loads_content_for_branch() throws IOException {
-    when(branchConfiguration.referenceBranchName()).thenReturn("name");
-
-    setResponse(MSG);
-    AnalysisCacheMsg msg = loader.load().get();
-
-    assertThat(msg).isEqualTo(MSG);
-    assertRequestPath("api/analysis_cache/get?project=myproject&branch=name");
-  }
-
-  @Test
-  public void loads_compressed_content() throws IOException {
-    setCompressedResponse(MSG);
-    AnalysisCacheMsg msg = loader.load().get();
-    assertThat(msg).isEqualTo(MSG);
-  }
-
-  @Test
-  public void returns_empty_if_404() {
-    when(wsClient.call(any(GetRequest.class))).thenThrow(new HttpException("url", 404, "content"));
-    assertThat(loader.load()).isEmpty();
-  }
-
-  @Test
-  public void throw_error_if_http_exception_not_404() {
-    when(wsClient.call(any(GetRequest.class))).thenThrow(new HttpException("url", 401, "content"));
-    assertThatThrownBy(loader::load)
-      .isInstanceOf(MessageException.class)
-      .hasMessage("Failed to download analysis cache: HTTP code 401: content");
-  }
-
-  @Test
-  public void throw_error_if_cant_decompress_content() {
-    setInvalidCompressedResponse();
-    assertThatThrownBy(loader::load)
-      .isInstanceOf(IllegalStateException.class)
-      .hasMessage("Failed to download analysis cache");
-  }
-
-  private void assertRequestPath(String expectedPath) {
-    ArgumentCaptor<GetRequest> requestCaptor = ArgumentCaptor.forClass(GetRequest.class);
-    verify(wsClient).call(requestCaptor.capture());
-    assertThat(requestCaptor.getValue().getPath()).isEqualTo(expectedPath);
-  }
-
-  private void setResponse(AnalysisCacheMsg msg) throws IOException {
-    when(response.contentStream()).thenReturn(createInputStream(msg));
-  }
-
-  private void setCompressedResponse(AnalysisCacheMsg msg) throws IOException {
-    when(response.contentStream()).thenReturn(new DeflaterInputStream(createInputStream(msg)));
-    when(response.header(CONTENT_ENCODING)).thenReturn(Optional.of("gzip"));
-  }
-
-  private void setInvalidCompressedResponse() {
-    when(response.contentStream()).thenReturn(new ByteArrayInputStream(new byte[] {1, 2, 3}));
-    when(response.header(CONTENT_ENCODING)).thenReturn(Optional.of("gzip"));
-  }
-
-  private InputStream createInputStream(AnalysisCacheMsg analysisCacheMsg) throws IOException {
-    ByteArrayOutputStream serialized = new ByteArrayOutputStream(analysisCacheMsg.getSerializedSize());
-    analysisCacheMsg.writeTo(serialized);
-    return new ByteArrayInputStream(serialized.toByteArray());
-  }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoaderTest.java
new file mode 100644 (file)
index 0000000..be8ad55
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import com.google.protobuf.ByteString;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+import java.util.zip.DeflaterInputStream;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.api.scanner.fs.InputProject;
+import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
+import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.HttpException;
+import org.sonarqube.ws.client.WsResponse;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.scanner.cache.DefaultAnalysisCacheLoader.CONTENT_ENCODING;
+
+public class DefaultAnalysisCacheLoaderTest {
+  private final static AnalysisCacheMsg MSG = AnalysisCacheMsg.newBuilder()
+    .putMap("key", ByteString.copyFrom("value", StandardCharsets.UTF_8))
+    .build();
+  private final WsResponse response = mock(WsResponse.class);
+  private final DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
+  private final InputProject project = mock(InputProject.class);
+  private final BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
+  private final DefaultAnalysisCacheLoader loader = new DefaultAnalysisCacheLoader(wsClient, project, branchConfiguration);
+
+  @Before
+  public void before() {
+    when(project.key()).thenReturn("myproject");
+    when(wsClient.call(any(GetRequest.class))).thenReturn(response);
+  }
+
+  @Test
+  public void loads_content() throws IOException {
+    setResponse(MSG);
+    AnalysisCacheMsg msg = loader.load().get();
+    assertThat(msg).isEqualTo(MSG);
+    assertRequestPath("api/analysis_cache/get?project=myproject");
+  }
+
+  @Test
+  public void loads_content_for_branch() throws IOException {
+    when(branchConfiguration.referenceBranchName()).thenReturn("name");
+
+    setResponse(MSG);
+    AnalysisCacheMsg msg = loader.load().get();
+
+    assertThat(msg).isEqualTo(MSG);
+    assertRequestPath("api/analysis_cache/get?project=myproject&branch=name");
+  }
+
+  @Test
+  public void loads_compressed_content() throws IOException {
+    setCompressedResponse(MSG);
+    AnalysisCacheMsg msg = loader.load().get();
+    assertThat(msg).isEqualTo(MSG);
+  }
+
+  @Test
+  public void returns_empty_if_404() {
+    when(wsClient.call(any(GetRequest.class))).thenThrow(new HttpException("url", 404, "content"));
+    assertThat(loader.load()).isEmpty();
+  }
+
+  @Test
+  public void throw_error_if_http_exception_not_404() {
+    when(wsClient.call(any(GetRequest.class))).thenThrow(new HttpException("url", 401, "content"));
+    assertThatThrownBy(loader::load)
+      .isInstanceOf(MessageException.class)
+      .hasMessage("Failed to download analysis cache: HTTP code 401: content");
+  }
+
+  @Test
+  public void throw_error_if_cant_decompress_content() {
+    setInvalidCompressedResponse();
+    assertThatThrownBy(loader::load)
+      .isInstanceOf(IllegalStateException.class)
+      .hasMessage("Failed to download analysis cache");
+  }
+
+  private void assertRequestPath(String expectedPath) {
+    ArgumentCaptor<GetRequest> requestCaptor = ArgumentCaptor.forClass(GetRequest.class);
+    verify(wsClient).call(requestCaptor.capture());
+    assertThat(requestCaptor.getValue().getPath()).isEqualTo(expectedPath);
+  }
+
+  private void setResponse(AnalysisCacheMsg msg) throws IOException {
+    when(response.contentStream()).thenReturn(createInputStream(msg));
+  }
+
+  private void setCompressedResponse(AnalysisCacheMsg msg) throws IOException {
+    when(response.contentStream()).thenReturn(new DeflaterInputStream(createInputStream(msg)));
+    when(response.header(CONTENT_ENCODING)).thenReturn(Optional.of("gzip"));
+  }
+
+  private void setInvalidCompressedResponse() {
+    when(response.contentStream()).thenReturn(new ByteArrayInputStream(new byte[] {1, 2, 3}));
+    when(response.header(CONTENT_ENCODING)).thenReturn(Optional.of("gzip"));
+  }
+
+  private InputStream createInputStream(AnalysisCacheMsg analysisCacheMsg) throws IOException {
+    ByteArrayOutputStream serialized = new ByteArrayOutputStream(analysisCacheMsg.getSerializedSize());
+    analysisCacheMsg.writeTo(serialized);
+    return new ByteArrayInputStream(serialized.toByteArray());
+  }
+}
index d560991ad50260aac3603f5674933e05a8f59290..e694c35a70275cc02652bd8d1b677930291fb0c9 100644 (file)
@@ -33,6 +33,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -45,6 +46,7 @@ import org.sonar.api.SonarProduct;
 import org.sonar.api.SonarQubeSide;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.batch.rule.LoadedActiveRule;
+import org.sonar.api.batch.sensor.cache.ReadCache;
 import org.sonar.api.impl.server.RulesDefinitionContext;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Metric;
@@ -57,6 +59,10 @@ import org.sonar.batch.bootstrapper.Batch;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
 import org.sonar.batch.bootstrapper.LogOutput;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.cache.AnalysisCacheLoader;
+import org.sonar.scanner.cache.AnalysisCacheMemoryStorage;
+import org.sonar.scanner.cache.ReadCacheImpl;
+import org.sonar.scanner.protocol.internal.ScannerInternal;
 import org.sonar.scanner.report.CeTaskReportDataHolder;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.repository.MetricsRepository;
@@ -79,6 +85,7 @@ import org.sonar.scanner.scan.branch.ProjectPullRequests;
 import org.sonarqube.ws.NewCodePeriods;
 import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 import org.sonarqube.ws.Rules.ListResponse.Rule;
+import org.springframework.context.annotation.Bean;
 
 import static java.util.Collections.emptySet;
 
@@ -97,6 +104,7 @@ public class ScannerMediumTester extends ExternalResource {
   private final FakeGlobalSettingsLoader globalSettingsLoader = new FakeGlobalSettingsLoader();
   private final FakeProjectSettingsLoader projectSettingsLoader = new FakeProjectSettingsLoader();
   private final FakeNewCodePeriodLoader newCodePeriodLoader = new FakeNewCodePeriodLoader();
+  private final FakeAnalysisCacheLoader analysisCacheLoader = new FakeAnalysisCacheLoader();
   private final FakeRulesLoader rulesLoader = new FakeRulesLoader();
   private final FakeQualityProfileLoader qualityProfiles = new FakeQualityProfileLoader();
   private final FakeActiveRulesLoader activeRules = new FakeActiveRulesLoader();
@@ -307,6 +315,7 @@ public class ScannerMediumTester extends ExternalResource {
           tester.globalSettingsLoader,
           tester.projectSettingsLoader,
           tester.newCodePeriodLoader,
+          tester.analysisCacheLoader,
           tester.sonarRuntime,
           tester.reportMetadataHolder,
           result)
@@ -518,6 +527,14 @@ public class ScannerMediumTester extends ExternalResource {
     }
   }
 
+  @Priority(1)
+  private static class FakeAnalysisCacheLoader implements AnalysisCacheLoader {
+    @Override
+    public Optional<ScannerInternal.AnalysisCacheMsg> load() {
+      return Optional.empty();
+    }
+  }
+
   @Priority(1)
   private static class FakeGlobalSettingsLoader implements GlobalSettingsLoader {