]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18647 Remove parameter period in api/measures endpoints
authorZipeng WU <zipeng.wu@sonarsource.com>
Thu, 9 Mar 2023 15:16:52 +0000 (16:16 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 10 Mar 2023 20:02:47 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java
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/MeasureDtoToWsMeasure.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/search-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java
sonar-ws/src/main/protobuf/ws-measures.proto

index 8b647b05344108e53c08cd355b4b780d66f4592c..6ac47d18f69713745353449f0e6b8e60e1b3dadd 100644 (file)
@@ -48,15 +48,9 @@ public class MeasuresWsParameters {
 
   public static final String ADDITIONAL_METRICS = "metrics";
 
-  /**
-   * @deprecated since 8.1
-   */
-  @Deprecated
-  public static final String DEPRECATED_ADDITIONAL_PERIODS = "periods";
-
   public static final String ADDITIONAL_PERIOD = "period";
 
-  public static final Set<String> ADDITIONAL_FIELDS = ImmutableSortedSet.of(ADDITIONAL_METRICS, DEPRECATED_ADDITIONAL_PERIODS, ADDITIONAL_PERIOD);
+  public static final Set<String> ADDITIONAL_FIELDS = ImmutableSortedSet.of(ADDITIONAL_METRICS, ADDITIONAL_PERIOD);
 
   private MeasuresWsParameters() {
     // static constants only
index 0c10d0e3923b828fe4d5c28f344b1cfe7b112c38..95a9d4d715ace5cbfd0fe202795719059339a6d8 100644 (file)
@@ -59,7 +59,6 @@ import static java.util.Collections.singletonMap;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIOD;
-import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_ADDITIONAL_PERIODS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT;
@@ -97,6 +96,8 @@ public class ComponentAction implements MeasuresWsAction {
       .setResponseExample(getClass().getResource("component-example.json"))
       .setSince("5.4")
       .setChangelog(
+        new Change("10.0", "the response field periods under measures field is removed."),
+        new Change("10.0", "the option `periods` of 'additionalFields' request field is removed."),
         new Change("9.3", "When the new code period is set to 'reference branch', the response field 'date' under the 'period' field has been removed"),
         new Change("9.3", format("The use of the following metrics in 'metricKeys' parameter is deprecated: %s",
           MeasuresWsModule.getDeprecatedMetrics())),
@@ -271,11 +272,6 @@ public class ComponentAction implements MeasuresWsAction {
         }
       }
 
-      // backward compatibility
-      if (additionalFields.contains(DEPRECATED_ADDITIONAL_PERIODS) && period.isPresent()) {
-        response.getPeriodsBuilder().addPeriods(period.get());
-      }
-
       if (additionalFields.contains(ADDITIONAL_PERIOD) && period.isPresent()) {
         response.setPeriod(period.get());
       }
index 4e5eabfa263bad6b98902f09fe1435342fe09345..3c65f7c95ef86677f0ac9f37f80053585d0d332a 100644 (file)
@@ -85,7 +85,6 @@ import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ACTION_COMPONENT_TREE;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_METRICS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIOD;
-import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_ADDITIONAL_PERIODS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT;
@@ -106,8 +105,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.createQualifiersParameter;
 import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
+import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 /**
@@ -179,6 +178,8 @@ public class ComponentTreeAction implements MeasuresWsAction {
       .setHandler(this)
       .addPagingParams(100, MAX_SIZE)
       .setChangelog(
+        new Change("10.0", "the response field periods under measures field is removed."),
+        new Change("10.0", "the option `periods` of 'additionalFields' request field is removed."),
         new Change("9.3", format("The use of the following metrics in 'metricKeys' parameter is deprecated: %s",
           MeasuresWsModule.getDeprecatedMetrics())),
         new Change("8.8", "parameter 'component' is now required"),
@@ -317,10 +318,6 @@ public class ComponentTreeAction implements MeasuresWsAction {
     }
 
     List<String> additionalFields = Optional.ofNullable(request.getAdditionalFields()).orElse(Collections.emptyList());
-    // backward compatibility
-    if (additionalFields.contains(DEPRECATED_ADDITIONAL_PERIODS) && data.getPeriod() != null) {
-      response.getPeriodsBuilder().addPeriods(data.getPeriod());
-    }
 
     if (additionalFields.contains(ADDITIONAL_PERIOD) && data.getPeriod() != null) {
       response.setPeriod(data.getPeriod());
index f9d2a3b4e8c30f0a05da0b9872b6e2a5443893a8..96c3536af69f6419b7afe15b3c59895c0300b747 100644 (file)
@@ -66,8 +66,6 @@ class MeasureDtoToWsMeasure {
         .setIndex(1)
         .setValue(formatMeasureValue(doubleValue, stringValue, metric));
       ofNullable(bestValue).ifPresent(v -> builderForValue.setBestValue(compare(doubleValue, v) == 0));
-      //deprecated since 8.1
-      measureBuilder.getPeriodsBuilder().addPeriodsValue(builderForValue);
       measureBuilder.setPeriod(builderForValue);
     }
   }
index 4b88de945e8c6ef2e098c2291f59848d46173306..6887fd31da3d1c260b72923dcc1464b4ab62488d 100644 (file)
@@ -3,62 +3,65 @@
     {
       "metric": "complexity",
       "value": "12",
-      "component": "MY_PROJECT_1"
+      "component": "MY_PROJECT_1",
+      "bestValue": false
     },
     {
       "metric": "complexity",
       "value": "35",
-      "component": "MY_PROJECT_2"
+      "component": "MY_PROJECT_2",
+      "bestValue": false
     },
     {
       "metric": "complexity",
       "value": "42",
-      "component": "MY_PROJECT_3"
+      "component": "MY_PROJECT_3",
+      "bestValue": false
     },
     {
       "metric": "ncloc",
       "value": "114",
-      "component": "MY_PROJECT_1"
+      "component": "MY_PROJECT_1",
+      "bestValue": false
     },
     {
       "metric": "ncloc",
       "value": "217",
-      "component": "MY_PROJECT_2"
+      "component": "MY_PROJECT_2",
+      "bestValue": false
     },
     {
       "metric": "ncloc",
       "value": "1984",
-      "component": "MY_PROJECT_3"
+      "component": "MY_PROJECT_3",
+      "bestValue": false
     },
     {
       "metric": "new_violations",
-      "periods": [
-        {
-          "index": 1,
-          "value": "25"
-        }
-      ],
-      "component": "MY_PROJECT_1"
+      "component": "MY_PROJECT_1",
+      "period": {
+        "index": 1,
+        "value": "25",
+        "bestValue": false
+      }
     },
     {
       "metric": "new_violations",
-      "periods": [
-        {
-          "index": 1,
-          "value": "25"
-        }
-      ],
-      "component": "MY_PROJECT_2"
+      "component": "MY_PROJECT_2",
+      "period": {
+        "index": 1,
+        "value": "25",
+        "bestValue": false
+      }
     },
     {
       "metric": "new_violations",
-      "periods": [
-        {
-          "index": 1,
-          "value": "255"
-        }
-      ],
-      "component": "MY_PROJECT_3"
+      "component": "MY_PROJECT_3",
+      "period": {
+        "index": 1,
+        "value": "255",
+        "bestValue": false
+      }
     }
   ]
 }
index 58573d628670d41e74da0d092cefeaeb8f3af32e..be90595ee842a18bfd5d7f3191742afcf13fbd48 100644 (file)
@@ -19,7 +19,9 @@
  */
 package org.sonar.server.measure.ws;
 
+import java.util.Optional;
 import java.util.function.Function;
+import java.util.function.Predicate;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
@@ -42,9 +44,11 @@ import org.sonarqube.ws.Measures.Component;
 import org.sonarqube.ws.Measures.ComponentWsResponse;
 
 import static java.lang.Double.parseDouble;
+import static java.util.function.Predicate.not;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.tuple;
+import static org.assertj.core.api.InstanceOfAssertFactories.OPTIONAL;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
@@ -94,7 +98,6 @@ public class ComponentActionTest {
 
     assertThat(response.getMetrics().getMetricsCount()).isOne();
     assertThat(response.hasPeriod()).isFalse();
-    assertThat(response.getPeriods().getPeriodsCount()).isZero();
     assertThat(response.getComponent().getKey()).isEqualTo(project.getKey());
   }
 
@@ -203,12 +206,11 @@ public class ComponentActionTest {
     assertThat(response.getComponent()).extracting(Component::getKey, Component::getPullRequest)
       .containsExactlyInAnyOrder(file.getKey(), "pr-123");
 
-    Function<Measures.Measure, Double> extractVariation = m -> {
-      if (m.getPeriods().getPeriodsValueCount() > 0) {
-        return parseDouble(m.getPeriods().getPeriodsValue(0).getValue());
-      }
-      return null;
-    };
+    Function<Measures.Measure, Double> extractVariation = m -> Optional.ofNullable(m.getPeriod())
+      .map(Measures.PeriodValue::getValue)
+      .filter(not(String::isEmpty))
+      .map(Double::parseDouble)
+      .orElse(null);
     assertThat(response.getComponent().getMeasuresList())
       .extracting(Measures.Measure::getMetric, extractVariation, m -> m.getValue().isEmpty() ? null : parseDouble(m.getValue()))
       .containsExactlyInAnyOrder(
@@ -448,7 +450,7 @@ public class ComponentActionTest {
     String response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations")
-      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period,periods")
+      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period")
       .execute()
       .getInput();
 
@@ -459,7 +461,7 @@ public class ComponentActionTest {
     return ws.newRequest()
       .setParam(PARAM_COMPONENT, componentKey)
       .setParam(PARAM_METRIC_KEYS, metricKeys)
-      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period,periods")
+      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period")
       .executeProtobuf(ComponentWsResponse.class);
   }
 }
index 06dfc41d5ed79aefe76317ba63f2390dab459bf8..1360f5ef2e74c6a2b3160fce7106a261c0c73f80 100644 (file)
@@ -77,7 +77,6 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.server.component.ws.MeasuresWsParameters.ADDITIONAL_PERIOD;
-import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_ADDITIONAL_PERIODS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_BRANCH;
 import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_COMPONENT;
@@ -162,7 +161,7 @@ public class ComponentTreeActionTest {
     String response = ws.newRequest()
       .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations")
-      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period,periods")
+      .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period")
       .execute()
       .getInput();
 
@@ -183,7 +182,6 @@ public class ComponentTreeActionTest {
     assertThat(response.getComponentsList()).isEmpty();
     assertThat(response.getMetrics().getMetricsList()).isEmpty();
     assertThat(response.hasPeriod()).isFalse();
-    assertThat(response.getPeriods().getPeriodsList()).isEmpty();
   }
 
   @Test
@@ -209,7 +207,7 @@ public class ComponentTreeActionTest {
     ComponentTreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, project.getKey())
       .setParam(PARAM_METRIC_KEYS, "ncloc,coverage")
-      .setParam(PARAM_ADDITIONAL_FIELDS, DEPRECATED_ADDITIONAL_PERIODS + "," + ADDITIONAL_PERIOD)
+      .setParam(PARAM_ADDITIONAL_FIELDS, ADDITIONAL_PERIOD)
       .executeProtobuf(ComponentTreeWsResponse.class);
 
     assertThat(response.getComponentsList().get(0).getMeasuresList()).extracting("metric").containsOnly("coverage");
@@ -218,7 +216,6 @@ public class ComponentTreeActionTest {
     assertThat(fileMeasures).extracting("metric").containsOnly("ncloc", "coverage");
     assertThat(fileMeasures).extracting("value").containsOnly("5", "15.5");
     assertThat(response.getPeriod().getMode()).isEqualTo("last_version");
-    assertThat(response.getPeriods().getPeriodsList()).extracting("mode").containsOnly("last_version");
   }
 
   @Test
@@ -300,12 +297,6 @@ public class ComponentTreeActionTest {
 
     // verify backward compatibility
     List<Measure> fileMeasures = response.getComponentsList().get(0).getMeasuresList();
-    assertThat(fileMeasures)
-      .extracting(Measure::getMetric, m -> m.getPeriods().getPeriodsValueList())
-      .containsExactlyInAnyOrder(
-        tuple(matchingBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("100").setBestValue(true).build())),
-        tuple(doesNotMatchBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("10").setBestValue(false).build())),
-        tuple(noBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("42").build())));
 
     assertThat(fileMeasures)
       .extracting(Measure::getMetric, Measure::getPeriod)
@@ -342,10 +333,10 @@ public class ComponentTreeActionTest {
       .executeProtobuf(ComponentTreeWsResponse.class);
 
     // directory
-    assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("2.0");
+    assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriod().getValue()).isEqualTo("2.0");
     assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriod().getValue()).isEqualTo("2.0");
     // file measures
-    assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("1.0");
+    assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriod().getValue()).isEqualTo("1.0");
     assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriod().getValue()).isEqualTo("1.0");
   }
 
@@ -631,7 +622,7 @@ public class ComponentTreeActionTest {
     assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest)
       .containsExactlyInAnyOrder(file.getKey(), "pr-123");
     assertThat(response.getBaseComponent().getMeasuresList())
-      .extracting(Measure::getMetric, m -> parseDouble(m.getPeriods().getPeriodsValue(0).getValue()), Measure::getValue)
+      .extracting(Measure::getMetric, m -> parseDouble(m.getPeriod().getValue()), Measure::getValue)
       .containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), ""));
 
     assertThat(response.getBaseComponent().getMeasuresList())
