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