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