diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-01-27 17:34:28 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-01-27 17:34:39 +0100 |
commit | 6420445cad9acb42bf465e008124abd3ffb7c0ae (patch) | |
tree | 49b56a04d90791a72c4f779c6e0fa8ed24d8132a | |
parent | 332dadd8f5c261c87266783a71777b2cdbb0ff3b (diff) | |
download | sonarqube-6420445cad9acb42bf465e008124abd3ffb7c0ae.tar.gz sonarqube-6420445cad9acb42bf465e008124abd3ffb7c0ae.zip |
SourcesShowWS : Do not repeat scm data if it's not necessary
4 files changed, 46 insertions, 4 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java b/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java index b89f64d02c5..e087f62bf46 100644 --- a/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java @@ -78,6 +78,9 @@ public class SourcesShowWsHandler implements RequestHandler { json.name("scm").beginObject(); List<String> authors = splitLine(authorData); List<String> dates = splitLine(scmDateData); + + String previousAuthor = null; + String previousDate = null; for (int i = 0; i < authors.size(); i++) { String[] authorWithLine = splitColumn(authors.get(i)); Integer line = Integer.parseInt(authorWithLine[0]); @@ -86,12 +89,16 @@ public class SourcesShowWsHandler implements RequestHandler { String[] dateWithLine = splitColumn(dates.get(i)); String date = dateWithLine[1]; String formattedDate = DateUtils.formatDate(DateUtils.parseDateTime(date)); - if (line >= from && line <= to) { + if (!author.equals(previousAuthor) && !date.equals(previousDate) && + line >= from && line <= to) { json.name(Integer.toString(line)).beginArray(); json.value(author); json.value(formattedDate); json.endArray(); } + + previousAuthor = author; + previousDate = date; } json.endObject(); } diff --git a/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java index 7185b9121f0..aec87ed9dd1 100644 --- a/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java @@ -114,11 +114,27 @@ public class SourcesShowWsHandlerTest { "public class <span class=\"sym-31 sym\">HelloWorld</span> {" )); when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)) - .thenReturn("1=julien;2=simon;3=julien;4=simon;5=simon;6=julien"); + .thenReturn("1=julien;2=simon;3=julien;4=simon;5=jean;6=julien"); when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)) - .thenReturn("1=2013-03-13T16:22:31+0100;2=2013-03-14T16:22:31+0100;3=2013-03-13T16:22:31+0100;4=2013-03-14T16:22:31+0100;5=2013-03-14T16:22:31+0100;6=2013-03-13T16:22:31+0100;"); + .thenReturn("1=2013-03-13T16:22:31+0100;2=2013-03-14T16:22:31+0100;3=2013-03-13T16:22:31+0100;4=2013-03-14T16:22:31+0100;5=2013-03-15T16:22:31+0100;6=2013-03-13T16:22:31+0100;"); WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5"); request.execute().assertJson(getClass(), "show_source_with_scm_with_from_and_to_params.json"); } + + @Test + public void show_source_with_scm_without_repeating_same_lines() throws Exception { + String componentKey = "org.apache.struts:struts:Dispatcher"; + when(sourceService.sourcesFromComponent(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList( + " */", + "", + "public class <span class=\"sym-31 sym\">HelloWorld</span> {" + )); + when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)) + .thenReturn("1=julien;2=julien;3=simon"); + when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)) + .thenReturn("1=2013-03-13T16:22:31+0100;2=2013-03-13T16:22:31+0100;3=2013-03-14T16:22:31+0100;"); + WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey); + request.execute().assertJson(getClass(), "show_source_with_scm_without_repeating_same_lines.json"); + } } diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json index 5decae55c4b..a4540521bdc 100644 --- a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json +++ b/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json @@ -7,7 +7,7 @@ "scm": { "3": ["julien", "2013-03-13"], "4": ["simon", "2013-03-14"], - "5": ["simon", "2013-03-14"] + "5": ["jean", "2013-03-15"] } } diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines.json new file mode 100644 index 00000000000..ae74340195c --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines.json @@ -0,0 +1,19 @@ +{ + "source": { + "1": " */", + "2": "", + "3": "public class <span class=\"sym-31 sym\">HelloWorld</span> {" + }, + "scm": { + "1": ["julien", "2013-03-13"], + "3": ["simon", "2013-03-14"] + } +} + + + + + + + + |