* @throws java.io.IOException If an error occurs while reading the stream
*/
@Override
public void processStream(InputStream input) throws IOException {
DateFormat df = repository.getDateFormat();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
String s;
HistoryEntry entry = null;
int state = 0;
while ((s = in.readLine()) != null) {
if ("------------------------------------------------------------".equals(s)) {
if (entry != null && state > 2) {
entries.add(entry);
}
entry = new HistoryEntry();
entry.setActive(true);
state = 0;
continue;
}
switch (state) {
case 0:
// First, go on until revno is found.
if (s.startsWith("revno:")) {
String rev[] = s.substring("revno:".length()).trim().split(" ");
entry.setRevision(rev[0]);
++state;
}
break;
case 1:
// Then, look for committer.
if (s.startsWith("committer:")) {
entry.setAuthor(s.substring("committer:".length()).trim());
++state;
}
break;
case 2:
// And then, look for timestamp.
if (s.startsWith("timestamp:")) {
try {
Date date = df.parse(s.substring("timestamp:".length()).trim());
entry.setDate(date);
} catch (ParseException e) {
OpenGrokLogger.getLogger().log(Level.WARNING,
"Failed to parse history timestamp:" + s, e);
}
++state;
}
break;
case 3:
// Expect the commit message to follow immediately after
// the timestamp, and that everything up to the list of
// modified, added and removed files is part of the commit
// message.
if (s.startsWith("modified:") || s.startsWith("added:") || s.startsWith("removed:")) {
++state;
} else if (s.startsWith(" ")) {
// Commit messages returned by bzr log -v are prefixed
// with two blanks.
entry.appendMessage(s.substring(2));
}
break;
case 4:
// Finally, store the list of modified, added and removed
// files. (Except the labels.)
if (!(s.startsWith("modified:") || s.startsWith("added:") || s.startsWith("removed:"))) {
// The list of files is prefixed with blanks.
s = s.trim();
int idx = s.indexOf(" => ");
if (idx != -1) {
s = s.substring(idx + 4);
}
File f = new File(myDir, s);
String name = env.getPathRelativeToSourceRoot(f, 0);
entry.addFile(name);
}
break;
default:
OpenGrokLogger.getLogger().warning("Unknown parser state: " + state);