587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.maven.scm.provider.hg.command.log;
|
|
19 |
|
628
|
20 |
import java.text.ParseException;
|
|
21 |
import java.text.SimpleDateFormat;
|
|
22 |
import java.util.ArrayList;
|
|
23 |
import java.util.Date;
|
|
24 |
import java.util.List;
|
587
|
25 |
|
628
|
26 |
import org.apache.maven.scm.ChangeFile;
|
|
27 |
import org.apache.maven.scm.ScmBranch;
|
587
|
28 |
import org.apache.maven.scm.ScmException;
|
628
|
29 |
import org.apache.maven.scm.ScmFileStatus;
|
|
30 |
import org.apache.maven.scm.ScmRevision;
|
587
|
31 |
import org.apache.maven.scm.ScmTag;
|
|
32 |
import org.apache.maven.scm.log.ScmLogger;
|
|
33 |
import org.apache.maven.scm.provider.hg.command.HgConsumer;
|
|
34 |
|
628
|
35 |
import com.nokia.maven.scm.provider.hg.VersionChangeSet;
|
587
|
36 |
|
|
37 |
/**
|
|
38 |
* Consumer of 'hg changelog' command output.
|
|
39 |
*/
|
|
40 |
public class HgChangeLogConsumer extends HgConsumer {
|
|
41 |
|
|
42 |
private static final String TIME_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z";
|
|
43 |
|
|
44 |
private static final String REVNO_TAG = "changeset: ";
|
|
45 |
|
|
46 |
private static final String TAG_BRANCH = "branch: ";
|
|
47 |
|
|
48 |
private static final String TAG_TAG = "tag: ";
|
|
49 |
|
|
50 |
private static final String AUTHOR_TAG = "user: ";
|
|
51 |
|
|
52 |
private static final String TIME_STAMP_TOKEN = "date: ";
|
|
53 |
|
|
54 |
private static final String MESSAGE_TOKEN = "description:";
|
|
55 |
|
|
56 |
private static final String MERGED_TOKEN = "merged: ";
|
|
57 |
|
|
58 |
private static final String FILES_TOKEN = "files: ";
|
|
59 |
|
|
60 |
private String prevLine = "";
|
|
61 |
|
|
62 |
private String prevPrevLine = "";
|
|
63 |
|
|
64 |
private ArrayList<VersionChangeSet> logEntries = new ArrayList<VersionChangeSet>();
|
|
65 |
|
|
66 |
private VersionChangeSet currentChange;
|
|
67 |
|
|
68 |
private VersionChangeSet lastChange;
|
|
69 |
|
|
70 |
private boolean isMergeEntry;
|
|
71 |
|
|
72 |
private String currentRevision;
|
|
73 |
|
|
74 |
private String currentTag; // don't know what to do with this
|
|
75 |
|
|
76 |
private String currentBranch;
|
|
77 |
|
|
78 |
private String userDatePattern;
|
|
79 |
|
|
80 |
private boolean spoolingComments;
|
|
81 |
|
|
82 |
private List<String> currentComment;
|
|
83 |
|
|
84 |
public HgChangeLogConsumer(ScmLogger logger, String userDatePattern) {
|
|
85 |
super(logger);
|
|
86 |
this.userDatePattern = userDatePattern;
|
|
87 |
}
|
|
88 |
|
|
89 |
public List<VersionChangeSet> getModifications() {
|
|
90 |
return logEntries;
|
|
91 |
}
|
|
92 |
|
|
93 |
/** {@inheritDoc} */
|
|
94 |
public void consumeLine(String line) {
|
|
95 |
|
|
96 |
// override default behavior which tries to pick through things for
|
|
97 |
// some standard messages. that
|
|
98 |
// does not apply here
|
|
99 |
doConsume(null, line);
|
|
100 |
}
|
|
101 |
|
|
102 |
/** {@inheritDoc} */
|
|
103 |
public void doConsume(ScmFileStatus status, String line) {
|
|
104 |
String tmpLine = line;
|
|
105 |
// If current status == null then this is a new entry
|
|
106 |
// If the line == "" and previous line was "", then this is also a new
|
|
107 |
// entry
|
|
108 |
if ((line.equals("") && (prevLine.equals("") && prevPrevLine.equals("")))
|
|
109 |
|| currentComment == null) {
|
|
110 |
if (currentComment != null) {
|
|
111 |
StringBuffer comment = new StringBuffer();
|
|
112 |
int i = 0;
|
|
113 |
for (String eachComment : currentComment) {
|
|
114 |
comment.append(eachComment);
|
|
115 |
if (i + 1 < currentComment.size() - 1) {
|
|
116 |
comment.append('\n');
|
|
117 |
}
|
|
118 |
i += 1;
|
|
119 |
}
|
|
120 |
currentChange.setComment(comment.toString());
|
|
121 |
}
|
|
122 |
|
|
123 |
spoolingComments = false;
|
|
124 |
|
|
125 |
// If last entry was part a merged entry
|
|
126 |
if (isMergeEntry && lastChange != null) {
|
|
127 |
String comment = lastChange.getComment();
|
|
128 |
comment += "\n[MAVEN]: Merged from "
|
|
129 |
+ currentChange.getAuthor();
|
|
130 |
comment += "\n[MAVEN]: " + currentChange.getDateFormatted();
|
|
131 |
comment += "\n[MAVEN]: " + currentChange.getComment();
|
|
132 |
lastChange.setComment(comment);
|
|
133 |
}
|
|
134 |
|
|
135 |
// Init a new changeset
|
|
136 |
currentChange = new VersionChangeSet();
|
|
137 |
currentChange.setFiles(new ArrayList<ChangeFile>());
|
|
138 |
logEntries.add(currentChange);
|
|
139 |
|
|
140 |
// Reset member vars
|
|
141 |
currentComment = new ArrayList<String>();
|
|
142 |
currentRevision = "";
|
|
143 |
isMergeEntry = false;
|
|
144 |
}
|
|
145 |
|
|
146 |
if (spoolingComments) {
|
|
147 |
currentComment.add(line);
|
|
148 |
} else if (line.startsWith(MESSAGE_TOKEN)) {
|
|
149 |
spoolingComments = true;
|
|
150 |
} else if (line.startsWith(MERGED_TOKEN)) {
|
|
151 |
// This is part of lastChange and is not a separate log entry
|
|
152 |
isMergeEntry = true;
|
|
153 |
logEntries.remove(currentChange);
|
|
154 |
if (logEntries.size() > 0) {
|
|
155 |
lastChange = logEntries.get(logEntries
|
|
156 |
.size() - 1);
|
|
157 |
} else {
|
|
158 |
getLogger().warn("First entry was unexpectedly a merged entry");
|
|
159 |
lastChange = null;
|
|
160 |
}
|
|
161 |
} else if (line.startsWith(REVNO_TAG)) {
|
|
162 |
tmpLine = line.substring(REVNO_TAG.length()).trim();
|
|
163 |
currentRevision = tmpLine;
|
|
164 |
try {
|
|
165 |
currentChange.setScmVersion(new ScmRevision(tmpLine));
|
|
166 |
} catch (ScmException se) {
|
|
167 |
getLogger().warn(se.getMessage());
|
|
168 |
}
|
|
169 |
} else if (line.startsWith(TAG_TAG)) {
|
|
170 |
tmpLine = line.substring(TAG_TAG.length()).trim();
|
|
171 |
currentTag = tmpLine;
|
|
172 |
try {
|
|
173 |
currentChange.setScmVersion(new ScmTag(tmpLine));
|
|
174 |
} catch (ScmException se) {
|
|
175 |
getLogger().warn(se.getMessage());
|
|
176 |
}
|
|
177 |
} else if (line.startsWith(TAG_BRANCH)) {
|
|
178 |
tmpLine = line.substring(TAG_BRANCH.length()).trim();
|
|
179 |
currentBranch = tmpLine;
|
|
180 |
try {
|
|
181 |
currentChange.setScmVersion(new ScmBranch(tmpLine));
|
|
182 |
} catch (ScmException se) {
|
|
183 |
getLogger().warn(se.getMessage());
|
|
184 |
}
|
|
185 |
} else if (line.startsWith(AUTHOR_TAG)) {
|
|
186 |
tmpLine = line.substring(AUTHOR_TAG.length());
|
|
187 |
tmpLine = tmpLine.trim();
|
|
188 |
currentChange.setAuthor(tmpLine);
|
|
189 |
} else if (line.startsWith(TIME_STAMP_TOKEN)) {
|
|
190 |
tmpLine = line.substring(TIME_STAMP_TOKEN.length()).trim();
|
|
191 |
Date date = null;
|
|
192 |
try {
|
|
193 |
SimpleDateFormat format = new SimpleDateFormat(TIME_PATTERN);
|
|
194 |
date = format.parse(tmpLine);
|
|
195 |
currentChange.setDate(date);
|
|
196 |
} catch (ParseException e) {
|
|
197 |
getLogger().warn(
|
|
198 |
"Consumer Change Log Date Format not supported:"
|
|
199 |
+ e.getMessage());
|
|
200 |
}
|
|
201 |
} else if (line.startsWith(FILES_TOKEN)) {
|
|
202 |
tmpLine = line.substring(FILES_TOKEN.length()).trim();
|
|
203 |
String[] files = tmpLine.split(" ");
|
|
204 |
for (String eachFile : files) {
|
|
205 |
ChangeFile changeFile = new ChangeFile(eachFile, currentRevision);
|
|
206 |
currentChange.addFile(changeFile);
|
|
207 |
}
|
|
208 |
} else {
|
|
209 |
if (!line.equals("")) {
|
|
210 |
getLogger().warn("Could not figure out: " + line);
|
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
// record previous line
|
|
215 |
prevLine = line;
|
|
216 |
prevPrevLine = prevLine;
|
|
217 |
}
|
|
218 |
}
|