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
162 textRow.add( mailingList.getName() );
163
164 textRow.add( createLinkPatternedText( subscribe, mailingList.getSubscribe() ) );
165
166 textRow.add( createLinkPatternedText( unsubscribe, mailingList.getUnsubscribe() ) );
167
168 if ( mailingList.getPost() != null && mailingList.getPost().length() > 0 )
169 {
170 textRow.add( createLinkPatternedText( post, mailingList.getPost() ) );
171 }
172 else
173 {
174 textRow.add( "-" );
175 }
176
177 if ( mailingList.getArchive() != null && mailingList.getArchive().length() > 0 )
178 {
179 textRow.add( createLinkPatternedText( getArchiveServer( mailingList.getArchive() ),
180 mailingList.getArchive() ) );
181 }
182 else
183 {
184 textRow.add( "-" );
185 }
186
187 if ( mailingList.getOtherArchives() != null && !mailingList.getOtherArchives().isEmpty() )
188 {
189
190 Iterator<String> it = mailingList.getOtherArchives().iterator();
191 String otherArchive = it.next();
192
193 textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) );
194
195 tableRow( textRow.toArray( new String[textRow.size()] ) );
196
197
198 while ( it.hasNext() )
199 {
200 otherArchive = it.next();
201
202
203 textRow = new ArrayList<>();
204
205
206 textRow.add( " " );
207
208
209 textRow.add( " " );
210
211
212 textRow.add( " " );
213
214
215 textRow.add( " " );
216
217
218 textRow.add( " " );
219
220 textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) );
221
222 tableRow( textRow.toArray( new String[textRow.size()] ) );
223 }
224 }
225 else
226 {
227 if ( otherArchives )
228 {
229 textRow.add( null );
230 }
231
232 tableRow( textRow.toArray( new String[textRow.size()] ) );
233 }
234 }
235
236 endTable();
237
238 endSection();
239 }
240
241
242
243
244
245
246
247
248
249 private static String getArchiveServer( String uri )
250 {
251 if ( StringUtils.isEmpty( uri ) )
252 {
253 return "???UNKNOWN???";
254 }
255
256 int at = uri.indexOf( "//" );
257 int fromIndex;
258 if ( at >= 0 )
259 {
260 fromIndex = uri.lastIndexOf( '/', at - 1 ) >= 0 ? 0 : at + 2;
261 }
262 else
263 {
264 fromIndex = 0;
265 }
266
267 int from = uri.indexOf( '/', fromIndex );
268
269 if ( from == -1 )
270 {
271 return uri.substring( at + 2 );
272 }
273
274 return uri.substring( at + 2, from );
275 }
276 }
277 }