]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22951 high_impact_accepted_issues should include blocker severities
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Tue, 24 Sep 2024 14:40:27 +0000 (16:40 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 Sep 2024 20:02:54 +0000 (20:02 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueCounter.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueCounterTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/IssueCounter.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureUpdateFormulaFactoryImplTest.java

index f2e4de123add08c0fae92b0df26e62ae2c31404d..6732c26d0ae1060a52d462d3e46908980e72510d 100644 (file)
@@ -313,7 +313,7 @@ public class IssueCounter extends IssueVisitor {
         falsePositives++;
       } else if (IssueStatus.ACCEPTED.equals(issue.issueStatus())) {
         accepted++;
-        if (issue.impacts().values().stream().anyMatch(severity -> severity == Severity.HIGH)) {
+        if (issue.impacts().values().stream().anyMatch(severity -> severity == Severity.HIGH || severity == Severity.BLOCKER)) {
           highImpactAccepted++;
         }
       }
index f47a6da5495fb475bfe74d4cc01107506fa061a6..e5a460157f3b9b8ea0117b11899b6e3e33dcd545 100644 (file)
@@ -58,6 +58,7 @@ import static org.sonar.api.issue.Issue.STATUS_CONFIRMED;
 import static org.sonar.api.issue.Issue.STATUS_OPEN;
 import static org.sonar.api.issue.Issue.STATUS_RESOLVED;
 import static org.sonar.api.issue.impact.Severity.HIGH;
+import static org.sonar.api.issue.impact.Severity.INFO;
 import static org.sonar.api.issue.impact.Severity.LOW;
 import static org.sonar.api.issue.impact.Severity.MEDIUM;
 import static org.sonar.api.measures.CoreMetrics.ACCEPTED_ISSUES;
@@ -115,7 +116,6 @@ import static org.sonar.api.measures.CoreMetrics.VIOLATIONS;
 import static org.sonar.api.measures.CoreMetrics.VIOLATIONS_KEY;
 import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES;
 import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY;
-import static org.sonar.api.rule.Severity.BLOCKER;
 import static org.sonar.api.rule.Severity.CRITICAL;
 import static org.sonar.api.rule.Severity.MAJOR;
 import static org.sonar.api.rules.RuleType.BUG;
@@ -187,13 +187,13 @@ class IssueCounterTest {
   void count_issues_by_status() {
     // bottom-up traversal -> from files to project
     underTest.beforeComponent(FILE1);
-    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, BLOCKER));
+    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, org.sonar.api.rule.Severity.BLOCKER));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_FIXED, STATUS_CLOSED, MAJOR));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_FALSE_POSITIVE, STATUS_RESOLVED, MAJOR));
     underTest.afterComponent(FILE1);
 
     underTest.beforeComponent(FILE2);
-    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, BLOCKER));
+    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, org.sonar.api.rule.Severity.BLOCKER));
     underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, MAJOR));
     underTest.afterComponent(FILE2);
 
@@ -215,14 +215,14 @@ class IssueCounterTest {
   void count_issues_by_resolution() {
     // bottom-up traversal -> from files to project
     underTest.beforeComponent(FILE1);
-    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, BLOCKER));
+    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, org.sonar.api.rule.Severity.BLOCKER));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_FIXED, STATUS_CLOSED, MAJOR));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_FALSE_POSITIVE, STATUS_RESOLVED, MAJOR));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_WONT_FIX, STATUS_RESOLVED, MAJOR));
     underTest.afterComponent(FILE1);
 
     underTest.beforeComponent(FILE2);
-    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, BLOCKER));
+    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, org.sonar.api.rule.Severity.BLOCKER));
     underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, MAJOR));
     underTest.onIssue(FILE2, createIssue(RESOLUTION_WONT_FIX, STATUS_RESOLVED, MAJOR));
     underTest.afterComponent(FILE2);
@@ -245,13 +245,13 @@ class IssueCounterTest {
   void count_unresolved_issues_by_severity() {
     // bottom-up traversal -> from files to project
     underTest.beforeComponent(FILE1);
-    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, BLOCKER));
+    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, org.sonar.api.rule.Severity.BLOCKER));
     // this resolved issue is ignored
     underTest.onIssue(FILE1, createIssue(RESOLUTION_FIXED, STATUS_CLOSED, MAJOR));
     underTest.afterComponent(FILE1);
 
     underTest.beforeComponent(FILE2);
-    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, BLOCKER));
+    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, org.sonar.api.rule.Severity.BLOCKER));
     underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, MAJOR));
     underTest.afterComponent(FILE2);
 
@@ -270,13 +270,13 @@ class IssueCounterTest {
     // bottom-up traversal -> from files to project
     // file1 : one open code smell, one closed code smell (which will be excluded from metric)
     underTest.beforeComponent(FILE1);
-    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, BLOCKER).setType(CODE_SMELL));
+    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, org.sonar.api.rule.Severity.BLOCKER).setType(CODE_SMELL));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_FIXED, STATUS_CLOSED, MAJOR).setType(CODE_SMELL));
     underTest.afterComponent(FILE1);
 
     // file2 : one bug
     underTest.beforeComponent(FILE2);
