aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java2
8 files changed, 75 insertions, 53 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"
diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java
index 458b1d27eb0..41b2af1fafa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java
@@ -76,7 +76,7 @@ public final class SqaleRatingDecorator implements Decorator {
@DependedUpon
public List<Metric> generatesMetrics() {
- return Lists.<Metric>newArrayList(CoreMetrics.RATING, CoreMetrics.DEVELOPMENT_COST, CoreMetrics.SQALE_DEBT_RATIO);
+ return Lists.<Metric>newArrayList(CoreMetrics.SQALE_RATING, CoreMetrics.DEVELOPMENT_COST, CoreMetrics.SQALE_DEBT_RATIO);
}
public void decorate(Resource resource, DecoratorContext context) {
@@ -94,7 +94,7 @@ public final class SqaleRatingDecorator implements Decorator {
}
private Measure createRatingMeasure(int rating) {
- return new Measure(CoreMetrics.RATING).setIntValue(rating).setData(toRatingLetter(rating));
+ return new Measure(CoreMetrics.SQALE_RATING).setIntValue(rating).setData(toRatingLetter(rating));
}
static String toRatingLetter(@Nullable Integer rating) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
index 48a58f4a050..1b1840a8443 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
@@ -119,7 +119,7 @@ public class SqaleRatingDecoratorTest {
when(context.getMeasure(CoreMetrics.TECHNICAL_DEBT)).thenReturn(new Measure(CoreMetrics.TECHNICAL_DEBT, 300.0 * ONE_DAY_IN_MINUTES));
decorator.decorate(file, context);
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 3.0)));
+ verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.SQALE_RATING, 3.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 1500d);
@@ -137,7 +137,7 @@ public class SqaleRatingDecoratorTest {
when(context.getMeasure(CoreMetrics.TECHNICAL_DEBT)).thenReturn(new Measure(CoreMetrics.TECHNICAL_DEBT, 0.0));
decorator.decorate(file, context);
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 1.0)));
+ verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.SQALE_RATING, 1.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 0d);
@@ -155,7 +155,7 @@ public class SqaleRatingDecoratorTest {
when(context.getMeasure(CoreMetrics.TECHNICAL_DEBT)).thenReturn(new Measure(CoreMetrics.TECHNICAL_DEBT, 960000.0));
decorator.decorate(file, context);
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 5.0)));
+ verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.SQALE_RATING, 5.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 10000d);
@@ -171,7 +171,7 @@ public class SqaleRatingDecoratorTest {
when(context.getChildrenMeasures(CoreMetrics.DEVELOPMENT_COST)).thenReturn(newArrayList(new Measure(CoreMetrics.DEVELOPMENT_COST, Double.toString(20.0 * ONE_DAY_IN_MINUTES))));
decorator.decorate(mock(File.class), context);
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 3.0)));
+ verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.SQALE_RATING, 3.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 1500d);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
index 2545bd0699a..dc72077af41 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
@@ -2130,7 +2130,7 @@ public final class CoreMetrics {
/**
* @since 4.5
*/
- public static final Metric<String> RATING = new Metric.Builder(SQALE_RATING_KEY, "SQALE Rating", Metric.ValueType.RATING)
+ public static final Metric<String> SQALE_RATING = new Metric.Builder(SQALE_RATING_KEY, "SQALE Rating", Metric.ValueType.RATING)
.setDomain(DOMAIN_TECHNICAL_DEBT)
.setDirection(Metric.DIRECTION_WORST)
.setQualitative(true)