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 import org.apache.regexp.RE;
27 import org.apache.regexp.RESyntaxException;
28
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.TimeZone;
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 String LINE_PATTERN = "(\\d+) (.*) \\((\\d+)\\) (\\d+-\\d+-\\d+) (.*)";
51
52
53
54
55 private RE lineRegexp;
56
57 private List<BlameLine> fLines = new ArrayList<BlameLine>();
58
59 private SimpleDateFormat dateFormat;
60
61
62
63
64
65
66
67 public JazzBlameConsumer( ScmProviderRepository repository, ScmLogger logger )
68 {
69 super( repository, logger );
70
71 dateFormat = new SimpleDateFormat( JAZZ_TIMESTAMP_PATTERN );
72 dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
73
74 try
75 {
76 lineRegexp = new RE( LINE_PATTERN );
77 }
78 catch ( RESyntaxException ex )
79 {
80 throw new RuntimeException(
81 "INTERNAL ERROR: Could not create regexp to parse jazz scm blame output. This shouldn't happen. Something is probably wrong with the oro installation.",
82 ex );
83 }
84 }
85
86
87
88
89
90
91
92 public void consumeLine( String line )
93 {
94 super.consumeLine( line );
95
96 if ( lineRegexp.match( line ) )
97 {
98 String lineNumberStr = lineRegexp.getParen( 1 );
99 String owner = lineRegexp.getParen( 2 );
100 String changeSetNumberStr = lineRegexp.getParen( 3 );
101 String dateStr = lineRegexp.getParen( 4 );
102 Date date = parseDate( dateStr, JAZZ_TIMESTAMP_PATTERN, null );
103 fLines.add( new BlameLine( date, changeSetNumberStr, owner ) );
104 }
105 }
106
107 public List<BlameLine> getLines()
108 {
109 return fLines;
110 }
111 }