-    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, BLOCKER).setType(BUG));
+    underTest.onIssue(FILE2, createIssue(null, STATUS_CONFIRMED, org.sonar.api.rule.Severity.BLOCKER).setType(BUG));
     underTest.afterComponent(FILE2);
 
     // file3 : one unresolved security hotspot
@@ -300,8 +300,8 @@ class IssueCounterTest {
 
     underTest.beforeComponent(FILE1);
     // created before -> existing issues (so ignored)
-    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, BLOCKER).setType(CODE_SMELL));
-    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, BLOCKER).setType(BUG));
+    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, org.sonar.api.rule.Severity.BLOCKER).setType(CODE_SMELL));
+    underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, org.sonar.api.rule.Severity.BLOCKER).setType(BUG));
 
     // created after -> 4 new issues but 1 is closed
     underTest.onIssue(FILE1, createNewIssue(null, STATUS_OPEN, CRITICAL).setType(CODE_SMELL));
@@ -421,7 +421,7 @@ class IssueCounterTest {
 
   private static Map<String, Long> getImpactMeasure(long total, long high, long medium, long low, long info, long blocker) {
     Map<String, Long> map = getImpactMeasure(total, high, medium, low);
-    map.put(Severity.INFO.name(), info);
+    map.put(INFO.name(), info);
     map.put(Severity.BLOCKER.name(), blocker);
     return map;
   }
@@ -452,9 +452,10 @@ class IssueCounterTest {
     when(newIssueClassifier.isEnabled()).thenReturn(true);
 
     underTest.beforeComponent(FILE1);
-    // created before -> existing issues with 1 high impact accepted
+    // created before -> existing issues with 2 high impact accepted (High and Blocker)
     underTest.onIssue(FILE1, createIssue(null, STATUS_OPEN, HIGH));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_WONT_FIX, STATUS_RESOLVED, HIGH));
+    underTest.onIssue(FILE1, createIssue(RESOLUTION_WONT_FIX, STATUS_RESOLVED, Severity.BLOCKER));
     underTest.onIssue(FILE1, createIssue(RESOLUTION_WONT_FIX, STATUS_RESOLVED, MEDIUM));
 
     // created after -> 2 high impact accepted
@@ -469,9 +470,9 @@ class IssueCounterTest {
     underTest.afterComponent(PROJECT);
 
     assertIntValue(FILE1, entry(VIOLATIONS_KEY, 2), entry(NEW_VIOLATIONS_KEY, 1), entry(NEW_ACCEPTED_ISSUES_KEY, 3),
-      entry(HIGH_IMPACT_ACCEPTED_ISSUES_KEY, 3));
+      entry(HIGH_IMPACT_ACCEPTED_ISSUES_KEY, 4));
     assertIntValue(PROJECT, entry(VIOLATIONS_KEY, 2), entry(NEW_VIOLATIONS_KEY, 1), entry(NEW_ACCEPTED_ISSUES_KEY, 3),
-      entry(HIGH_IMPACT_ACCEPTED_ISSUES_KEY, 3));
+      entry(HIGH_IMPACT_ACCEPTED_ISSUES_KEY, 4));
   }
 
   @Test
@@ -510,7 +511,7 @@ class IssueCounterTest {
     // created after, but closed
     underTest.onIssue(FILE1, createNewSecurityHotspot().setStatus(STATUS_RESOLVED).setResolution(RESOLUTION_WONT_FIX));
 
-    for (String severity : Arrays.asList(CRITICAL, BLOCKER, MAJOR)) {
+    for (String severity : Arrays.asList(CRITICAL, org.sonar.api.rule.Severity.BLOCKER, MAJOR)) {
       DefaultIssue issue = createNewSecurityHotspot();
       issue.setSeverity(severity);
       underTest.onIssue(FILE1, issue);
index c7c0fbb34ecc92d425b82457cfa0e7d1b4452cca..d148936d19224a76f4e0daad9c3feb4ef66e3481 100644 (file)
@@ -130,7 +130,7 @@ class IssueCounter {
         .add(group);
     }
 
-    if (Severity.HIGH == group.getSeverity() && IssueStatus.ACCEPTED == issueStatus) {
+    if ((Severity.HIGH == group.getSeverity() || Severity.BLOCKER == group.getSeverity()) && IssueStatus.ACCEPTED == issueStatus) {
       highImpactAccepted.add(group);
     }
   }
index 8d8d29c8a9eee7d5d6caa4c4fa6402bdf28497df..43db7c44d63fce17f8500d41d146f3ca145a8157 100644 (file)
@@ -1195,8 +1195,9 @@ class MeasureUpdateFormulaFactoryImplTest {
       newImpactGroup(SECURITY, MEDIUM, Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX, 5),
       newImpactGroup(SECURITY, LOW, Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX, 6),
       newImpactGroup(SECURITY, HIGH, Issue.STATUS_RESOLVED, Issue.RESOLUTION_FALSE_POSITIVE, 7),
-      newImpactGroup(RELIABILITY, HIGH, Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX, 8))
-      .assertThatValueIs(CoreMetrics.HIGH_IMPACT_ACCEPTED_ISSUES, 4 + 8);
+      newImpactGroup(RELIABILITY, HIGH, Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX, 8),
+      newImpactGroup(RELIABILITY, BLOCKER, Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX, 2))
+        .assertThatValueIs(CoreMetrics.HIGH_IMPACT_ACCEPTED_ISSUES, 4 + 8 + 2);
   }
 
   @Test