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