1 package org.apache.maven.scm.provider.hg.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.Locale;
26
27 import org.apache.maven.scm.ChangeFile;
28 import org.apache.maven.scm.ChangeSet;
29 import org.apache.maven.scm.ScmFileStatus;
30 import org.apache.maven.scm.provider.hg.command.HgConsumer;
31
32
33
34
35
36 public class HgChangeLogConsumer
37 extends HgConsumer
38 {
39
40 private static final String TIME_PATTERN = "yyyy-MM-dd HH:mm:ss Z";
41
42 private static final String REVNO_TAG = "changeset:";
43
44 private static final String TAG_TAG = "tag:";
45
46 private static final String BRANCH_TAG = "branch:";
47
48 private static final String AUTHOR_TAG = "user:";
49
50 private static final String TIME_STAMP_TOKEN = "date:";
51
52 private static final String MESSAGE_TOKEN = "description:";
53
54 private static final String FILES_TOKEN = "files:";
55
56 private List<ChangeSet> logEntries = new ArrayList<ChangeSet>();
57
58 private ChangeSet currentChange;
59
60 private String currentRevision;
61
62 @SuppressWarnings( "unused" )
63 private String currentBranch;
64
65 private String userDatePattern;
66
67 public HgChangeLogConsumer( String userDatePattern )
68 {
69 this.userDatePattern = userDatePattern;
70 }
71
72 public List<ChangeSet> getModifications()
73 {
74 return logEntries;
75 }
76
77
78
79
80 public void consumeLine( String line )
81 {
82
83
84 String trimmedLine = line.trim();
85 doConsume( null, trimmedLine );
86 }
87
88
89
90
91 public void doConsume( ScmFileStatus status, String line )
92 {
93 String tmpLine;
94
95
96 if ( line.startsWith( REVNO_TAG ) )
97 {
98
99 currentChange = new ChangeSet();
100 currentChange.setFiles( new ArrayList<ChangeFile>( 0 ) );
101 logEntries.add( currentChange );
102
103
104 tmpLine = line.substring( REVNO_TAG.length() ).trim();
105 currentRevision = tmpLine.substring( tmpLine.indexOf( ':' ) + 1 );
106 currentChange.setRevision( currentRevision );
107 }
108 else if ( line.startsWith( BRANCH_TAG ) )
109 {
110 tmpLine = line.substring( BRANCH_TAG.length() ).trim();
111 currentBranch = tmpLine;
112 }
113 else if ( line.startsWith( AUTHOR_TAG ) )
114 {
115 tmpLine = line.substring( AUTHOR_TAG.length() ).trim();
116 currentChange.setAuthor( tmpLine );
117 }
118 else if ( line.startsWith( TIME_STAMP_TOKEN ) )
119 {
120 tmpLine = line.substring( TIME_STAMP_TOKEN.length() ).trim();
121 Date date = parseDate( tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH );
122 currentChange.setDate( date );
123 }
124 else if ( line.startsWith( TAG_TAG ) )
125 {
126 tmpLine = line.substring( TAG_TAG.length() ).trim();
127 currentChange.addTag( tmpLine );
128 }
129 else if ( line.startsWith( FILES_TOKEN ) )
130 {
131 tmpLine = line.substring( FILES_TOKEN.length() ).trim();
132 String[] files = tmpLine.split( " " );
133 for ( int i = 0; i < files.length; i++ )
134 {
135 String file = files[i];
136 ChangeFile changeFile = new ChangeFile( file, currentRevision );
137 currentChange.addFile( changeFile );
138 }
139 }
140 else if ( line.startsWith( MESSAGE_TOKEN ) )
141 {
142 currentChange.setComment( "" );
143 }
144 else
145 {
146 StringBuilder comment = new StringBuilder( currentChange.getComment() );
147 comment.append( line );
148 currentChange.setComment( comment.toString() );
149 }
150 }
151 }