aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-05-20 10:55:22 +0200
committersonartech <sonartech@sonarsource.com>2022-05-24 20:10:13 +0000
commit7475e9d7a6e89ebe552e101250518ab67b56531d (patch)
treefc298d165b983f1035594fd4a7f743a9de4c1703 /sonar-scanner-engine/src/main/java/org/sonar
parent7603603aec3c165e4739c8a74282114c49bb08f3 (diff)
downloadsonarqube-7475e9d7a6e89ebe552e101250518ab67b56531d.tar.gz
sonarqube-7475e9d7a6e89ebe552e101250518ab67b56531d.zip
SONAR-16395 Activate Analyzers Cache by default
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java65
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoader.java87
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java4
4 files changed, 92 insertions, 66 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java
index b93150ae944..3333c767310 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheEnabled.java
@@ -30,6 +30,6 @@ public class AnalysisCacheEnabled {
}
public boolean isEnabled() {
- return configuration.getBoolean(PROP_KEY).orElse(false);
+ return configuration.getBoolean(PROP_KEY).orElse(true);
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java
index 4832bd774b0..b44d2dd9cec 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java
@@ -19,70 +19,9 @@
*/
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
index 00000000000..7e04a91c30f
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/DefaultAnalysisCacheLoader.java
@@ -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);
+ }
+ }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
index da491cf9f5a..aebe65007de 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java
@@ -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,