1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.hg.command.blame;
20
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.Locale;
25
26 import org.apache.maven.scm.ScmFileStatus;
27 import org.apache.maven.scm.command.blame.BlameLine;
28 import org.apache.maven.scm.provider.hg.command.HgConsumer;
29
30
31
32
33
34
35 public class HgBlameConsumer extends HgConsumer {
36 private final List<BlameLine> lines = new ArrayList<>();
37
38 private static final String HG_TIMESTAMP_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z";
39
40 public void doConsume(ScmFileStatus status, String trimmedLine) {
41
42 String annotation;
43 if (trimmedLine.indexOf(": ") > -1) {
44 annotation = trimmedLine.substring(0, trimmedLine.indexOf(": ")).trim();
45 } else {
46 annotation = trimmedLine.substring(0, trimmedLine.lastIndexOf(":")).trim();
47 }
48
49 String author = annotation.substring(0, annotation.indexOf(' '));
50 annotation = annotation.substring(annotation.indexOf(' ') + 1).trim();
51
52 String revision = annotation.substring(0, annotation.indexOf(' '));
53 annotation = annotation.substring(annotation.indexOf(' ') + 1).trim();
54
55 String dateStr = annotation;
56 Date dateTime = parseDate(dateStr, null, HG_TIMESTAMP_PATTERN, Locale.ENGLISH);
57
58 lines.add(new BlameLine(dateTime, revision, author));
59 }
60
61 public List<BlameLine> getLines() {
62 return lines;
63 }
64 }