]> source.dussan.org Git - sonarqube.git/commitdiff
SourcesShowWS : Add scm date
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 27 Jan 2014 16:23:58 +0000 (17:23 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 27 Jan 2014 16:34:39 +0000 (17:34 +0100)
sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java
sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java
sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm.json
sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json

index eda1fc926c401e670f84c57344d75da9dbb262ed..b89f64d02c518558bae85d8c37f999c69ce8ac34 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.measures.CoreMetrics;
 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.utils.DateUtils;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.source.SourceService;
@@ -76,13 +77,19 @@ public class SourcesShowWsHandler implements RequestHandler {
     if (authorData != null) {
       json.name("scm").beginObject();
       List<String> authors = splitLine(authorData);
+      List<String> dates = splitLine(scmDateData);
       for (int i = 0; i < authors.size(); i++) {
         String[] authorWithLine = splitColumn(authors.get(i));
         Integer line = Integer.parseInt(authorWithLine[0]);
         String author = authorWithLine[1];
+
+        String[] dateWithLine = splitColumn(dates.get(i));
+        String date = dateWithLine[1];
+        String formattedDate = DateUtils.formatDate(DateUtils.parseDateTime(date));
         if (line >= from && line <= to) {
           json.name(Integer.toString(line)).beginArray();
           json.value(author);
+          json.value(formattedDate);
           json.endArray();
         }
       }
@@ -91,7 +98,7 @@ public class SourcesShowWsHandler implements RequestHandler {
   }
 
   private List<String> splitLine(String line){
-    return newArrayList(Splitter.on(";").split(line));
+    return newArrayList(Splitter.on(";").omitEmptyStrings().split(line));
   }
 
   private String[] splitColumn(String column){
index f02b4c25cd13439aca9ea3f40b25adae257e0d5d..7185b9121f09d3eb1485a13858502043b0b72e89 100644 (file)
@@ -98,7 +98,8 @@ 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");
+    when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)).thenReturn("1=julien;");
+    when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)).thenReturn("1=2013-03-13T16:22:31+0100;");
 
     WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey);
     request.execute().assertJson(getClass(), "show_source_with_scm.json");
@@ -114,6 +115,8 @@ public class SourcesShowWsHandlerTest {
     ));
     when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY))
       .thenReturn("1=julien;2=simon;3=julien;4=simon;5=simon;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;");
 
     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");
index c9e2ac9f58bd7ac9aeb53a7d39d5f3b596f4c5f3..6e753092de69e5c7b98b3bfafc6444d17c2f8c9e 100644 (file)
@@ -3,8 +3,7 @@
     "1": "public class <span class=\"sym-31 sym\">HelloWorld</span> {}"
   },
   "scm": {
-    "1": ["julien"],
-    "2": ["simon"]
+    "1": ["julien", "2013-03-13"]
   }
 }
 
index 6990b66a865a25ed53b82dc355a9832b90b967f7..5decae55c4b99aebaed1e49375c8bb6b9f5c75d4 100644 (file)
@@ -5,9 +5,9 @@
     "5": "public class <span class=\"sym-31 sym\">HelloWorld</span> {"
   },
   "scm": {
-    "3": ["julien"],
-    "4": ["simon"],
-    "5": ["simon"]
+    "3": ["julien", "2013-03-13"],
+    "4": ["simon", "2013-03-14"],
+    "5": ["simon", "2013-03-14"]
   }
 }