1 | |
package org.apache.maven.report.projectinfo; |
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.model.MailingList; |
24 | |
import org.apache.maven.model.Model; |
25 | |
import org.apache.maven.reporting.AbstractMavenReportRenderer; |
26 | |
import org.codehaus.plexus.i18n.I18N; |
27 | |
import org.codehaus.plexus.util.StringUtils; |
28 | |
|
29 | |
import java.util.ArrayList; |
30 | |
import java.util.Iterator; |
31 | |
import java.util.List; |
32 | |
import java.util.Locale; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 2 | public class MailingListsReport |
44 | |
extends AbstractProjectInfoReport |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public String getName( Locale locale ) |
52 | |
{ |
53 | 2 | return i18n.getString( "project-info-report", locale, "report.mailing-lists.name" ); |
54 | |
} |
55 | |
|
56 | |
|
57 | |
public String getDescription( Locale locale ) |
58 | |
{ |
59 | 0 | return i18n.getString( "project-info-report", locale, "report.mailing-lists.description" ); |
60 | |
} |
61 | |
|
62 | |
|
63 | |
public void executeReport( Locale locale ) |
64 | |
{ |
65 | 2 | MailingListsRenderer r = new MailingListsRenderer( getSink(), getProject().getModel(), i18n, locale ); |
66 | |
|
67 | 2 | r.render(); |
68 | 2 | } |
69 | |
|
70 | |
|
71 | |
public String getOutputName() |
72 | |
{ |
73 | 6 | return "mail-lists"; |
74 | |
} |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 2 | protected static class MailingListsRenderer |
84 | |
extends AbstractMavenReportRenderer |
85 | |
{ |
86 | |
private Model model; |
87 | |
|
88 | |
private I18N i18n; |
89 | |
|
90 | |
private Locale locale; |
91 | |
|
92 | 1 | private static final String[] EMPTY_STRING_ARRAY = new String[0]; |
93 | |
|
94 | |
MailingListsRenderer( Sink sink, Model model, I18N i18n, Locale locale ) |
95 | |
{ |
96 | 2 | super( sink ); |
97 | |
|
98 | 2 | this.model = model; |
99 | |
|
100 | 2 | this.i18n = i18n; |
101 | |
|
102 | 2 | this.locale = locale; |
103 | 2 | } |
104 | |
|
105 | |
|
106 | |
public String getTitle() |
107 | |
{ |
108 | 4 | return i18n.getString( "project-info-report", locale, "report.mailing-lists.title" ); |
109 | |
} |
110 | |
|
111 | |
|
112 | |
public void renderBody() |
113 | |
{ |
114 | 2 | List mailingLists = model.getMailingLists(); |
115 | |
|
116 | 2 | if ( mailingLists == null || mailingLists.isEmpty() ) |
117 | |
{ |
118 | 0 | startSection( getTitle() ); |
119 | |
|
120 | |
|
121 | 0 | paragraph( i18n.getString( "project-info-report", locale, "report.mailing-lists.nolist" ) ); |
122 | |
|
123 | 0 | endSection(); |
124 | |
|
125 | 0 | return; |
126 | |
} |
127 | |
|
128 | 2 | startSection( getTitle() ); |
129 | |
|
130 | 2 | paragraph( i18n.getString( "project-info-report", locale, "report.mailing-lists.intro" ) ); |
131 | |
|
132 | 2 | startTable(); |
133 | |
|
134 | |
|
135 | 2 | boolean otherArchives = false; |
136 | 2 | for ( Iterator i = mailingLists.iterator(); i.hasNext(); ) |
137 | |
{ |
138 | 2 | MailingList m = (MailingList) i.next(); |
139 | |
|
140 | 2 | if ( m.getOtherArchives() != null && !m.getOtherArchives().isEmpty() ) |
141 | |
{ |
142 | 0 | otherArchives = true; |
143 | |
} |
144 | |
} |
145 | |
|
146 | 2 | String name = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.name" ); |
147 | 2 | String subscribe = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.subscribe" ); |
148 | 2 | String unsubscribe = |
149 | |
i18n.getString( "project-info-report", locale, "report.mailing-lists.column.unsubscribe" ); |
150 | 2 | String post = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.post" ); |
151 | 2 | String archive = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.archive" ); |
152 | 2 | String archivesOther = |
153 | |
i18n.getString( "project-info-report", locale, "report.mailing-lists.column.otherArchives" ); |
154 | |
|
155 | 2 | if ( otherArchives ) |
156 | |
{ |
157 | 0 | tableHeader( new String[]{name, subscribe, unsubscribe, post, archive, archivesOther} ); |
158 | |
} |
159 | |
else |
160 | |
{ |
161 | 2 | tableHeader( new String[]{name, subscribe, unsubscribe, post, archive} ); |
162 | |
} |
163 | |
|
164 | 2 | for ( Iterator i = model.getMailingLists().iterator(); i.hasNext(); ) |
165 | |
{ |
166 | 2 | MailingList mailingList = (MailingList) i.next(); |
167 | |
|
168 | 2 | List textRow = new ArrayList(); |
169 | |
|
170 | |
|
171 | 2 | textRow.add( mailingList.getName() ); |
172 | |
|
173 | 2 | textRow.add( createLinkPatternedText( subscribe, mailingList.getSubscribe() ) ); |
174 | |
|
175 | 2 | textRow.add( createLinkPatternedText( unsubscribe, mailingList.getUnsubscribe() ) ); |
176 | |
|
177 | 2 | if ( mailingList.getPost() != null && mailingList.getPost().length() > 0 ) |
178 | |
{ |
179 | 2 | textRow.add( createLinkPatternedText( post, mailingList.getPost() ) ); |
180 | |
} |
181 | |
else |
182 | |
{ |
183 | 0 | textRow.add( "-" ); |
184 | |
} |
185 | |
|
186 | 2 | if ( mailingList.getArchive() != null && mailingList.getArchive().length() > 0 ) |
187 | |
{ |
188 | 0 | textRow.add( createLinkPatternedText( getArchiveServer( mailingList.getArchive() ), |
189 | |
mailingList.getArchive() ) ); |
190 | |
} |
191 | |
else |
192 | |
{ |
193 | 2 | textRow.add( "-" ); |
194 | |
} |
195 | |
|
196 | 2 | if ( mailingList.getOtherArchives() != null && !mailingList.getOtherArchives().isEmpty() ) |
197 | |
{ |
198 | |
|
199 | 0 | Iterator it = mailingList.getOtherArchives().iterator(); |
200 | 0 | String otherArchive = it.next().toString(); |
201 | |
|
202 | 0 | textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) ); |
203 | |
|
204 | 0 | tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) ); |
205 | |
|
206 | |
|
207 | 0 | while ( it.hasNext() ) |
208 | |
{ |
209 | 0 | otherArchive = (String) it.next(); |
210 | |
|
211 | |
|
212 | 0 | textRow = new ArrayList(); |
213 | |
|
214 | |
|
215 | 0 | textRow.add( " " ); |
216 | |
|
217 | |
|
218 | 0 | textRow.add( " " ); |
219 | |
|
220 | |
|
221 | 0 | textRow.add( " " ); |
222 | |
|
223 | |
|
224 | 0 | textRow.add( " " ); |
225 | |
|
226 | |
|
227 | 0 | textRow.add( " " ); |
228 | |
|
229 | 0 | textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) ); |
230 | |
|
231 | 0 | tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) ); |
232 | |
} |
233 | |
} |
234 | |
else |
235 | |
{ |
236 | 2 | if ( otherArchives ) |
237 | |
{ |
238 | 0 | textRow.add( null ); |
239 | |
} |
240 | |
|
241 | 2 | tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) ); |
242 | |
} |
243 | |
} |
244 | |
|
245 | 2 | endTable(); |
246 | |
|
247 | 2 | endSection(); |
248 | 2 | } |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
private static String getArchiveServer( String uri ) |
261 | |
{ |
262 | 6 | if ( StringUtils.isEmpty( uri ) ) |
263 | |
{ |
264 | 0 | return "???UNKNOWN???"; |
265 | |
} |
266 | |
|
267 | 6 | int at = uri.indexOf( "//" ); |
268 | |
int fromIndex; |
269 | 6 | if ( at >= 0 ) |
270 | |
{ |
271 | 6 | fromIndex = uri.lastIndexOf( "/", at - 1 ) >= 0 ? 0 : at + 2; |
272 | |
} |
273 | |
else |
274 | |
{ |
275 | 0 | fromIndex = 0; |
276 | |
} |
277 | |
|
278 | 6 | int from = uri.indexOf( "/", fromIndex ); |
279 | |
|
280 | 6 | if ( from == -1 ) |
281 | |
{ |
282 | 1 | return uri.substring( at + 2 ); |
283 | |
} |
284 | |
|
285 | 5 | return uri.substring( at + 2, from ); |
286 | |
} |
287 | |
} |
288 | |
} |