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