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