From e7e6956074d6d7ce5d6f8323af89ea876a79ef2c Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 22 Oct 2019 13:39:33 -0500 Subject: [PATCH] SONAR-11604 - api/measures/component move 'periods' response field to 'period' - api/measures/component and api/measures/component_tree move 'periods' response field to 'period' --- .../component/ws/MeasuresWsParameters.java | 11 ++- .../server/measure/ws/ComponentAction.java | 16 +++-- .../measure/ws/ComponentTreeAction.java | 24 ++++--- .../server/measure/ws/ComponentTreeData.java | 1 - .../measure/ws/MeasureDtoToWsMeasure.java | 2 + .../ws/MeasuresWsParametersBuilder.java | 2 +- .../server/measure/ws/component-example.json | 43 +++++------- .../measure/ws/component_tree-example.json | 67 +++++++------------ .../measure/ws/ComponentActionTest.java | 7 +- .../measure/ws/ComponentTreeActionTest.java | 33 +++++++-- sonar-ws/src/main/protobuf/ws-measures.proto | 8 +++ 11 files changed, 118 insertions(+), 96 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java index 1dc236821fc..55a61c290da 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/MeasuresWsParameters.java @@ -49,9 +49,16 @@ public class MeasuresWsParameters { public static final String PARAM_TO = "to"; public static final String ADDITIONAL_METRICS = "metrics"; - public static final String ADDITIONAL_PERIODS = "periods"; - public static final Set ADDITIONAL_FIELDS = ImmutableSortedSet.of(ADDITIONAL_METRICS, ADDITIONAL_PERIODS); + /** + * @deprecated since 8.1 + */ + @Deprecated + public static final String DEPRECATED_ADDITIONAL_PERIODS = "periods"; + + public static final String ADDITIONAL_PERIOD = "period"; + + public static final Set ADDITIONAL_FIELDS = ImmutableSortedSet.of(ADDITIONAL_METRICS, DEPRECATED_ADDITIONAL_PERIODS, ADDITIONAL_PERIOD); private MeasuresWsParameters() { // static constants only diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 8ccd6eb5013..e8305d99e8b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.measure.ws; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Maps; import java.util.Collection; @@ -59,7 +58,8 @@ import static java.util.Collections.singletonList; 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_PERIODS; +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 +97,8 @@ public class ComponentAction implements MeasuresWsAction { .setResponseExample(getClass().getResource("component-example.json")) .setSince("5.4") .setChangelog( + new Change("8.1", "the response field periods under measures field is deprecated. Use period instead."), + new Change("8.1", "the response field periods is deprecated. Use period instead."), new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), new Change("6.6", "the response field id is deprecated. Use key instead."), new Change("6.6", "the response field refId is deprecated. Use refKey instead.")) @@ -166,7 +168,7 @@ public class ComponentAction implements MeasuresWsAction { if (metrics.size() < metricKeys.size()) { Set foundMetricKeys = metrics.stream().map(MetricDto::getKey).collect(Collectors.toSet()); Set missingMetricKeys = metricKeys.stream().filter(m -> !foundMetricKeys.contains(m)).collect(Collectors.toSet()); - throw new NotFoundException(format("The following metric keys are not found: %s", Joiner.on(", ").join(missingMetricKeys))); + throw new NotFoundException(format("The following metric keys are not found: %s", String.join(", ", missingMetricKeys))); } return metrics; @@ -258,9 +260,15 @@ public class ComponentAction implements MeasuresWsAction { response.getMetricsBuilder().addMetrics(metricDtoToWsMetric(metric)); } } - if (additionalFields.contains(ADDITIONAL_PERIODS) && period.isPresent()) { + + // 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()); + } } return response.build(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index 818ed85da1e..4cb01c588a4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -86,7 +86,8 @@ import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES; import static org.sonar.server.component.ComponentFinder.ParamNames.BASE_COMPONENT_ID_AND_KEY; 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_PERIODS; +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.DEPRECATED_PARAM_BASE_COMPONENT_ID; import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; @@ -109,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; /** @@ -174,14 +175,16 @@ public class ComponentTreeAction implements MeasuresWsAction { public void define(WebService.NewController context) { WebService.NewAction action = context.createAction(ACTION_COMPONENT_TREE) .setDescription(format("Navigate through components based on the chosen strategy with specified measures. The %s or the %s parameter must be provided.
" + - "Requires the following permission: 'Browse' on the specified project.
" + - "When limiting search with the %s parameter, directories are not returned.", + "Requires the following permission: 'Browse' on the specified project.
" + + "When limiting search with the %s parameter, directories are not returned.", DEPRECATED_PARAM_BASE_COMPONENT_ID, PARAM_COMPONENT, Param.TEXT_QUERY)) .setResponseExample(getClass().getResource("component_tree-example.json")) .setSince("5.4") .setHandler(this) .addPagingParams(100, MAX_SIZE) .setChangelog( + new Change("8.1", "the response field periods under measures field is deprecated. Use period instead."), + new Change("8.1", "the response field periods is deprecated. Use period instead."), new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)), new Change("7.2", "field 'bestValue' is added to the response"), new Change("6.3", format("Number of metric keys is limited to %s", MAX_METRIC_KEYS)), @@ -308,10 +311,16 @@ public class ComponentTreeAction implements MeasuresWsAction { } } - if (arePeriodsInResponse(request) && data.getPeriod() != null) { + List 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()); + } + return response.build(); } @@ -320,11 +329,6 @@ public class ComponentTreeAction implements MeasuresWsAction { return additionalFields != null && additionalFields.contains(ADDITIONAL_METRICS); } - private static boolean arePeriodsInResponse(ComponentTreeRequest request) { - List additionalFields = request.getAdditionalFields(); - return additionalFields != null && additionalFields.contains(ADDITIONAL_PERIODS); - } - private static ComponentTreeWsResponse emptyResponse(@Nullable ComponentDto baseComponent, ComponentTreeRequest request) { ComponentTreeWsResponse.Builder response = ComponentTreeWsResponse.newBuilder(); response.getPagingBuilder() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java index d2747787f0c..e2af088fbc3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java @@ -76,7 +76,6 @@ class ComponentTreeData { return metrics; } - @CheckForNull Measures.Period getPeriod() { return period; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java index ad9929aeb7a..186b6ce0c38 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasure.java @@ -67,6 +67,8 @@ class MeasureDtoToWsMeasure { .setIndex(1) .setValue(formatNumericalValue(variation, metric)); ofNullable(bestValue).ifPresent(v -> builderForValue.setBestValue(compare(variation, v) == 0)); + //deprecated since 8.1 measureBuilder.getPeriodsBuilder().addPeriodsValue(builderForValue); + measureBuilder.setPeriod(builderForValue); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java index d3d8768662a..68319afda76 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsParametersBuilder.java @@ -36,7 +36,7 @@ class MeasuresWsParametersBuilder { return action.createParam(PARAM_ADDITIONAL_FIELDS) .setDescription("Comma-separated list of additional fields that can be returned in the response.") .setPossibleValues(ADDITIONAL_FIELDS) - .setExampleValue("periods,metrics"); + .setExampleValue("period,metrics"); } static NewParam createMetricKeysParameter(NewAction action) { diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json index dbac846a7e7..fabfaed6134 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component-example.json @@ -9,31 +9,25 @@ { "metric": "complexity", "value": "12", - "periods": [ - { - "index": 1, - "value": "2" - } - ] + "period": { + "value": "2", + "bestValue": false + } }, { "metric": "new_violations", - "periods": [ - { - "index": 1, - "value": "25" - } - ] + "period": { + "value": "25", + "bestValue": false + } }, { "metric": "ncloc", "value": "114", - "periods": [ - { - "index": 1, - "value": "3" - } - ] + "period": { + "value": "3", + "bestValue": false + } } ] }, @@ -72,12 +66,9 @@ "custom": false } ], - "periods": [ - { - "index": 1, - "mode": "previous_version", - "date": "2016-01-11T10:49:50+0100", - "parameter": "1.0-SNAPSHOT" - } - ] + "period": { + "mode": "previous_version", + "date": "2016-01-11T10:49:50+0100", + "parameter": "1.0-SNAPSHOT" + } } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json index 701f30a3970..5344fd97e81 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/measure/ws/component_tree-example.json @@ -11,12 +11,9 @@ "measures": [ { "metric": "new_violations", - "periods": [ - { - "index": 1, - "value": "255" - } - ] + "period": { + "value": "255" + } }, { "metric": "complexity", @@ -38,12 +35,9 @@ "measures": [ { "metric": "new_violations", - "periods": [ - { - "index": 1, - "value": "25" - } - ] + "period": { + "value": "25" + } }, { "metric": "complexity", @@ -64,12 +58,9 @@ "measures": [ { "metric": "new_violations", - "periods": [ - { - "index": 1, - "value": "0" - } - ] + "period": { + "value": "0" + } } ] }, @@ -81,32 +72,23 @@ "measures": [ { "metric": "new_violations", - "periods": [ - { - "index": 1, - "value": "25" - } - ] + "period": { + "value": "25" + } }, { "metric": "complexity", "value": "35", - "periods": [ - { - "index": 1, - "value": "0" - } - ] + "period": { + "value": "0" + } }, { "metric": "ncloc", "value": "217", - "periods": [ - { - "index": 1, - "value": "0" - } - ] + "period": { + "value": "0" + } } ] } @@ -147,12 +129,9 @@ "bestValue": "0" } ], - "periods": [ - { - "index": 1, - "mode": "previous_version", - "date": "2016-01-11T10:49:50+0100", - "parameter": "1.0-SNAPSHOT" - } - ] + "period": { + "mode": "previous_version", + "date": "2016-01-11T10:49:50+0100", + "parameter": "1.0-SNAPSHOT" + } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index 7e166ecb97b..0d82256257c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -97,6 +97,7 @@ public class ComponentActionTest { ComponentWsResponse response = newRequest(project.getKey(), metric.getKey()); assertThat(response.getMetrics().getMetricsCount()).isEqualTo(1); + assertThat(response.hasPeriod()).isFalse(); assertThat(response.getPeriods().getPeriodsCount()).isEqualTo(0); assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); } @@ -114,7 +115,7 @@ public class ComponentActionTest { .execute().getInput(); assertThat(response) - .doesNotContain("periods") + .doesNotContain("period") .doesNotContain("metrics"); } @@ -469,7 +470,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,periods") + .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period,periods") .execute() .getInput(); @@ -480,7 +481,7 @@ public class ComponentActionTest { return ws.newRequest() .setParam(PARAM_COMPONENT, componentKey) .setParam(PARAM_METRIC_KEYS, metricKeys) - .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,periods") + .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period,periods") .executeProtobuf(ComponentWsResponse.class); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 57fd73c38d5..9ed8ba673e9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -77,7 +77,8 @@ import static org.sonar.db.component.ComponentTesting.newDirectory; 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_PERIODS; +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.DEPRECATED_PARAM_BASE_COMPONENT_ID; import static org.sonar.server.component.ws.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; @@ -165,7 +166,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,periods") + .setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period,periods") .execute() .getInput(); @@ -184,6 +185,7 @@ public class ComponentTreeActionTest { assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getKey()); assertThat(response.getComponentsList()).isEmpty(); assertThat(response.getMetrics().getMetricsList()).isEmpty(); + assertThat(response.hasPeriod()).isFalse(); assertThat(response.getPeriods().getPeriodsList()).isEmpty(); } @@ -210,7 +212,7 @@ public class ComponentTreeActionTest { ComponentTreeWsResponse response = ws.newRequest() .setParam(PARAM_COMPONENT, project.getKey()) .setParam(PARAM_METRIC_KEYS, "ncloc,coverage") - .setParam(PARAM_ADDITIONAL_FIELDS, ADDITIONAL_PERIODS) + .setParam(PARAM_ADDITIONAL_FIELDS, DEPRECATED_ADDITIONAL_PERIODS + "," + ADDITIONAL_PERIOD) .executeProtobuf(ComponentTreeWsResponse.class); assertThat(response.getComponentsList().get(0).getMeasuresList()).extracting("metric").containsOnly("coverage"); @@ -218,6 +220,7 @@ public class ComponentTreeActionTest { List fileMeasures = response.getComponentsList().get(1).getMeasuresList(); 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"); } @@ -297,6 +300,8 @@ public class ComponentTreeActionTest { .executeProtobuf(ComponentTreeWsResponse.class); // file measures + + // verify backward compatibility List fileMeasures = response.getComponentsList().get(0).getMeasuresList(); assertThat(fileMeasures) .extracting(Measure::getMetric, m -> m.getPeriods().getPeriodsValueList()) @@ -304,6 +309,13 @@ public class ComponentTreeActionTest { 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) + .containsExactlyInAnyOrder( + tuple(matchingBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("100").setBestValue(true).build()), + tuple(doesNotMatchBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("10").setBestValue(false).build()), + tuple(noBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("42").build())); } @Test @@ -334,8 +346,10 @@ public class ComponentTreeActionTest { // 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"); // 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"); } @Test @@ -584,6 +598,10 @@ public class ComponentTreeActionTest { assertThat(response.getBaseComponent().getMeasuresList()) .extracting(Measure::getMetric, m -> parseDouble(m.getPeriods().getPeriodsValue(0).getValue()), Measure::getValue) .containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), "")); + + assertThat(response.getBaseComponent().getMeasuresList()) + .extracting(Measure::getMetric, m -> parseDouble(m.getPeriod().getValue()), Measure::getValue) + .containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), "")); } @Test @@ -605,10 +623,15 @@ public class ComponentTreeActionTest { .executeProtobuf(ComponentTreeWsResponse.class); Function extractVariation = m -> { + Double periodValue = null; if (m.getPeriods().getPeriodsValueCount() > 0) { - return parseDouble(m.getPeriods().getPeriodsValue(0).getValue()); + periodValue = parseDouble(m.getPeriods().getPeriodsValue(0).getValue()); + } + + if (m.hasPeriod()) { + assertThat(parseDouble(m.getPeriod().getValue())).isEqualTo(periodValue); } - return null; + return periodValue; }; assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch) diff --git a/sonar-ws/src/main/protobuf/ws-measures.proto b/sonar-ws/src/main/protobuf/ws-measures.proto index 0385751c43b..17d7c0c866c 100644 --- a/sonar-ws/src/main/protobuf/ws-measures.proto +++ b/sonar-ws/src/main/protobuf/ws-measures.proto @@ -32,14 +32,18 @@ message ComponentTreeWsResponse { optional Component baseComponent = 2; repeated Component components = 3; optional Metrics metrics = 4; + //deprecated since 8.1 optional Periods periods = 5; + optional Period period = 6; } // WS api/measures/component message ComponentWsResponse { optional Component component = 1; optional Metrics metrics = 2; + //deprecated since 8.1 optional Periods periods = 3; + optional Period period = 4; } // WS api/measures/search @@ -80,6 +84,7 @@ message Component { } message Period { + //deprecated since 8.1 optional int32 index = 1; optional string mode = 2; optional string date = 3; @@ -97,9 +102,11 @@ message Metrics { message Measure { optional string metric = 1; optional string value = 2; + //deprecated since 8.1 optional PeriodsValue periods = 3; optional string component = 4; optional bool bestValue = 5; + optional PeriodValue period = 6; } message PeriodsValue { @@ -107,6 +114,7 @@ message PeriodsValue { } message PeriodValue { + //deprecated since 8.1 optional int32 index = 1; optional string value = 2; optional bool bestValue = 3; -- 2.39.5