aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-21 15:54:06 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-21 16:00:41 +0200
commitfc6d8e2ddcca736718a073b1487869be2b6de5fc (patch)
tree988a935354e7553ad1bef3e4fcef5bb42795eba8 /server/sonar-server
parent997932e76a9ed18ddf8534f575b39814c019ea6c (diff)
downloadsonarqube-fc6d8e2ddcca736718a073b1487869be2b6de5fc.tar.gz
sonarqube-fc6d8e2ddcca736718a073b1487869be2b6de5fc.zip
SONAR-5319 Return SQALE Rating and SQALE Debt ratio in /api/component/app WS
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java95
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-app.json5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentAppActionTest.java7
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures.json4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures_when_period_is_set.json3
5 files changed, 68 insertions, 46 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java
index e73451be671..f853ce26652 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentAppAction.java
@@ -211,11 +211,13 @@ public class ComponentAppAction implements RequestHandler {
private void appendMeasures(JsonWriter json, Map<String, MeasureDto> measuresByMetricKey, Multiset<String> severitiesAggregation, Integer periodIndex) {
json.name("measures").beginObject();
- json.prop("fNcloc", formatMeasure(measuresByMetricKey.get(CoreMetrics.NCLOC_KEY), periodIndex));
- json.prop("fCoverage", formatMeasure(measuresByMetricKey.get(CoreMetrics.COVERAGE_KEY), periodIndex));
- json.prop("fDuplicationDensity", formatMeasure(measuresByMetricKey.get(CoreMetrics.DUPLICATED_LINES_DENSITY_KEY), periodIndex));
- json.prop("fDebt", formatMeasure(measuresByMetricKey.get(CoreMetrics.TECHNICAL_DEBT_KEY), periodIndex));
- json.prop("fTests", formatMeasure(measuresByMetricKey.get(CoreMetrics.TESTS_KEY), periodIndex));
+ json.prop("fNcloc", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.NCLOC_KEY), periodIndex));
+ json.prop("fCoverage", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.COVERAGE_KEY), periodIndex));
+ json.prop("fDuplicationDensity", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.DUPLICATED_LINES_DENSITY_KEY), periodIndex));
+ json.prop("fDebt", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.TECHNICAL_DEBT_KEY), periodIndex));
+ json.prop("fSqaleRating", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.SQALE_RATING_KEY), periodIndex));
+ json.prop("fSqaleDebtRatio", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.SQALE_DEBT_RATIO_KEY), periodIndex));
+ json.prop("fTests", formatMeasureOrVariation(measuresByMetricKey.get(CoreMetrics.TESTS_KEY), periodIndex));
json.prop("fIssues", i18n.formatInteger(UserSession.get().locale(), severitiesAggregation.size()));
for (String severity : severitiesAggregation.elementSet()) {
@@ -268,7 +270,7 @@ public class ComponentAppAction implements RequestHandler {
json.beginObject()
.prop("key", manualRule.key().toString())
.prop("name", manualRule.name())
- .endObject();
+ .endObject();
}
json.endArray();
}
@@ -334,7 +336,7 @@ public class ComponentAppAction implements RequestHandler {
for (MeasureDto measureDto : dbClient.measureDao().findByComponentKeyAndMetricKeys(fileKey,
newArrayList(CoreMetrics.NCLOC_KEY, CoreMetrics.COVERAGE_KEY,
CoreMetrics.DUPLICATED_LINES_KEY, CoreMetrics.DUPLICATED_LINES_DENSITY_KEY, CoreMetrics.TECHNICAL_DEBT_KEY, CoreMetrics.TESTS_KEY,
- CoreMetrics.SCM_AUTHORS_BY_LINE_KEY),
+ CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, CoreMetrics.SQALE_RATING_KEY, CoreMetrics.SQALE_DEBT_RATIO_KEY),
session)) {
measuresByMetricKey.put(measureDto.getKey().metricKey(), measureDto);
}
@@ -368,51 +370,58 @@ public class ComponentAppAction implements RequestHandler {
}
@CheckForNull
- private String formatMeasure(@Nullable MeasureDto measure, @Nullable Integer periodIndex) {
- if (measure != null) {
- Metric metric = CoreMetrics.getMetric(measure.getKey().metricKey());
- if (periodIndex == null) {
- Double value = measure.getValue();
- if (value != null) {
- return formatValue(value, metric.getType());
- }
- } else {
- Double variation = measure.getVariation(periodIndex);
- if (variation != null) {
- return formatVariation(variation, metric.getType());
- }
- }
+ private String formatMeasureOrVariation(@Nullable MeasureDto measure, @Nullable Integer periodIndex) {
+ if (periodIndex == null) {
+ return formatMeasure(measure);
+ } else {
+ return formatVariation(measure, periodIndex);
}
- return null;
}
@CheckForNull
- private String formatValue(Double value, Metric.ValueType metricType) {
- if (metricType.equals(Metric.ValueType.FLOAT)) {
- return i18n.formatDouble(UserSession.get().locale(), value);
- }
- if (metricType.equals(Metric.ValueType.INT)) {
- return i18n.formatInteger(UserSession.get().locale(), value.intValue());
- }
- if (metricType.equals(Metric.ValueType.PERCENT)) {
- return i18n.formatDouble(UserSession.get().locale(), value) + "%";
- }
- if (metricType.equals(Metric.ValueType.WORK_DUR)) {
- return durations.format(UserSession.get().locale(), durations.create(value.longValue()), Durations.DurationFormat.SHORT);
+ private String formatMeasure(@Nullable MeasureDto measure) {
+ if (measure != null) {
+ Metric metric = CoreMetrics.getMetric(measure.getKey().metricKey());
+ Metric.ValueType metricType = metric.getType();
+ Double value = measure.getValue();
+ String data = measure.getData();
+
+ if (metricType.equals(Metric.ValueType.FLOAT) && value != null) {
+ return i18n.formatDouble(UserSession.get().locale(), value);
+ }
+ if (metricType.equals(Metric.ValueType.INT) && value != null) {
+ return i18n.formatInteger(UserSession.get().locale(), value.intValue());
+ }
+ if (metricType.equals(Metric.ValueType.PERCENT) && value != null) {
+ return i18n.formatDouble(UserSession.get().locale(), value) + "%";
+ }
+ if (metricType.equals(Metric.ValueType.WORK_DUR) && value != null) {
+ return durations.format(UserSession.get().locale(), durations.create(value.longValue()), Durations.DurationFormat.SHORT);
+ }
+ if ((metricType.equals(Metric.ValueType.STRING) || metricType.equals(Metric.ValueType.RATING)) && data != null) {
+ return data;
+ }
}
return null;
}
@CheckForNull
- private String formatVariation(Double value, Metric.ValueType metricType) {
- if (metricType.equals(Metric.ValueType.FLOAT) || metricType.equals(Metric.ValueType.PERCENT)) {
- return i18n.formatDouble(UserSession.get().locale(), value);
- }
- if (metricType.equals(Metric.ValueType.INT)) {
- return i18n.formatInteger(UserSession.get().locale(), value.intValue());
- }
- if (metricType.equals(Metric.ValueType.WORK_DUR)) {
- return durations.format(UserSession.get().locale(), durations.create(value.longValue()), Durations.DurationFormat.SHORT);
+ private String formatVariation(@Nullable MeasureDto measure, Integer periodIndex) {
+ if (measure != null) {
+ Double variation = measure.getVariation(periodIndex);
+ if (variation != null) {
+ Metric metric = CoreMetrics.getMetric(measure.getKey().metricKey());
+ Metric.ValueType metricType = metric.getType();
+ if (metricType.equals(Metric.ValueType.FLOAT) || metricType.equals(Metric.ValueType.PERCENT)) {
+ return i18n.formatDouble(UserSession.get().locale(), variation);
+ }
+ if (metricType.equals(Metric.ValueType.INT)) {
+ return i18n.formatInteger(UserSession.get().locale(), variation.intValue());
+ }
+ if (metricType.equals(Metric.ValueType.WORK_DUR)) {
+ return durations.format(UserSession.get().locale(), durations.create(variation.longValue()), Durations.DurationFormat.SHORT);
+ }
+ }
}
return null;
}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-app.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-app.json
index a04bad19e9d..8070e3d3df2 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-app.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/components-example-app.json
@@ -47,7 +47,10 @@
"fNcloc": "12",
"fDebt": "4h",
"fIssues": "4",
- "fInfoIssues": "4"
+ "fInfoIssues": "4",
+ "fDuplicationDensity": "1.2",
+ "fSqaleRating" : "C",
+ "fSqaleDebtRatio" : "35.0%"
},
"extensions": [
["metricsTab", "Metrics"]
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentAppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentAppActionTest.java
index 9a0f822eef3..25ee502d97a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentAppActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentAppActionTest.java
@@ -206,6 +206,8 @@ public class ComponentAppActionTest {
addMeasure(CoreMetrics.NCLOC_KEY, 200);
addMeasure(CoreMetrics.COVERAGE_KEY, 95.4);
addMeasure(CoreMetrics.DUPLICATED_LINES_DENSITY_KEY, 7.4);
+ addMeasure(CoreMetrics.SQALE_RATING_KEY, "C");
+ addMeasure(CoreMetrics.SQALE_DEBT_RATIO_KEY, 35d);
measures.add(MeasureDto.createFor(MeasureKey.of(COMPONENT_KEY, CoreMetrics.TECHNICAL_DEBT_KEY)).setValue(182.0));
when(durations.format(any(Locale.class), any(Duration.class), eq(Durations.DurationFormat.SHORT))).thenReturn("3h 2min");
@@ -227,6 +229,7 @@ public class ComponentAppActionTest {
addVariationMeasure(CoreMetrics.NCLOC_KEY, 2, 1);
addVariationMeasure(CoreMetrics.COVERAGE_KEY, 5d, 1);
addVariationMeasure(CoreMetrics.DUPLICATED_LINES_DENSITY_KEY, 1.2, 1);
+ addVariationMeasure(CoreMetrics.SQALE_DEBT_RATIO_KEY, 5d, 1);
measures.add(MeasureDto.createFor(MeasureKey.of(COMPONENT_KEY, CoreMetrics.TECHNICAL_DEBT_KEY)).setVariation(1, 10.0));
when(durations.format(any(Locale.class), any(Duration.class), eq(Durations.DurationFormat.SHORT))).thenReturn("10min");
@@ -463,6 +466,10 @@ public class ComponentAppActionTest {
when(i18n.formatDouble(any(Locale.class), eq(value))).thenReturn(Double.toString(value));
}
+ private void addMeasure(String metricKey, String value) {
+ measures.add(MeasureDto.createFor(MeasureKey.of(COMPONENT_KEY, metricKey)).setTextValue(value));
+ }
+
private void addVariationMeasure(String metricKey, Integer value, Integer periodIndex) {
measures.add(MeasureDto.createFor(MeasureKey.of(COMPONENT_KEY, metricKey)).setVariation(periodIndex, value.doubleValue()));
when(i18n.formatInteger(any(Locale.class), eq(value))).thenReturn(Integer.toString(value));
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures.json b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures.json
index 8f26dd9621c..e9d2d29c52f 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures.json
@@ -19,7 +19,9 @@
"fNcloc": "200",
"fCoverage": "95.4%",
"fDuplicationDensity": "7.4%",
- "fDebt": "3h 2min"
+ "fDebt": "3h 2min",
+ "fSqaleRating" : "C",
+ "fSqaleDebtRatio" : "35.0%"
},
"tabs": [
"coverage"
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures_when_period_is_set.json b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures_when_period_is_set.json
index cce534b0462..41501a758ab 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures_when_period_is_set.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/ComponentAppActionTest/app_with_measures_when_period_is_set.json
@@ -21,7 +21,8 @@
"fNcloc": "2",
"fCoverage": "5.0",
"fDuplicationDensity": "1.2",
- "fDebt": "10min"
+ "fDebt": "10min",
+ "fSqaleDebtRatio" : "5.0"
},
"tabs": [
"coverage"