1 package org.apache.maven.scm.provider.accurev.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Date;
23 import java.util.List;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 import org.apache.maven.scm.command.blame.BlameLine;
28 import org.apache.maven.scm.log.ScmLogger;
29 import org.apache.maven.scm.provider.accurev.AccuRev;
30 import org.apache.maven.scm.util.AbstractConsumer;
31
32
33
34
35
36
37 public class AnnotateConsumer
38 extends AbstractConsumer
39 {
40
41
42 private static final Pattern LINE_PATTERN = Pattern.compile( "^\\s+(\\d+)\\s+(\\w+)\\s+([0-9/]+ [0-9:]+).*" );
43
44 private List<BlameLine> lines;
45
46 public AnnotateConsumer( List<BlameLine> lines, ScmLogger scmLogger )
47 {
48
49 super( scmLogger );
50 this.lines = lines;
51 }
52
53 public void consumeLine( String line )
54 {
55
56 final Matcher matcher = LINE_PATTERN.matcher( line );
57 if ( matcher.matches() )
58 {
59 String revision = matcher.group( 1 ).trim();
60 String author = matcher.group( 2 ).trim();
61 String dateStr = matcher.group( 3 ).trim();
62
63 Date date = parseDate( dateStr, null, AccuRev.ACCUREV_TIME_FORMAT_STRING );
64
65 lines.add( new BlameLine( date, revision, author ) );
66 }
67 else
68 {
69 throw new RuntimeException( "Unable to parse annotation from line: " + line );
70 }
71 }
72
73 public List<BlameLine> getLines()
74 {
75
76 return lines;
77 }
78 }