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