1 | |
package org.apache.maven.plugin.changelog; |
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.doxia.sink.Sink; |
23 | |
import org.apache.maven.scm.ChangeFile; |
24 | |
import org.apache.maven.scm.ChangeSet; |
25 | |
import org.apache.maven.scm.command.changelog.ChangeLogSet; |
26 | |
|
27 | |
import java.util.Collection; |
28 | |
import java.util.Collections; |
29 | |
import java.util.HashMap; |
30 | |
import java.util.Iterator; |
31 | |
import java.util.LinkedList; |
32 | |
import java.util.List; |
33 | |
import java.util.Locale; |
34 | |
import java.util.Map; |
35 | |
import java.util.ResourceBundle; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 2 | public class FileActivityReport |
44 | |
extends ChangeLogReport |
45 | |
{ |
46 | |
|
47 | |
public String getDescription( Locale locale ) |
48 | |
{ |
49 | 0 | return getBundle( locale ).getString( "report.file-activity.description" ); |
50 | |
} |
51 | |
|
52 | |
|
53 | |
public String getName( Locale locale ) |
54 | |
{ |
55 | 0 | return getBundle( locale ).getString( "report.file-activity.name" ); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
public String getOutputName() |
60 | |
{ |
61 | 2 | return "file-activity"; |
62 | |
} |
63 | |
|
64 | |
|
65 | |
protected void doGenerateEmptyReport( ResourceBundle bundle, Sink sink ) |
66 | |
{ |
67 | 1 | sink.head(); |
68 | 1 | sink.title(); |
69 | 1 | sink.text( bundle.getString( "report.file-activity.header" ) ); |
70 | 1 | sink.title_(); |
71 | 1 | sink.head_(); |
72 | |
|
73 | 1 | sink.body(); |
74 | 1 | sink.section1(); |
75 | |
|
76 | 1 | sink.sectionTitle1(); |
77 | 1 | sink.text( bundle.getString( "report.file-activity.mainTitle" ) ); |
78 | 1 | sink.sectionTitle1_(); |
79 | |
|
80 | 1 | sink.paragraph(); |
81 | 1 | sink.text( "No sources found to create a report." ); |
82 | 1 | sink.paragraph_(); |
83 | |
|
84 | 1 | sink.section1_(); |
85 | |
|
86 | 1 | sink.body_(); |
87 | 1 | sink.flush(); |
88 | 1 | sink.close(); |
89 | 1 | } |
90 | |
|
91 | |
|
92 | |
protected void doGenerateReport( List changeLogSets, ResourceBundle bundle, Sink sink ) |
93 | |
{ |
94 | 1 | sink.head(); |
95 | 1 | sink.title(); |
96 | 1 | sink.text( bundle.getString( "report.file-activity.header" ) ); |
97 | 1 | sink.title_(); |
98 | 1 | sink.head_(); |
99 | |
|
100 | 1 | sink.body(); |
101 | 1 | sink.section1(); |
102 | 1 | sink.sectionTitle1(); |
103 | 1 | sink.text( bundle.getString( "report.file-activity.mainTitle" ) ); |
104 | 1 | sink.sectionTitle1_(); |
105 | |
|
106 | 1 | for ( Iterator sets = changeLogSets.iterator(); sets.hasNext(); ) |
107 | |
{ |
108 | 2 | ChangeLogSet set = (ChangeLogSet) sets.next(); |
109 | 2 | doChangedSets( set, bundle, sink ); |
110 | 2 | } |
111 | |
|
112 | 1 | sink.section1_(); |
113 | 1 | sink.body_(); |
114 | |
|
115 | 1 | sink.flush(); |
116 | 1 | sink.close(); |
117 | 1 | } |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private void doChangedSets( ChangeLogSet set, ResourceBundle bundle, Sink sink ) |
127 | |
{ |
128 | 2 | sink.section2(); |
129 | |
|
130 | 2 | doChangeSetTitle( set, bundle, sink ); |
131 | |
|
132 | 2 | doSummary( set, bundle, sink ); |
133 | |
|
134 | 2 | sink.table(); |
135 | |
|
136 | 2 | sink.tableRow(); |
137 | 2 | sink.tableHeaderCell(); |
138 | 2 | sink.text( bundle.getString( "report.file-activity.filename" ) ); |
139 | 2 | sink.tableHeaderCell_(); |
140 | 2 | sink.tableHeaderCell(); |
141 | 2 | sink.text( bundle.getString( "report.file-activity.timesChanged" ) ); |
142 | 2 | sink.tableHeaderCell_(); |
143 | 2 | sink.tableRow_(); |
144 | |
|
145 | 2 | doRows( set, sink ); |
146 | |
|
147 | 2 | sink.table_(); |
148 | |
|
149 | 2 | sink.section2_(); |
150 | 2 | } |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
private void doRows( ChangeLogSet set, Sink sink ) |
159 | |
{ |
160 | 2 | List list = getOrderedFileList( set.getChangeSets() ); |
161 | |
|
162 | 2 | initReportUrls(); |
163 | |
|
164 | 2 | for ( Iterator i = list.iterator(); i.hasNext(); ) |
165 | |
{ |
166 | 4 | List revision = (List) i.next(); |
167 | 4 | ChangeFile file = (ChangeFile) revision.get( 0 ); |
168 | |
|
169 | 4 | sink.tableRow(); |
170 | 4 | sink.tableCell(); |
171 | |
|
172 | |
try |
173 | |
{ |
174 | 4 | generateLinks( getConnection(), file.getName(), sink ); |
175 | |
} |
176 | 0 | catch ( Exception e ) |
177 | |
{ |
178 | 0 | if ( getLog().isDebugEnabled() ) |
179 | |
{ |
180 | 0 | getLog().error( e.getMessage(), e ); |
181 | |
} |
182 | |
else |
183 | |
{ |
184 | 0 | getLog().error( e.getMessage() ); |
185 | |
} |
186 | |
|
187 | 0 | sink.text( file.getName() ); |
188 | 4 | } |
189 | 4 | sink.tableCell_(); |
190 | |
|
191 | 4 | sink.tableCell(); |
192 | 4 | sink.text( "" + revision.size() ); |
193 | |
|
194 | 4 | sink.tableCell_(); |
195 | 4 | sink.tableRow_(); |
196 | 4 | } |
197 | 2 | } |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
private List getOrderedFileList( Collection entries ) |
207 | |
{ |
208 | 2 | List list = new LinkedList(); |
209 | |
|
210 | 2 | Map map = new HashMap(); |
211 | |
|
212 | 2 | for ( Iterator i = entries.iterator(); i.hasNext(); ) |
213 | |
{ |
214 | 4 | ChangeSet entry = (ChangeSet) i.next(); |
215 | |
|
216 | 4 | for ( Iterator j = entry.getFiles().iterator(); j.hasNext(); ) |
217 | |
{ |
218 | 6 | ChangeFile file = (ChangeFile) j.next(); |
219 | |
|
220 | |
List revisions; |
221 | |
|
222 | 6 | if ( map.containsKey( file.getName() ) ) |
223 | |
{ |
224 | 2 | revisions = (List) map.get( file.getName() ); |
225 | |
} |
226 | |
else |
227 | |
{ |
228 | 4 | revisions = new LinkedList(); |
229 | |
} |
230 | |
|
231 | 6 | revisions.add( file ); |
232 | |
|
233 | 6 | map.put( file.getName(), revisions ); |
234 | 6 | } |
235 | 4 | } |
236 | |
|
237 | 2 | list.addAll( map.values() ); |
238 | |
|
239 | 2 | Collections.sort( list, new FileActivityComparator() ); |
240 | |
|
241 | 2 | return list; |
242 | |
} |
243 | |
} |