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