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;
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();
}
}
}
private List<String> splitLine(String line){
- return newArrayList(Splitter.on(";").split(line));
+ return newArrayList(Splitter.on(";").omitEmptyStrings().split(line));
}
private String[] splitColumn(String column){
"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");
));
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");