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 = "EEE MMM dd HH:mm:ss yyyy 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 AUTHOR_TAG = "user: "; |
48 | |
|
49 | |
private static final String TIME_STAMP_TOKEN = "date: "; |
50 | |
|
51 | |
private static final String MESSAGE_TOKEN = "description:"; |
52 | |
|
53 | |
private static final String FILES_TOKEN = "files: "; |
54 | |
|
55 | 0 | private String prevLine = ""; |
56 | |
|
57 | 0 | private String prevPrevLine = ""; |
58 | |
|
59 | 0 | private List<ChangeSet> logEntries = new ArrayList<ChangeSet>(); |
60 | |
|
61 | |
private ChangeSet currentChange; |
62 | |
|
63 | |
private String currentRevision; |
64 | |
|
65 | |
@SuppressWarnings( "unused" ) |
66 | |
private String currentTag; |
67 | |
|
68 | |
private String userDatePattern; |
69 | |
|
70 | |
private boolean spoolingComments; |
71 | |
|
72 | 0 | private List<String> currentComment = null; |
73 | |
|
74 | |
public HgChangeLogConsumer( ScmLogger logger, String userDatePattern ) |
75 | |
{ |
76 | 0 | super( logger ); |
77 | |
|
78 | 0 | this.userDatePattern = userDatePattern; |
79 | 0 | } |
80 | |
|
81 | |
public List<ChangeSet> getModifications() |
82 | |
{ |
83 | 0 | return logEntries; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
public void consumeLine( String line ) |
88 | |
{ |
89 | |
|
90 | |
|
91 | |
|
92 | 0 | doConsume( null, line ); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
public void doConsume( ScmFileStatus status, String line ) |
97 | |
{ |
98 | 0 | String tmpLine = line; |
99 | |
|
100 | |
|
101 | 0 | if ( ( line.equals( "" ) && ( prevLine.equals( "" ) && prevPrevLine.equals( "" ) ) ) || currentComment == null ) |
102 | |
{ |
103 | 0 | if ( currentComment != null ) |
104 | |
{ |
105 | 0 | StringBuilder comment = new StringBuilder(); |
106 | 0 | for ( int i = 0; i < currentComment.size() - 1; i++ ) |
107 | |
{ |
108 | 0 | comment.append( currentComment.get( i ) ); |
109 | 0 | if ( i + 1 < currentComment.size() - 1 ) |
110 | |
{ |
111 | 0 | comment.append( '\n' ); |
112 | |
} |
113 | |
} |
114 | 0 | currentChange.setComment( comment.toString() ); |
115 | |
|
116 | |
} |
117 | |
|
118 | 0 | spoolingComments = false; |
119 | |
|
120 | |
|
121 | 0 | currentChange = new ChangeSet(); |
122 | 0 | currentChange.setFiles( new ArrayList<ChangeFile>( 0 ) ); |
123 | 0 | logEntries.add( currentChange ); |
124 | |
|
125 | |
|
126 | 0 | currentComment = new ArrayList<String>(); |
127 | 0 | currentRevision = ""; |
128 | |
} |
129 | |
|
130 | 0 | if ( spoolingComments ) |
131 | |
{ |
132 | 0 | currentComment.add( line ); |
133 | |
} |
134 | 0 | else if ( line.startsWith( MESSAGE_TOKEN ) ) |
135 | |
{ |
136 | 0 | spoolingComments = true; |
137 | |
} |
138 | 0 | else if ( line.startsWith( REVNO_TAG ) ) |
139 | |
{ |
140 | 0 | tmpLine = line.substring( REVNO_TAG.length() ); |
141 | 0 | tmpLine = tmpLine.trim(); |
142 | 0 | currentRevision = tmpLine.substring( tmpLine.indexOf( ':' ) + 1 ); |
143 | 0 | currentChange.setRevision( currentRevision ); |
144 | |
|
145 | |
} |
146 | 0 | else if ( line.startsWith( TAG_TAG ) ) |
147 | |
{ |
148 | 0 | tmpLine = line.substring( TAG_TAG.length() ).trim(); |
149 | 0 | currentTag = tmpLine; |
150 | |
} |
151 | 0 | else if ( line.startsWith( AUTHOR_TAG ) ) |
152 | |
{ |
153 | 0 | tmpLine = line.substring( AUTHOR_TAG.length() ); |
154 | 0 | tmpLine = tmpLine.trim(); |
155 | 0 | currentChange.setAuthor( tmpLine ); |
156 | |
} |
157 | 0 | else if ( line.startsWith( TIME_STAMP_TOKEN ) ) |
158 | |
{ |
159 | |
|
160 | 0 | tmpLine = line.substring( TIME_STAMP_TOKEN.length() ).trim(); |
161 | 0 | Date date = parseDate( tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH ); |
162 | 0 | currentChange.setDate( date ); |
163 | 0 | } |
164 | 0 | else if ( line.startsWith( FILES_TOKEN ) ) |
165 | |
{ |
166 | 0 | tmpLine = line.substring( FILES_TOKEN.length() ).trim(); |
167 | 0 | String[] files = tmpLine.split( " " ); |
168 | 0 | for ( int i = 0; i < files.length; i++ ) |
169 | |
{ |
170 | 0 | String file = files[i]; |
171 | 0 | ChangeFile changeFile = new ChangeFile( file, currentRevision ); |
172 | 0 | currentChange.addFile( changeFile ); |
173 | |
} |
174 | 0 | } |
175 | 0 | else if ( line.length() > 0 ) |
176 | |
{ |
177 | 0 | if ( getLogger().isWarnEnabled() ) |
178 | |
{ |
179 | 0 | getLogger().warn( "Could not figure out: " + line ); |
180 | |
} |
181 | |
} |
182 | |
|
183 | |
|
184 | 0 | prevLine = line; |
185 | 0 | prevPrevLine = prevLine; |
186 | 0 | } |
187 | |
} |