1 package org.apache.maven.scm.provider.jazz.command.blame;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.command.blame.BlameLine;
23 import org.apache.maven.scm.log.ScmLogger;
24 import org.apache.maven.scm.provider.ScmProviderRepository;
25 import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer;
26
27 import java.text.SimpleDateFormat;
28 import java.util.ArrayList;
29 import java.util.Date;
30 import java.util.List;
31 import java.util.TimeZone;
32 import java.util.regex.Matcher;
33 import java.util.regex.Pattern;
34
35
36
37
38
39
40
41
42 public class JazzBlameConsumer
43 extends AbstractRepositoryConsumer
44 {
45 private static final String JAZZ_TIMESTAMP_PATTERN = "yyyy-MM-dd";
46
47
48
49
50 private static final Pattern LINE_PATTERN = Pattern.compile( "(\\d+) (.*) \\((\\d+)\\) (\\d+-\\d+-\\d+) (.*)" );
51
52 private List<BlameLine> fLines = new ArrayList<BlameLine>();
53
54 private SimpleDateFormat dateFormat;
55
56
57
58
59
60
61
62 public JazzBlameConsumer( ScmProviderRepository repository, ScmLogger logger )
63 {
64 super( repository, logger );
65
66 dateFormat = new SimpleDateFormat( JAZZ_TIMESTAMP_PATTERN );
67 dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
68 }
69
70
71
72
73
74
75
76 public void consumeLine( String line )
77 {
78 super.consumeLine( line );
79
80 Matcher matcher = LINE_PATTERN.matcher( line );
81 if ( matcher.matches() )
82 {
83 String lineNumberStr = matcher.group( 1 );
84 String owner = matcher.group( 2 );
85 String changeSetNumberStr = matcher.group( 3 );
86 String dateStr = matcher.group( 4 );
87 Date date = parseDate( dateStr, JAZZ_TIMESTAMP_PATTERN, null );
88 fLines.add( new BlameLine( date, changeSetNumberStr, owner ) );
89 }
90 }
91
92 public List<BlameLine> getLines()
93 {
94 return fLines;
95 }
96 }