index c2a229ea1e7be31ad1a1e28a8e3e21501be42520..2895d76bc0682674389890b925d4203e97955d38 100644 (file)
@@ -156,9 +156,7 @@ public class SearchActionTest {
     Measure measure = measures.get(0);
     assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
     assertThat(measure.getValue()).isEmpty();
-    assertThat(measure.getPeriods().getPeriodsValueList())
-      .extracting(Measures.PeriodValue::getIndex, Measures.PeriodValue::getValue)
-      .containsOnly(tuple(1, "10.0"));
+    assertThat(measure.getPeriod().getValue()).isEqualTo("10.0");
   }
 
   @Test
index ebe34f594a3eabad96f4615470ad945e4b237b87..2d86f60418b56414a22342ed5d66f6798dde5234 100644 (file)
@@ -32,8 +32,7 @@ message ComponentTreeWsResponse {
   optional Component baseComponent = 2;
   repeated Component components = 3;
   optional Metrics metrics = 4;
-  //deprecated since 8.1
-  optional Periods periods = 5;
+  reserved 5; //periods
   optional Period period = 6;
 }
 
@@ -41,8 +40,7 @@ message ComponentTreeWsResponse {
 message ComponentWsResponse {
   optional Component component = 1;
   optional Metrics metrics = 2;
-  //deprecated since 8.1
-  optional Periods periods = 3;
+  reserved 3; //periods
   optional Period period = 4;
 }
 
@@ -90,10 +88,6 @@ message Period {
   optional string parameter = 4;
 }
 
-message Periods {
-  repeated Period periods = 1;
-}
-
 message Metrics {
   repeated sonarqube.ws.commons.Metric metrics = 1;
 }
@@ -101,16 +95,12 @@ message Metrics {
 message Measure {
   optional string metric = 1;
   optional string value = 2;
-  //deprecated since 8.1
-  optional PeriodsValue periods = 3;
+  reserved 3; // periods
   optional string component = 4;
   optional bool bestValue = 5;
   optional PeriodValue period = 6;
 }
 
-message PeriodsValue {
-  repeated PeriodValue periodsValue = 1;
-}
 
 message PeriodValue {
   //deprecated since 8.1