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 public CategorySummaryDocumentRenderer(
63 MojoExecution mojoExecution,
64 DocumentRenderingContext docRenderingContext,
65 String title,
66 String desc1,
67 String desc2,
68 I18N i18n,
69 List<MavenReport> categoryReports,
70 Log log) {
71 this.docRenderingContext = docRenderingContext;
72 this.reportMojoInfo = mojoExecution.getPlugin().getArtifactId()
73 + ':'
74 + mojoExecution.getPlugin().getVersion()
75 + ':'
76 + mojoExecution.getGoal();
77 this.title = title;
78 this.desc1 = desc1;
79 this.desc2 = desc2;
80 this.i18n = i18n;
81 this.categoryReports = Collections.unmodifiableList(categoryReports);
82 this.log = log;
83 }
84
85 @Override
86 public void renderDocument(Writer writer, SiteRenderer siteRenderer, SiteRenderingContext siteRenderingContext)
87 throws RendererException, IOException {
88 String msg = "Generating \"" + buffer().strong(title) + "\" report";
89
90 log.info((StringUtils.rightPad(msg, 40) + buffer().strong(" --- ").mojo(reportMojoInfo)));
91
92
93 SiteRendererSink sink = new SiteRendererSink(docRenderingContext);
94
95 sink.head();
96
97 sink.title();
98
99 sink.text(title);
100
101 sink.title_();
102
103 sink.head_();
104
105 sink.body();
106
107 sink.section1();
108 sink.sectionTitle1();
109 sink.text(title);
110 sink.sectionTitle1_();
111
112 sink.paragraph();
113 sink.text(desc1 + " ");
114 sink.link("https://maven.apache.org");
115 sink.text("Maven");
116 sink.link_();
117 sink.text(" " + desc2);
118 sink.paragraph_();
119
120 sink.section2();
121 sink.sectionTitle2();
122 Locale locale = siteRenderingContext.getLocale();
123 sink.text(i18n.getString("site-plugin", locale, "report.category.sectionTitle"));
124 sink.sectionTitle2_();
125
126 sink.table();
127
128 sink.tableRows();
129
130 String name = i18n.getString("site-plugin", locale, "report.category.column.document");
131 String description = i18n.getString("site-plugin", locale, "report.category.column.description");
132
133 sink.tableRow();
134
135 sink.tableHeaderCell();
136
137 sink.text(name);
138
139 sink.tableHeaderCell_();
140
141 sink.tableHeaderCell();
142
143 sink.text(description);
144
145 sink.tableHeaderCell_();
146
147 sink.tableRow_();
148
149 if (categoryReports != null) {
150 for (MavenReport report : categoryReports) {
151 sink.tableRow();
152 sink.tableCell();
153 sink.link(report.getOutputName() + ".html");
154 sink.text(report.getName(locale));
155 sink.link_();
156 sink.tableCell_();
157 sink.tableCell();
158 sink.text(report.getDescription(locale));
159 sink.tableCell_();
160 sink.tableRow_();
161 }
162 }
163
164 sink.tableRows_();
165
166 sink.table_();
167
168 sink.section2_();
169
170 sink.section1_();
171
172 sink.body_();
173
174 sink.flush();
175
176 sink.close();
177
178 siteRenderer.mergeDocumentIntoSite(writer, sink, siteRenderingContext);
179 }
180
181 @Override
182 public String getOutputName() {
183 return docRenderingContext.getOutputName();
184 }
185
186 @Override
187 public DocumentRenderingContext getRenderingContext() {
188 return docRenderingContext;
189 }
190
191 @Override
192 public boolean isOverwrite() {
193 return true;
194 }
195
196 @Override
197 public boolean isExternalReport() {
198 return false;
199 }
200
201 @Override
202 public String getReportMojoInfo() {
203 return reportMojoInfo;
204 }
205 }