1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.site.render;
20
21 import java.io.IOException;
22 import java.io.Writer;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Locale;
26
27 import org.apache.commons.lang3.StringUtils;
28 import org.apache.maven.doxia.siterenderer.DocumentRenderingContext;
29 import org.apache.maven.doxia.siterenderer.RendererException;
30 import org.apache.maven.doxia.siterenderer.SiteRenderer;
31 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
32 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
33 import org.apache.maven.plugin.MojoExecution;
34 import org.apache.maven.plugin.logging.Log;
35 import org.apache.maven.reporting.MavenReport;
36 import org.codehaus.plexus.i18n.I18N;
37
38 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
39
40
41
42
43
44
45 public class CategorySummaryDocumentRenderer implements SitePluginReportDocumentRenderer {
46 private DocumentRenderingContext docRenderingContext;
47
48 private final String reportMojoInfo;
49
50 private String title;
51
52 private String desc1;
53
54 private String desc2;
55
56 private I18N i18n;
57
58 private List<MavenReport> categoryReports;
59
60 private final Log log;
61
62 @SuppressWarnings("checkstyle:parameternumber")
63 public CategorySummaryDocumentRenderer(
64 MojoExecution mojoExecution,
65 DocumentRenderingContext docRenderingContext,
66 String title,
67 String desc1,
68 String desc2,
69 I18N i18n,
70 List<MavenReport> categoryReports,
71 Log log) {
72 this.docRenderingContext = docRenderingContext;
73 this.reportMojoInfo = mojoExecution.getPlugin().getArtifactId()
74 + ':'
75 + mojoExecution.getPlugin().getVersion()
76 + ':'
77 + mojoExecution.getGoal();
78 this.title = title;
79 this.desc1 = desc1;
80 this.desc2 = desc2;
81 this.i18n = i18n;
82 this.categoryReports = Collections.unmodifiableList(categoryReports);
83 this.log = log;
84 }
85
86 @Override
87 public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderingContext siteRenderingContext)
88 throws RendererException, IOException {
89 String msg = "Generating \"" + buffer().strong(title) + "\" report";
90
91 log.info((StringUtils.rightPad(msg, 40) + buffer().strong(" --- ").mojo(reportMojoInfo)));
92
93
94 SiteRendererSink sink = new SiteRendererSink(docRenderingContext);
95
96 sink.head();
97
98 sink.title();
99
100 sink.text(title);
101
102 sink.title_();
103
104 sink.head_();
105
106 sink.body();
107
108 sink.section1();
109 sink.sectionTitle1();
110 sink.text(title);
111 sink.sectionTitle1_();
112
113 sink.paragraph();
114 sink.text(desc1 + " ");
115 sink.link("https://maven.apache.org");
116 sink.text("Maven");
117 sink.link_();
118 sink.text(" " + desc2);
119 sink.paragraph_();
120
121 sink.section2();
122 sink.sectionTitle2();
123 Locale locale = siteRenderingContext.getLocale();
124 sink.text(i18n.getString("site-plugin", locale, "report.category.sectionTitle"));
125 sink.sectionTitle2_();
126
127 sink.table();
128
129 sink.tableRows();
130
131 String name = i18n.getString("site-plugin", locale, "report.category.column.document");
132 String description = i18n.getString("site-plugin", locale, "report.category.column.description");
133
134 sink.tableRow();
135
136 sink.tableHeaderCell();
137
138 sink.text(name);
139
140 sink.tableHeaderCell_();
141
142 sink.tableHeaderCell();
143
144 sink.text(description);
145
146 sink.tableHeaderCell_();
147
148 sink.tableRow_();
149
150 if (categoryReports != null) {
151 for (MavenReport report : categoryReports) {
152 sink.tableRow();
153 sink.tableCell();
154 sink.link(report.getOutputName() + ".html");
155 sink.text(report.getName(locale));
156 sink.link_();
157 sink.tableCell_();
158 sink.tableCell();
159 sink.text(report.getDescription(locale));
160 sink.tableCell_();
161 sink.tableRow_();
162 }
163 }
164
165 sink.tableRows_();
166
167 sink.table_();
168
169 sink.section2_();
170
171 sink.section1_();
172
173 sink.body_();
174
175 sink.flush();
176
177 sink.close();
178
179 siteRenderer.mergeDocumentIntoSite(writer, sink, siteRenderingContext);
180 }
181
182 @Override
183 public String getOutputName() {
184 return docRenderingContext.getOutputName();
185 }
186
187 @Override
188 public DocumentRenderingContext getRenderingContext() {
189 return docRenderingContext;
190 }
191
192 @Override
193 public boolean isOverwrite() {
194 return true;
195 }
196
197 @Override
198 public boolean isExternalReport() {
199 return false;
200 }
201
202 @Override
203 public String getReportMojoInfo() {
204 return reportMojoInfo;
205 }
206 }