aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2024-10-09 15:09:39 +0200
committersonartech <sonartech@sonarsource.com>2024-10-11 20:02:42 +0000
commit3f0a34901c55eb1e204fe4028d2773f8484b513f (patch)
treee79565fd2126baf3711a545619470dd2f44d2598 /sonar-plugin-api-impl
parent8859ed6887ec1e2eb3e86a11b98b73b5b8606710 (diff)
downloadsonarqube-3f0a34901c55eb1e204fe4028d2773f8484b513f.tar.gz
sonarqube-3f0a34901c55eb1e204fe4028d2773f8484b513f.zip
SONAR-23327 Implement addTelemetryProperty in the scanner engine
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/InMemorySensorStorage.java10
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java5
2 files changed, 13 insertions, 2 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/InMemorySensorStorage.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/InMemorySensorStorage.java
index de7add875be..0b4d729aee8 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/InMemorySensorStorage.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/InMemorySensorStorage.java
@@ -57,6 +57,7 @@ class InMemorySensorStorage implements SensorStorage {
Map<String, List<DefaultCoverage>> coverageByComponent = new HashMap<>();
Map<String, DefaultSymbolTable> symbolsPerComponent = new HashMap<>();
Map<String, String> contextProperties = new HashMap<>();
+ Map<String, String> telemetryEntries = new HashMap<>();
Map<String, DefaultSignificantCode> significantCodePerComponent = new HashMap<>();
@Override
@@ -132,6 +133,15 @@ class InMemorySensorStorage implements SensorStorage {
contextProperties.put(key, value);
}
+ public void storeTelemetry(String key, String value) {
+ checkArgument(key != null, "Key of context property must not be null");
+ checkArgument(value != null, "Value of context property must not be null");
+
+ if (telemetryEntries.size() < 1000 || telemetryEntries.containsKey(key)) {
+ telemetryEntries.put(key, value);
+ }
+ }
+
@Override
public void store(ExternalIssue issue) {
allExternalIssues.add(issue);
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
index ca8aae07c0f..c94a0ccaff0 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
@@ -442,8 +442,9 @@ public class SensorContextTester implements SensorContext {
}
@Override
- public void addTelemetryProperty(String s, String s1) {
- throw new UnsupportedOperationException("addTelemetryProperty");
+ public void addTelemetryProperty(String key, String value) {
+ //No Need to check the source of the plugin in the tester
+ sensorStorage.storeTelemetry(key, value);
}
public void setCacheEnabled(boolean enabled) {