aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/main
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-03-14 11:27:18 -0500
committersonartech <sonartech@sonarsource.com>2022-03-18 20:02:57 +0000
commit1269984e8e09338c057d068d715ade7df5a0c354 (patch)
treeb483c992fd8c57b79188c936fb9bfb6ff7955ed8 /sonar-scanner-protocol/src/main
parente987de516356fe37ee8eb35793d5fd709e2a099b (diff)
downloadsonarqube-1269984e8e09338c057d068d715ade7df5a0c354.tar.gz
sonarqube-1269984e8e09338c057d068d715ade7df5a0c354.zip
SONAR-16115 Store plugin's scanner cache in SonarQube
Diffstat (limited to 'sonar-scanner-protocol/src/main')
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java4
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java17
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java7
-rw-r--r--sonar-scanner-protocol/src/main/protobuf/scanner_internal.proto8
4 files changed, 36 insertions, 0 deletions
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java
index a7bafb3e307..041bf6cbeff 100644
--- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java
+++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java
@@ -66,6 +66,10 @@ public class FileStructure {
return new File(dir, "metadata.pb");
}
+ public File pluginCache() {
+ return new File(dir, "plugin-cache.pb");
+ }
+
public File analysisLog() {
return new File(dir, "analysis.log");
}
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java
index 8ebb7b623f1..aaa0190a802 100644
--- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java
+++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java
@@ -19,7 +19,11 @@
*/
package org.sonar.scanner.protocol.output;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import javax.annotation.CheckForNull;
import org.sonar.core.util.CloseableIterator;
import org.sonar.core.util.Protobuf;
@@ -75,6 +79,19 @@ public class ScannerReportReader {
return null;
}
+ @CheckForNull
+ public InputStream getPluginCache() {
+ File file = fileStructure.pluginCache();
+ if (fileExists(file)) {
+ try {
+ return new BufferedInputStream(new FileInputStream(fileStructure.pluginCache()));
+ } catch (FileNotFoundException e) {
+ throw new IllegalStateException("Unable to open file " + fileStructure.pluginCache(), e);
+ }
+ }
+ return null;
+ }
+
public ScannerReport.Component readComponent(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, componentRef);
if (!fileExists(file)) {
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java
index 3ae3fa517db..88f16d14d19 100644
--- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java
+++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java
@@ -26,6 +26,7 @@ import java.io.OutputStream;
import javax.annotation.concurrent.Immutable;
import org.sonar.core.util.ContextException;
import org.sonar.core.util.Protobuf;
+import org.sonar.scanner.protocol.internal.ScannerInternal;
@Immutable
public class ScannerReportWriter {
@@ -94,6 +95,12 @@ public class ScannerReportWriter {
return file;
}
+ public File writePluginCache(ScannerInternal.PluginCacheMsg cacheMsg) {
+ File file = fileStructure.pluginCache();
+ Protobuf.writeGzip(cacheMsg, file);
+ return file;
+ }
+
public void appendComponentExternalIssue(int componentRef, ScannerReport.ExternalIssue issue) {
File file = fileStructure.fileFor(FileStructure.Domain.EXTERNAL_ISSUES, componentRef);
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file, true))) {
diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_internal.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_internal.proto
new file mode 100644
index 00000000000..b0d38058c4c
--- /dev/null
+++ b/sonar-scanner-protocol/src/main/protobuf/scanner_internal.proto
@@ -0,0 +1,8 @@
+syntax = "proto3";
+
+option java_package = "org.sonar.scanner.protocol.internal";
+option optimize_for = SPEED;
+
+message PluginCacheMsg {
+ map<string, bytes> map = 1;
+}