]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23566 Remove deprecation on metrics based on type or severity
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Tue, 12 Nov 2024 14:28:13 +0000 (15:28 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 13 Nov 2024 20:05:48 +0000 (20:05 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/MeasuresWsModuleTest.java

index 03604616f1fe38df8541ebd96023fc9521ddfaf1..e41a4f5d10d789ba47bfe1a4505f7a992a83845b 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-import org.sonar.db.component.ComponentQualifiers;
 import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
@@ -38,6 +37,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentQualifiers;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.MeasureDto;
 import org.sonar.db.metric.MetricDto;
@@ -88,10 +88,12 @@ public class ComponentAction implements MeasuresWsAction {
   public void define(WebService.NewController context) {
     WebService.NewAction action = context.createAction(ACTION_COMPONENT)
       .setDescription("Return component with specified measures.<br>" +
-                      "Requires the following permission: 'Browse' on the project of specified component.")
+        "Requires the following permission: 'Browse' on the project of specified component.")
       .setResponseExample(getClass().getResource("component-example.json"))
       .setSince("5.4")
       .setChangelog(
+        new Change("10.8", format("The following metrics are not deprecated anymore: %s",
+          MeasuresWsModule.getUndeprecatedMetricsinSonarQube108())),
         new Change("10.8", String.format("Added new accepted values for the 'metricKeys' param: %s",
           MeasuresWsModule.getNewMetricsInSonarQube108())),
         new Change("10.8", String.format("The metrics %s are now deprecated. Use 'software_quality_maintainability_issues', " +
@@ -100,7 +102,7 @@ public class ComponentAction implements MeasuresWsAction {
           MeasuresWsModule.getDeprecatedMetricsInSonarQube108())),
         new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
         new Change("10.5", String.format("The metrics %s are now deprecated " +
-                                         "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
         new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
         new Change("10.4", String.format("The metrics %s are now deprecated " +
index 8c8d55656778fbc3b27488f0ed13fa5088593ca9..d6d8bc8fc91183ab83590c47cf04359344ab7e38 100644 (file)
@@ -110,8 +110,8 @@ import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeri
 import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
 import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
 import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001;
-import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
 import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
+import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 /**
@@ -182,6 +182,8 @@ public class ComponentTreeAction implements MeasuresWsAction {
       .setHandler(this)
       .addPagingParams(100, MAX_SIZE)
       .setChangelog(
+        new Change("10.8", String.format("The following metrics are not deprecated anymore: %s",
+          MeasuresWsModule.getUndeprecatedMetricsinSonarQube108())),
         new Change("10.8", String.format("Added new accepted values for the 'metricKeys' param: %s",
           MeasuresWsModule.getNewMetricsInSonarQube108())),
         new Change("10.8", String.format("The metrics %s are now deprecated. Use 'software_quality_maintainability_issues', " +
@@ -194,12 +196,12 @@ public class ComponentTreeAction implements MeasuresWsAction {
         new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues'," +
           " 'new_security_issues'"),
         new Change("10.5", format("The metrics %s are now deprecated " +
-            "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
         new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'maintainability_issues', 'reliability_issues', " +
           "'security_issues'"),
         new Change("10.4", format("The metrics %s are now deprecated " +
-            "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
         new Change("10.4", "The metrics 'open_issues', 'reopened_issues' and 'confirmed_issues' are now deprecated in the response. " +
           "Consume 'violations' instead."),
@@ -316,7 +318,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
       request,
       data,
       Paging.forPageIndex(
-          request.getPage())
+        request.getPage())
         .withPageSize(request.getPageSize())
         .andTotal(data.getComponentCount()),
       request.getMetricKeys());
@@ -478,8 +480,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
 
       List<MetricDto> metrics = searchMetrics(dbSession,
         new HashSet<>(withRemovedMetricAlias(ofNullable(wsRequest.getMetricKeys()).orElse(List.of()))));
-      Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric =
-        searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, componentTreeQuery,
+      Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, componentTreeQuery,
         components, metrics);
 
       components = filterComponents(components, measuresByComponentUuidAndMetric, metrics, wsRequest);
index 38d2263f782ffed4e167c2e0ec3c13b708479929..cb24f75417646aaf1f02ee96388f1666a214374c 100644 (file)
@@ -76,37 +76,41 @@ public class MeasuresWsModule extends Module {
 
   public static String getNewMetricsInSonarQube108() {
     return Stream.of(
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_BLOCKER_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_HIGH_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_INFO_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MEDIUM_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_LOW_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_ISSUES,
-        SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_BLOCKER_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_HIGH_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_INFO_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MEDIUM_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_LOW_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_ISSUES,
+      SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_ISSUES,
 
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_BLOCKER_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_HIGH_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_INFO_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MEDIUM_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_LOW_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_ISSUES,
-        SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_ISSUES)
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_BLOCKER_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_HIGH_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_INFO_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MEDIUM_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_LOW_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_ISSUES,
+      SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_ISSUES)
       .map(e -> "'" + e.getKey() + "'")
       .collect(Collectors.joining(", "));
   }
 
   public static String getDeprecatedMetricsInSonarQube108() {
     return Stream.of(
-        CoreMetrics.MAINTAINABILITY_ISSUES_KEY,
-        CoreMetrics.RELIABILITY_ISSUES_KEY,
-        CoreMetrics.SECURITY_ISSUES_KEY,
+      CoreMetrics.MAINTAINABILITY_ISSUES_KEY,
+      CoreMetrics.RELIABILITY_ISSUES_KEY,
+      CoreMetrics.SECURITY_ISSUES_KEY,
 
-        CoreMetrics.NEW_MAINTAINABILITY_ISSUES_KEY,
-        CoreMetrics.NEW_RELIABILITY_ISSUES_KEY,
-        CoreMetrics.NEW_SECURITY_ISSUES_KEY)
+      CoreMetrics.NEW_MAINTAINABILITY_ISSUES_KEY,
+      CoreMetrics.NEW_RELIABILITY_ISSUES_KEY,
+      CoreMetrics.NEW_SECURITY_ISSUES_KEY)
       .map(e -> "'" + e + "'")
       .collect(Collectors.joining(", "));
   }
+
+  public static String getUndeprecatedMetricsinSonarQube108() {
+    return getDeprecatedMetricsInSonarQube104() + ", " + getDeprecatedMetricsInSonarQube105();
+  }
 }
index f19ef866e3c551d6f8d54aed4b402b73b6ba3222..a48b549934c230472dc16408130d9dc4336a7c19 100644 (file)
@@ -87,6 +87,7 @@ public class SearchAction implements MeasuresWsAction {
       .setResponseExample(getClass().getResource("search-example.json"))
       .setHandler(this)
       .setChangelog(
+        new Change("10.8", format("The following metrics are not deprecated anymore: %s", MeasuresWsModule.getUndeprecatedMetricsinSonarQube108())),
         new Change("10.8", String.format("Added new accepted values for the 'metricKeys' param: %s",
           MeasuresWsModule.getNewMetricsInSonarQube108())),
         new Change("10.8", String.format("The metrics %s are now deprecated. Use 'software_quality_maintainability_issues', " +
@@ -95,11 +96,11 @@ public class SearchAction implements MeasuresWsAction {
           MeasuresWsModule.getDeprecatedMetricsInSonarQube108())),
         new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
         new Change("10.5", String.format("The metrics %s are now deprecated " +
-                                         "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
         new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
         new Change("10.4", String.format("The metrics %s are now deprecated " +
-            "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
         new Change("10.4", "Added new accepted values for the 'metricKeys' param: 'maintainability_issues', 'reliability_issues', 'security_issues'"),
         new Change("10.4", "The metrics 'open_issues', 'reopened_issues' and 'confirmed_issues' are now deprecated in the response. Consume 'violations' instead."),
index 927587e28e5e7c55c00cac7839ab3faa52f647ec..777f0a8075c0f5e40ebb2a751c08f7392c17dfd5 100644 (file)
@@ -95,6 +95,8 @@ public class SearchHistoryAction implements MeasuresWsAction {
       .setResponseExample(getClass().getResource("search_history-example.json"))
       .setSince("6.3")
       .setChangelog(
+        new Change("10.8", String.format("The following metrics are not deprecated anymore: %s",
+          MeasuresWsModule.getUndeprecatedMetricsinSonarQube108())),
         new Change("10.8", String.format("Added new accepted values for the 'metricKeys' param: %s",
           MeasuresWsModule.getNewMetricsInSonarQube108())),
         new Change("10.8", String.format("The metrics %s are now deprecated. Use 'software_quality_maintainability_issues', " +
@@ -103,11 +105,11 @@ public class SearchHistoryAction implements MeasuresWsAction {
           MeasuresWsModule.getDeprecatedMetricsInSonarQube108())),
         new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
         new Change("10.5", String.format("The metrics %s are now deprecated " +
-                                         "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
         new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
         new Change("10.4", String.format("The metrics %s are now deprecated " +
-            "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
+          "without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
           MeasuresWsModule.getDeprecatedMetricsInSonarQube104())),
         new Change("10.4", "The metrics 'open_issues', 'reopened_issues' and 'confirmed_issues' are now deprecated in the response. Consume 'violations' instead."),
         new Change("10.4", "The use of 'open_issues', 'reopened_issues' and 'confirmed_issues' values in 'metricKeys' param are now deprecated. Use 'violations' instead."),
index 882e8d68af80f6b3ba9d2577fabf89c216a909c0..e37f918861954ade0dfcaf7600910460080332b0 100644 (file)
@@ -76,4 +76,12 @@ class MeasuresWsModuleTest {
       "'new_software_quality_medium_issues', 'new_software_quality_low_issues', 'new_software_quality_maintainability_issues', " +
       "'new_software_quality_reliability_issues', 'new_software_quality_security_issues'");
   }
+
+  @Test
+  void getUndeprecatedMetricsinSonarQube108_shouldReturnExactString() {
+    String actual = MeasuresWsModule.getUndeprecatedMetricsinSonarQube108();
+    assertThat(actual).isEqualTo("'bugs', 'new_bugs', 'vulnerabilities', 'new_vulnerabilities', 'code_smells', 'new_code_smells', 'high_impact_accepted_issues', " +
+      "'new_blocker_violations', 'new_critical_violations', 'new_major_violations', 'new_minor_violations', 'new_info_violations', 'blocker_violations', " +
+      "'critical_violations', 'major_violations', 'minor_violations', 'info_violations'");
+  }
 }