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.codehaus.plexus.i18n.I18N;
28 import org.codehaus.plexus.util.StringUtils;
29
30 import java.net.URI;
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 @Mojo( name = "mailing-lists" )
44 public class MailingListsReport
45 extends AbstractProjectInfoReport
46 {
47
48
49
50
51 @Override
52 public boolean canGenerateReport()
53 {
54 boolean result = super.canGenerateReport();
55 if ( result && skipEmptyReport )
56 {
57 result = !isEmpty( getProject().getModel().getMailingLists() );
58 }
59
60 return result;
61 }
62
63 @Override
64 public void executeReport( Locale locale )
65 {
66 MailingListsRenderer r =
67 new MailingListsRenderer( getLog(), getSink(), getProject().getModel(), getI18N( locale ), locale );
68
69 r.render();
70 }
71
72
73
74
75 public String getOutputName()
76 {
77 return "mailing-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
97 private final Log log;
98 private final Model model;
99
100 MailingListsRenderer( Log log, Sink sink, Model model, I18N i18n, Locale locale )
101 {
102 super( sink, i18n, locale );
103 this.model = model;
104 this.log = log;
105 }
106
107 @Override
108 protected String getI18Nsection()
109 {
110 return "mailing-lists";
111 }
112
113 @Override
114 public void renderBody()
115 {
116 List<MailingList> mailingLists = model.getMailingLists();
117
118 if ( mailingLists == null || mailingLists.isEmpty() )
119 {
120 startSection( getTitle() );
121
122 paragraph( getI18nString( "nolist" ) );
123
124 endSection();
125
126 return;
127 }
128
129 startSection( getTitle() );
130
131 paragraph( getI18nString( "intro" ) );
132
133 startTable();
134
135
136 boolean otherArchives = false;
137 for ( MailingList m : mailingLists )
138 {
139 if ( m.getOtherArchives() != null && !m.getOtherArchives().isEmpty() )
140 {
141 otherArchives = true;
142 }
143 }
144
145 String name = getI18nString( "column.name" );
146 String subscribe = getI18nString( "column.subscribe" );
147 String unsubscribe = getI18nString( "column.unsubscribe" );
148 String post = getI18nString( "column.post" );
149 String archive = getI18nString( "column.archive" );
150 String archivesOther = getI18nString( "column.otherArchives" );
151
152 if ( otherArchives )
153 {
154 tableHeader( new String[] { name, subscribe, unsubscribe, post, archive, archivesOther } );
155 }
156 else
157 {
158 tableHeader( new String[] { name, subscribe, unsubscribe, post, archive } );
159 }
160
161 for ( MailingList mailingList : model.getMailingLists() )
162 {
163 List<String> textRow = new ArrayList<>();
164
165 if ( StringUtils.isNotEmpty( mailingList.getName() ) )
166 {
167 textRow.add( mailingList.getName() );
168 }
169 else
170 {
171 textRow.add( "-" );
172 }
173
174 if ( StringUtils.isNotEmpty( mailingList.getSubscribe() ) )
175 {
176 textRow.add( createURILinkPatternedText( subscribe, mailingList.getSubscribe(), null ) );
177 }
178 else
179 {
180 textRow.add( "-" );
181 }
182
183 if ( StringUtils.isNotEmpty( mailingList.getUnsubscribe() ) )
184 {
185 textRow.add( createURILinkPatternedText( unsubscribe, mailingList.getUnsubscribe(), null ) );
186 }
187 else
188 {
189 textRow.add( "-" );
190 }
191
192 if ( StringUtils.isNotEmpty( mailingList.getPost() ) )
193 {
194 textRow.add( createURILinkPatternedText( post, mailingList.getPost(), null ) );
195 }
196 else
197 {
198 textRow.add( "-" );
199 }
200
201 if ( mailingList.getArchive() != null && !mailingList.getArchive().isEmpty() )
202 {
203 textRow.add( createLinkPatternedText(
204 ProjectInfoReportUtils.getArchiveServer( mailingList.getArchive() ),
205 mailingList.getArchive() ) );
206 }
207 else
208 {
209 textRow.add( "-" );
210 }
211
212 if ( mailingList.getOtherArchives() != null && !mailingList.getOtherArchives().isEmpty() )
213 {
214
215 Iterator<String> it = mailingList.getOtherArchives().iterator();
216 String otherArchive = it.next();
217
218 textRow.add( createLinkPatternedText(
219 ProjectInfoReportUtils.getArchiveServer( otherArchive ), otherArchive ) );
220
221 tableRow( textRow.toArray( new String[textRow.size()] ) );
222
223
224 while ( it.hasNext() )
225 {
226 otherArchive = it.next();
227
228
229 textRow = new ArrayList<>();
230
231
232 textRow.add( " " );
233
234
235 textRow.add( " " );
236
237
238 textRow.add( " " );
239
240
241 textRow.add( " " );
242
243
244 textRow.add( " " );
245
246 textRow.add( createLinkPatternedText(
247 ProjectInfoReportUtils.getArchiveServer( otherArchive ), otherArchive ) );
248
249 tableRow( textRow.toArray( new String[textRow.size()] ) );
250 }
251 }
252 else
253 {
254 if ( otherArchives )
255 {
256 textRow.add( null );
257 }
258
259 tableRow( textRow.toArray( new String[textRow.size()] ) );
260 }
261 }
262
263 endTable();
264
265 endSection();
266 }
267
268
269
270
271
272
273
274
275
276
277
278 private String createURILinkPatternedText( String text, String href, String defaultHref )
279 {
280 if ( href == null || href.isEmpty() )
281 {
282 return createLinkPatternedText( text, defaultHref );
283 }
284
285 try
286 {
287 URI hrefUri = URI.create( href );
288 if ( StringUtils.isNotEmpty( hrefUri.getScheme() ) )
289 {
290 return createLinkPatternedText( text, href );
291 }
292 else
293 {
294 return createLinkPatternedText( text, "mailto:" + href );
295 }
296 }
297 catch ( IllegalArgumentException e )
298 {
299 log.warn( "Invalid mailing list link provided '" + href + "': " + e.getMessage() );
300 return href;
301 }
302 }
303 }
304 }