1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.report.projectinfo;
20
21 import java.net.URI;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Locale;
26
27 import org.apache.maven.doxia.sink.Sink;
28 import org.apache.maven.model.MailingList;
29 import org.apache.maven.model.Model;
30 import org.apache.maven.plugin.logging.Log;
31 import org.apache.maven.plugins.annotations.Mojo;
32 import org.codehaus.plexus.i18n.I18N;
33 import org.codehaus.plexus.util.StringUtils;
34
35
36
37
38
39
40
41
42 @Mojo(name = "mailing-lists")
43 public class MailingListsReport extends AbstractProjectInfoReport {
44
45
46
47
48 @Override
49 public boolean canGenerateReport() {
50 boolean result = super.canGenerateReport();
51 if (result && skipEmptyReport) {
52 result = !isEmpty(getProject().getModel().getMailingLists());
53 }
54
55 return result;
56 }
57
58 @Override
59 public void executeReport(Locale locale) {
60 MailingListsRenderer r =
61 new MailingListsRenderer(getLog(), getSink(), getProject().getModel(), getI18N(locale), locale);
62
63 r.render();
64 }
65
66
67
68
69 public String getOutputName() {
70 return "mailing-lists";
71 }
72
73 @Override
74 protected String getI18Nsection() {
75 return "mailing-lists";
76 }
77
78
79
80
81
82
83
84
85 protected static class MailingListsRenderer extends AbstractProjectInfoRenderer {
86
87 private final Log log;
88 private final Model model;
89
90 MailingListsRenderer(Log log, Sink sink, Model model, I18N i18n, Locale locale) {
91 super(sink, i18n, locale);
92 this.model = model;
93 this.log = log;
94 }
95
96 @Override
97 protected String getI18Nsection() {
98 return "mailing-lists";
99 }
100
101 @Override
102 protected void renderBody() {
103 List<MailingList> mailingLists = model.getMailingLists();
104
105 if (mailingLists == null || mailingLists.isEmpty()) {
106 startSection(getTitle());
107
108 paragraph(getI18nString("nolist"));
109
110 endSection();
111
112 return;
113 }
114
115 startSection(getTitle());
116
117 paragraph(getI18nString("intro"));
118
119 startTable();
120
121
122 boolean otherArchives = false;
123 for (MailingList m : mailingLists) {
124 if (m.getOtherArchives() != null && !m.getOtherArchives().isEmpty()) {
125 otherArchives = true;
126 }
127 }
128
129 String name = getI18nString("column.name");
130 String subscribe = getI18nString("column.subscribe");
131 String unsubscribe = getI18nString("column.unsubscribe");
132 String post = getI18nString("column.post");
133 String archive = getI18nString("column.archive");
134 String archivesOther = getI18nString("column.otherArchives");
135
136 if (otherArchives) {
137 tableHeader(new String[] {name, subscribe, unsubscribe, post, archive, archivesOther});
138 } else {
139 tableHeader(new String[] {name, subscribe, unsubscribe, post, archive});
140 }
141
142 for (MailingList mailingList : model.getMailingLists()) {
143 List<String> textRow = new ArrayList<>();
144
145 if (StringUtils.isNotEmpty(mailingList.getName())) {
146 textRow.add(mailingList.getName());
147 } else {
148 textRow.add("-");
149 }
150
151 if (StringUtils.isNotEmpty(mailingList.getSubscribe())) {
152 textRow.add(createURILinkPatternedText(subscribe, mailingList.getSubscribe(), null));
153 } else {
154 textRow.add("-");
155 }
156
157 if (StringUtils.isNotEmpty(mailingList.getUnsubscribe())) {
158 textRow.add(createURILinkPatternedText(unsubscribe, mailingList.getUnsubscribe(), null));
159 } else {
160 textRow.add("-");
161 }
162
163 if (StringUtils.isNotEmpty(mailingList.getPost())) {
164 textRow.add(createURILinkPatternedText(post, mailingList.getPost(), null));
165 } else {
166 textRow.add("-");
167 }
168
169 if (mailingList.getArchive() != null
170 && !mailingList.getArchive().isEmpty()) {
171 textRow.add(createLinkPatternedText(
172 ProjectInfoReportUtils.getArchiveServer(mailingList.getArchive()),
173 mailingList.getArchive()));
174 } else {
175 textRow.add("-");
176 }
177
178 if (mailingList.getOtherArchives() != null
179 && !mailingList.getOtherArchives().isEmpty()) {
180
181 Iterator<String> it = mailingList.getOtherArchives().iterator();
182 String otherArchive = it.next();
183
184 textRow.add(createLinkPatternedText(
185 ProjectInfoReportUtils.getArchiveServer(otherArchive), otherArchive));
186
187 tableRow(textRow.toArray(new String[textRow.size()]));
188
189
190 while (it.hasNext()) {
191 otherArchive = it.next();
192
193
194 textRow = new ArrayList<>();
195
196
197 textRow.add(" ");
198
199
200 textRow.add(" ");
201
202
203 textRow.add(" ");
204
205
206 textRow.add(" ");
207
208
209 textRow.add(" ");
210
211 textRow.add(createLinkPatternedText(
212 ProjectInfoReportUtils.getArchiveServer(otherArchive), otherArchive));
213
214 tableRow(textRow.toArray(new String[textRow.size()]));
215 }
216 } else {
217 if (otherArchives) {
218 textRow.add(null);
219 }
220
221 tableRow(textRow.toArray(new String[textRow.size()]));
222 }
223 }
224
225 endTable();
226
227 endSection();
228 }
229
230
231
232
233
234
235
236
237
238
239
240 private String createURILinkPatternedText(String text, String href, String defaultHref) {
241 if (href == null || href.isEmpty()) {
242 return createLinkPatternedText(text, defaultHref);
243 }
244
245 try {
246 URI hrefUri = URI.create(href);
247 if (StringUtils.isNotEmpty(hrefUri.getScheme())) {
248 return createLinkPatternedText(text, href);
249 } else {
250 return createLinkPatternedText(text, "mailto:" + href);
251 }
252 } catch (IllegalArgumentException e) {
253 log.warn("Invalid mailing list link provided '" + href + "': " + e.getMessage());
254 return href;
255 }
256 }
257 }
258 }