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.changelog;
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.ChangeFile;
27 import org.apache.maven.scm.ChangeSet;
28 import org.apache.maven.scm.ScmFileStatus;
29 import org.apache.maven.scm.provider.hg.command.HgConsumer;
30
31
32
33
34
35 public class HgChangeLogConsumer extends HgConsumer {
36
37 private static final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss Z";
38
39 private static final String REVNO_TAG = "changeset:";
40
41 private static final String TAG_TAG = "tag:";
42
43 private static final String BRANCH_TAG = "branch:";
44
45 private static final String AUTHOR_TAG = "user:";
46
47 private static final String TIME_STAMP_TOKEN = "date:";
48
49 private static final String MESSAGE_TOKEN = "description:";
50
51 private static final String FILES_TOKEN = "files:";
52
53 private List<ChangeSet> logEntries = new ArrayList<>();
54
55 private ChangeSet currentChange;
56
57 private String currentRevision;
58
59 @SuppressWarnings("unused")
60 private String currentBranch;
61
62 private String userDatePattern;
63
64 public HgChangeLogConsumer(String userDatePattern) {
65 this.userDatePattern = userDatePattern;
66 }
67
68 public List<ChangeSet> getModifications() {
69 return logEntries;
70 }
71
72
73
74
75 public void consumeLine(String line) {
76
77
78 String trimmedLine = line.trim();
79 doConsume(null, trimmedLine);
80 }
81
82
83
84
85 public void doConsume(ScmFileStatus status, String line) {
86 String tmpLine;
87
88
89 if (line.startsWith(REVNO_TAG)) {
90
91 currentChange = new ChangeSet();
92 currentChange.setFiles(new ArrayList<>(0));
93 logEntries.add(currentChange);
94
95
96 tmpLine = line.substring(REVNO_TAG.length()).trim();
97 currentRevision = tmpLine.substring(tmpLine.indexOf(':') + 1);
98 currentChange.setRevision(currentRevision);
99 } else if (line.startsWith(BRANCH_TAG)) {
100 tmpLine = line.substring(BRANCH_TAG.length()).trim();
101 currentBranch = tmpLine;
102 } else if (line.startsWith(AUTHOR_TAG)) {
103 tmpLine = line.substring(AUTHOR_TAG.length()).trim();
104 currentChange.setAuthor(tmpLine);
105 } else if (line.startsWith(TIME_STAMP_TOKEN)) {
106 tmpLine = line.substring(TIME_STAMP_TOKEN.length()).trim();
107 Date date = parseDate(tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH);
108 currentChange.setDate(date);
109 } else if (line.startsWith(TAG_TAG)) {
110 tmpLine = line.substring(TAG_TAG.length()).trim();
111 currentChange.addTag(tmpLine);
112 } else if (line.startsWith(FILES_TOKEN)) {
113 tmpLine = line.substring(FILES_TOKEN.length()).trim();
114 String[] files = tmpLine.split(" ");
115 for (int i = 0; i < files.length; i++) {
116 String file = files[i];
117 ChangeFile changeFile = new ChangeFile(file, currentRevision);
118 currentChange.addFile(changeFile);
119 }
120 } else if (line.startsWith(MESSAGE_TOKEN)) {
121 currentChange.setComment("");
122 } else {
123 StringBuilder comment = new StringBuilder(currentChange.getComment());
124 comment.append(line);
125 currentChange.setComment(comment.toString());
126 }
127 }
128 }