diff --git a/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryLocalStorage.java b/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryLocalStorage.java index d4d060bd3a..1d1632d86f 100644 --- a/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryLocalStorage.java +++ b/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryLocalStorage.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -45,7 +46,7 @@ class TelemetryLocalStorage { private int showHotspotRequestsCount; private int taintVulnerabilitiesInvestigatedLocallyCount; private int taintVulnerabilitiesInvestigatedRemotelyCount; - private final Collection raisedIssuesRules; + private final Set raisedIssuesRules; TelemetryLocalStorage() { enabled = true; @@ -59,8 +60,8 @@ public Collection getRaisedIssuesRules() { return raisedIssuesRules; } - public void addReportedRule(String reportedRule) { - this.raisedIssuesRules.add(reportedRule); + public void addReportedRules(Set reportedRuleKeys) { + this.raisedIssuesRules.addAll(reportedRuleKeys); } @Deprecated diff --git a/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManager.java b/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManager.java index 898cc1edb7..df23bc61fe 100644 --- a/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManager.java +++ b/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManager.java @@ -20,6 +20,7 @@ package org.sonarsource.sonarlint.core.telemetry; import java.nio.file.Path; +import java.util.Set; import javax.annotation.Nullable; import org.sonarsource.sonarlint.core.client.api.common.Language; @@ -119,8 +120,8 @@ public void taintVulnerabilitiesInvestigatedRemotely() { storage.tryUpdateAtomically(TelemetryLocalStorage::incrementTaintVulnerabilitiesInvestigatedRemotelyCount); } - public void addReportedRule(String ruleKey) { - storage.tryUpdateAtomically(s -> s.addReportedRule(ruleKey)); + public void addReportedRules(Set ruleKeys) { + storage.tryUpdateAtomically(s -> s.addReportedRules(ruleKeys)); } /** diff --git a/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManagerTest.java b/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManagerTest.java index 6c1fd0c13c..d2bf97124e 100644 --- a/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManagerTest.java +++ b/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryManagerTest.java @@ -25,7 +25,9 @@ import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; +import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.Optional; import java.util.function.Consumer; import org.junit.Before; @@ -366,7 +368,7 @@ public void uploadLazily_should_clear_accumulated_data() { manager.devNotificationsClicked(FOO_EVENT); manager.taintVulnerabilitiesInvestigatedLocally(); manager.taintVulnerabilitiesInvestigatedRemotely(); - manager.addReportedRule("ruleKey"); + manager.addReportedRules(new HashSet<>(Arrays.asList("ruleKey1", "ruleKey2"))); manager.uploadLazily(); @@ -383,10 +385,11 @@ public void uploadLazily_should_clear_accumulated_data() { public void accumulate_rules_activation_settings_and_reported_rules() { createAndSaveSampleData(storage); - manager.addReportedRule("reportedRule1"); + manager.addReportedRules(new HashSet<>(Arrays.asList("ruleKey1", "ruleKey1", "ruleKey2"))); TelemetryLocalStorage reloaded = storage.tryRead(); - assertThat(reloaded.getRaisedIssuesRules()).containsOnly("reportedRule1"); + assertThat(reloaded.getRaisedIssuesRules()).hasSize(2); + assertThat(reloaded.getRaisedIssuesRules()).contains("ruleKey1", "ruleKey2"); } private void createAndSaveSampleData(TelemetryLocalStorageManager storage) {