import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.WsMeasures;
-import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
import static org.sonar.server.measure.ws.MeasureValueFormatter.formatMeasureValue;
+import static org.sonar.server.measure.ws.MeasureValueFormatter.formatNumericalValue;
class MeasureDtoToWsMeasure {
measure.setMetric(metricDto.getKey());
// a measure value can be null, new_violations metric for example
if (measureDto.getValue() != null
- || measureDto.getData()!=null) {
+ || measureDto.getData() != null) {
measure.setValue(formatMeasureValue(measureDto, metricDto));
}
- if (measureDto.getVariation(1) != null) {
- measure.setVariationValueP1(formatNumericalValue(measureDto.getVariation(1), metricDto));
- }
- if (measureDto.getVariation(2) != null) {
- measure.setVariationValueP2(formatNumericalValue(measureDto.getVariation(2), metricDto));
- }
- if (measureDto.getVariation(3) != null) {
- measure.setVariationValueP3(formatNumericalValue(measureDto.getVariation(3), metricDto));
- }
- if (measureDto.getVariation(4) != null) {
- measure.setVariationValueP4(formatNumericalValue(measureDto.getVariation(4), metricDto));
- }
- if (measureDto.getVariation(5) != null) {
- measure.setVariationValueP5(formatNumericalValue(measureDto.getVariation(5), metricDto));
+
+ WsMeasures.PeriodValue.Builder periodBuilder = WsMeasures.PeriodValue.newBuilder();
+ for (int i = 1; i <= 5; i++) {
+ if (measureDto.getVariation(i) != null) {
+ measure.addPeriods(periodBuilder
+ .clear()
+ .setIndex(i)
+ .setValue(formatNumericalValue(measureDto.getVariation(i), metricDto)));
+ }
}
return measure.build();
"measures": [
{
"metric": "new_violations",
- "variationValueP1": "255",
- "variationValueP2": "0",
- "variationValueP3": "255"
+ "periods": [
+ {
+ "index": 1,
+ "value": "255"
+ },
+ {
+ "index": 2,
+ "value": "0"
+ },
+ {
+ "index": 3,
+ "value": "255"
+ }
+ ]
},
{
- "metric": "ncloc",
- "value": "1984"
+ "metric": "complexity",
+ "value": "42",
+ "periods": []
},
{
- "metric": "complexity",
- "value": "42"
+ "metric": "ncloc",
+ "value": "1984",
+ "periods": []
}
]
},
"measures": [
{
"metric": "new_violations",
- "variationValueP1": "25",
- "variationValueP2": "0",
- "variationValueP3": "25"
+ "periods": [
+ {
+ "index": 1,
+ "value": "25"
+ },
+ {
+ "index": 2,
+ "value": "0"
+ },
+ {
+ "index": 3,
+ "value": "25"
+ }
+ ]
},
{
- "metric": "ncloc",
- "value": "114"
+ "metric": "complexity",
+ "value": "12",
+ "periods": []
},
{
- "metric": "complexity",
- "value": "12"
+ "metric": "ncloc",
+ "value": "114",
+ "periods": []
}
]
},
"measures": [
{
"metric": "new_violations",
- "variationValueP1": "0",
- "variationValueP2": "0",
- "variationValueP3": "0"
+ "periods": [
+ {
+ "index": 1,
+ "value": "0"
+ },
+ {
+ "index": 2,
+ "value": "0"
+ },
+ {
+ "index": 3,
+ "value": "0"
+ }
+ ]
}
]
},
"qualifier": "DIR",
"path": "src/main/java/com/sonarsource/markdown/impl",
"measures": [
- {
- "metric": "ncloc",
- "value": "217",
- "variationValueP2": "0"
- },
{
"metric": "new_violations",
- "variationValueP1": "25",
- "variationValueP2": "0",
- "variationValueP3": "25"
+ "periods": [
+ {
+ "index": 1,
+ "value": "25"
+ },
+ {
+ "index": 2,
+ "value": "0"
+ },
+ {
+ "index": 3,
+ "value": "25"
+ }
+ ]
},
{
"metric": "complexity",
"value": "35",
- "variationValueP2": "0"
+ "periods": [
+ {
+ "index": 2,
+ "value": "0"
+ }
+ ]
+ },
+ {
+ "metric": "ncloc",
+ "value": "217",
+ "periods": [
+ {
+ "index": 2,
+ "value": "0"
+ }
+ ]
}
]
}
db.commit();
InputStream responseStream = newRequest(Qualifiers.PROJECT)
- .setParam(Param.TEXT_QUERY, "project-_%")
+ .setParam(Param.TEXT_QUERY, "project-_%-key")
.execute().getInputStream();
SearchWsResponse response = SearchWsResponse.parseFrom(responseStream);
List<WsMeasures.Measure> fileMeasures = response.getComponentsList().get(1).getMeasures().getMeasuresList();
assertThat(fileMeasures).extracting("metric").containsOnly("ncloc", "coverage");
assertThat(fileMeasures).extracting("value").containsOnly("5", "15.5");
- assertThat(fileMeasures).extracting("variationValueP1").containsOnly("", "4");
- assertThat(fileMeasures).extracting("variationValueP3").containsOnly("", "2.0");
assertThat(response.getPeriods().getPeriodsList()).extracting("mode").containsOnly("last_version", "last_analysis");
}
return qualifiers;
}
+ @CheckForNull
public String getNameOrKeyQuery() {
return nameOrKeyQuery;
}
return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, AFTER).toLowerCase();
}
- @CheckForNull
- public String getNameOrKeyQueryToSqlForProjectKey() {
- return nameOrKeyQuery == null ? null : buildLikeValue(nameOrKeyQuery, AFTER);
- }
-
public Integer getPage() {
return page;
}
message Measure {
optional string metric = 1;
optional string value = 2;
- optional string variationValueP1 = 3;
- optional string variationValueP2 = 4;
- optional string variationValueP3 = 5;
- optional string variationValueP4 = 6;
- optional string variationValueP5 = 7;
+ repeated PeriodValue periods = 3;
+}
+
+message PeriodValue {
+ optional int32 index = 1;
+ optional string value = 2;
}