aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>2023-10-05 17:06:41 +0200
committersonartech <sonartech@sonarsource.com>2023-10-10 20:02:44 +0000
commit9ff811fd2d3421731dfb4097e8748cee1553d2c5 (patch)
tree45d4866bd21131d61def4f67536433aaade279c2 /server/sonar-server-common
parent047d3846d5e415786323625cd5101a9d54b04725 (diff)
downloadsonarqube-9ff811fd2d3421731dfb4097e8748cee1553d2c5.tar.gz
sonarqube-9ff811fd2d3421731dfb4097e8748cee1553d2c5.zip
SONAR-20548 added event for changing the CCT data for rules
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/PluginRuleUpdate.java85
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/PluginRuleUpdateTest.java48
2 files changed, 133 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/PluginRuleUpdate.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/PluginRuleUpdate.java
new file mode 100644
index 00000000000..762ac0bed57
--- /dev/null
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/PluginRuleUpdate.java
@@ -0,0 +1,85 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.rule;
+
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.api.issue.impact.Severity;
+import org.sonar.api.issue.impact.SoftwareQuality;
+import org.sonar.api.rules.CleanCodeAttribute;
+
+/**
+ * Represents a single update of a single rule done by new version of plugins at startup
+ */
+public class PluginRuleUpdate {
+
+ private String ruleUuid;
+
+ private CleanCodeAttribute newCleanCodeAttribute;
+ private CleanCodeAttribute oldCleanCodeAttribute;
+ private final Map<SoftwareQuality, Severity> newImpacts = new EnumMap<>(SoftwareQuality.class);
+ private final Map<SoftwareQuality, Severity> oldImpacts = new EnumMap<>(SoftwareQuality.class);
+
+ public String getRuleUuid() {
+ return ruleUuid;
+ }
+
+ public void setRuleUuid(String ruleUuid) {
+ this.ruleUuid = ruleUuid;
+ }
+
+ public void addOldImpact(SoftwareQuality softwareQuality, Severity severity) {
+ oldImpacts.put(softwareQuality, severity);
+ }
+
+ public void addNewImpact(SoftwareQuality softwareQuality, Severity severity) {
+ newImpacts.put(softwareQuality, severity);
+ }
+
+ public Map<SoftwareQuality, Severity> getNewImpacts() {
+ return newImpacts;
+ }
+
+ public Map<SoftwareQuality, Severity> getOldImpacts() {
+ return oldImpacts;
+ }
+
+ public List<SoftwareQuality> getMatchingSoftwareQualities() {
+ return newImpacts.keySet().stream().filter(oldImpacts::containsKey).toList();
+ }
+
+ public CleanCodeAttribute getNewCleanCodeAttribute() {
+ return newCleanCodeAttribute;
+ }
+
+ public void setNewCleanCodeAttribute(@Nullable CleanCodeAttribute newCleanCodeAttribute) {
+ this.newCleanCodeAttribute = newCleanCodeAttribute;
+ }
+
+ public CleanCodeAttribute getOldCleanCodeAttribute() {
+ return oldCleanCodeAttribute;
+ }
+
+ public void setOldCleanCodeAttribute(@Nullable CleanCodeAttribute oldCleanCodeAttribute) {
+ this.oldCleanCodeAttribute = oldCleanCodeAttribute;
+ }
+}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/PluginRuleUpdateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/PluginRuleUpdateTest.java
new file mode 100644
index 00000000000..c44bcc2e07c
--- /dev/null
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/PluginRuleUpdateTest.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.server.rule;
+
+import org.junit.Test;
+import org.sonar.api.issue.impact.Severity;
+import org.sonar.api.issue.impact.SoftwareQuality;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PluginRuleUpdateTest {
+
+ @Test
+ public void addOldImpact_whenOldImpactAdded_shouldContainOneImpact() {
+ PluginRuleUpdate pluginRuleUpdate = new PluginRuleUpdate();
+
+ pluginRuleUpdate.addOldImpact(SoftwareQuality.RELIABILITY, Severity.LOW);
+
+ assertThat(pluginRuleUpdate.getOldImpacts()).hasSize(1);
+ }
+
+ @Test
+ public void addNewImpact_whenNewImpactAdded_shouldContainOneImpact() {
+ PluginRuleUpdate pluginRuleUpdate = new PluginRuleUpdate();
+
+ pluginRuleUpdate.addNewImpact(SoftwareQuality.RELIABILITY, Severity.LOW);
+
+ assertThat(pluginRuleUpdate.getNewImpacts()).hasSize(1);
+ }
+
+}