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
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;
.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())),
}
}
- // 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());
}
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;
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;
/**
.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"),
}
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());
.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);
}
}
{
"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
+ }
}
]
}
*/
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;
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;
assertThat(response.getMetrics().getMetricsCount()).isOne();
assertThat(response.hasPeriod()).isFalse();
- assertThat(response.getPeriods().getPeriodsCount()).isZero();
assertThat(response.getComponent().getKey()).isEqualTo(project.getKey());
}
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(
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();
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);
}
}
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;
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();
assertThat(response.getComponentsList()).isEmpty();
assertThat(response.getMetrics().getMetricsList()).isEmpty();
assertThat(response.hasPeriod()).isFalse();
- assertThat(response.getPeriods().getPeriodsList()).isEmpty();
}
@Test
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");
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
// 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)
.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");
}
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())
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
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;
}
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;
}
optional string parameter = 4;
}
-message Periods {
- repeated Period periods = 1;
-}
-
message Metrics {
repeated sonarqube.ws.commons.Metric metrics = 1;
}
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