aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-07-15 15:01:30 +0200
committerGitHub <noreply@github.com>2016-07-15 15:01:30 +0200
commitfedaff73566aa885eb2151d2470a0549ea584c28 (patch)
tree0682a485541b986055c37c6100c8a31b01777da2
parent0f8478f0b413b2a2b4905462342d71183e8eb755 (diff)
downloadsonarqube-fedaff73566aa885eb2151d2470a0549ea584c28.tar.gz
sonarqube-fedaff73566aa885eb2151d2470a0549ea584c28.zip
SONAR-7888 Do not format measures in WS api/components/app (#1103)
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java27
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsTest.java2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_it_measure.json2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_measures.json9
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_overall_measure.json2
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_ut_measure.json2
-rw-r--r--server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer-header.hbs10
8 files changed, 15 insertions, 53 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java
index 02778a73f4c..3152632cd18 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/AppAction.java
@@ -27,14 +27,12 @@ import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.BooleanUtils;
-import org.sonar.api.i18n.I18n;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.Durations;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
@@ -63,15 +61,11 @@ public class AppAction implements RequestHandler {
private final DbClient dbClient;
- private final Durations durations;
- private final I18n i18n;
private final UserSession userSession;
private final ComponentFinder componentFinder;
- public AppAction(DbClient dbClient, Durations durations, I18n i18n, UserSession userSession, ComponentFinder componentFinder) {
+ public AppAction(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder) {
this.dbClient = dbClient;
- this.durations = durations;
- this.i18n = i18n;
this.userSession = userSession;
this.componentFinder = componentFinder;
}
@@ -163,9 +157,6 @@ public class AppAction implements RequestHandler {
json.prop("duplicationDensity", formatMeasure(measuresByMetricKey, CoreMetrics.DUPLICATED_LINES_DENSITY));
json.prop("issues", formatMeasure(measuresByMetricKey, CoreMetrics.VIOLATIONS));
json.prop("tests", formatMeasure(measuresByMetricKey, CoreMetrics.TESTS));
- json.prop("debt", formatMeasure(measuresByMetricKey, CoreMetrics.TECHNICAL_DEBT));
- json.prop("sqaleRating", formatMeasure(measuresByMetricKey, CoreMetrics.SQALE_RATING));
- json.prop("debtRatio", formatMeasure(measuresByMetricKey, CoreMetrics.SQALE_DEBT_RATIO));
json.endObject();
}
@@ -210,23 +201,9 @@ public class AppAction implements RequestHandler {
if (measure == null) {
return null;
}
- Metric.ValueType metricType = metric.getType();
Double value = getDoubleValue(measure, metric);
- String data = measure.getData();
if (value != null) {
- switch (metricType) {
- case FLOAT:
- return i18n.formatDouble(userSession.locale(), value);
- case INT:
- return i18n.formatInteger(userSession.locale(), value.intValue());
- case PERCENT:
- return i18n.formatDouble(userSession.locale(), value) + "%";
- case WORK_DUR:
- return durations.format(userSession.locale(), durations.create(value.longValue()), Durations.DurationFormat.SHORT);
- }
- }
- if ((metricType.equals(Metric.ValueType.STRING) || metricType.equals(Metric.ValueType.RATING)) && data != null) {
- return data;
+ return Double.toString(value);
}
return null;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
index cbe6c54ab83..8c7f3cbba6e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
@@ -26,10 +26,7 @@ import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.i18n.I18n;
import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.Durations;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbTester;
@@ -41,15 +38,11 @@ import org.sonar.db.measure.MeasureDto;
import org.sonar.db.measure.MeasureTesting;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.i18n.I18nRule;
import org.sonar.server.startup.RegisterMetrics;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class AppActionTest {
@@ -69,17 +62,13 @@ public class AppActionTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private I18n i18n = new I18nRule();
-
- private Durations durations = mock(Durations.class);
-
private WsTester wsTester;
@Before
public void setUp() {
insertMetrics();
wsTester = new WsTester(new ComponentsWs(
- new AppAction(dbTester.getDbClient(), durations, i18n, userSessionRule, new ComponentFinder(dbTester.getDbClient())), mock(SearchViewComponentsAction.class)));
+ new AppAction(dbTester.getDbClient(), userSessionRule, new ComponentFinder(dbTester.getDbClient())), mock(SearchViewComponentsAction.class)));
}
@Test
@@ -107,7 +96,6 @@ public class AppActionTest {
.login("john")
.setLocale(Locale.ENGLISH)
.addComponentPermission(UserRole.USER, PROJECT_KEY, FILE_KEY);
- when(durations.format(eq(Locale.ENGLISH), any(Duration.class), any())).thenReturn("3h 2min");
WsTester.TestRequest request = wsTester.newGetRequest("api/components", "app").setParam("uuid", FILE_UUID);
request.execute().assertJson(getClass(), "app_with_measures.json");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsTest.java
index cd5792c53aa..7a842bdc9af 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ComponentsWsTest.java
@@ -51,7 +51,7 @@ public class ComponentsWsTest {
when(languages.all()).thenReturn(new Language[0]);
WsTester tester = new WsTester(new ComponentsWs(
- new AppAction(mock(DbClient.class), mock(Durations.class), mock(I18n.class), userSessionRule, mock(ComponentFinder.class)),
+ new AppAction(mock(DbClient.class), userSessionRule, mock(ComponentFinder.class)),
new SearchViewComponentsAction(mock(DbClient.class), userSessionRule, mock(ComponentFinder.class)),
new SearchAction(mock(org.sonar.db.DbClient.class), mock(ResourceTypes.class), mock(I18n.class), userSessionRule, languages)
));
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_it_measure.json b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_it_measure.json
index d521f057ba9..5f762d5176e 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_it_measure.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_it_measure.json
@@ -12,6 +12,6 @@
"fav": false,
"canMarkAsFavourite": true,
"measures": {
- "coverage": "85.2%"
+ "coverage": "85.2"
}
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_measures.json b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_measures.json
index eb7b7630c1c..f50715b4b2c 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_measures.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_measures.json
@@ -12,11 +12,8 @@
"fav": false,
"canMarkAsFavourite": true,
"measures": {
- "lines": "200",
- "coverage": "95.4%",
- "duplicationDensity": "7.4%",
- "debt": "3h 2min",
- "sqaleRating": "C",
- "debtRatio": "35.0%"
+ "lines": "200.0",
+ "coverage": "95.4",
+ "duplicationDensity": "7.4"
}
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_overall_measure.json b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_overall_measure.json
index d8418a1c871..9fb8d6855cb 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_overall_measure.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_overall_measure.json
@@ -12,6 +12,6 @@
"fav": false,
"canMarkAsFavourite": true,
"measures": {
- "coverage": "90.1%"
+ "coverage": "90.1"
}
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_ut_measure.json b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_ut_measure.json
index 36b40eb9256..59b6db6325a 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_ut_measure.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/component/ws/AppActionTest/app_with_ut_measure.json
@@ -12,6 +12,6 @@
"fav": false,
"canMarkAsFavourite": true,
"measures": {
- "coverage": "95.4%"
+ "coverage": "95.4"
}
}
diff --git a/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer-header.hbs b/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer-header.hbs
index 2d012cfe8c2..e276c7e938b 100644
--- a/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer-header.hbs
+++ b/server/sonar-web/src/main/js/components/source-viewer/templates/source-viewer-header.hbs
@@ -34,14 +34,14 @@
<div class="source-viewer-header-measures">
{{#if isUnitTest}}
<div class="source-viewer-header-measure">
- <span class="source-viewer-header-measure-value">{{measures.tests}}</span>
+ <span class="source-viewer-header-measure-value">{{formatMeasure measures.tests 'SHORT_INT'}}</span>
<span class="source-viewer-header-measure-label">{{t 'metric.tests.name'}}</span>
</div>
{{/if}}
{{#unless isUnitTest}}
<div class="source-viewer-header-measure">
- <span class="source-viewer-header-measure-value">{{default measures.lines}}</span>
+ <span class="source-viewer-header-measure-value">{{formatMeasure measures.lines 'SHORT_INT'}}</span>
<span class="source-viewer-header-measure-label">{{t 'metric.lines.name'}}</span>
</div>
{{/unless}}
@@ -50,7 +50,7 @@
<span class="source-viewer-header-measure-value">
<a class="source-viewer-header-external-link" target="_blank"
href="{{link '/issues/search#resolved=false|fileUuids=' uuid}}">
- {{default measures.issues 0}}&nbsp;<i class="icon-detach"></i>
+ {{#if measures.issues}}{{formatMeasure measures.issues 'SHORT_INT'}}{{else}}0{{/if}}&nbsp;<i class="icon-detach"></i>
</a>
</span>
<span class="source-viewer-header-measure-label">{{t 'metric.violations.name'}}</span>
@@ -58,14 +58,14 @@
{{#notNull measures.coverage}}
<div class="source-viewer-header-measure">
- <span class="source-viewer-header-measure-value">{{default measures.coverage}}</span>
+ <span class="source-viewer-header-measure-value">{{formatMeasure measures.coverage 'PERCENT'}}</span>
<span class="source-viewer-header-measure-label">{{t 'metric.coverage.name'}}</span>
</div>
{{/notNull}}
{{#notNull measures.duplicationDensity}}
<div class="source-viewer-header-measure">
- <span class="source-viewer-header-measure-value">{{default measures.duplicationDensity}}</span>
+ <span class="source-viewer-header-measure-value">{{formatMeasure measures.duplicationDensity 'PERCENT'}}</span>
<span class="source-viewer-header-measure-label">{{t 'duplications'}}</span>
</div>
{{/notNull}}