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