use of org.apache.maven.doxia.siterenderer.sink.SiteRendererSink in project camel by apache.
the class DocumentGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
RenderingContext context = new RenderingContext(reportOutputDirectory, getOutputName() + ".html");
SiteRendererSink sink = new SiteRendererSink(context);
Locale locale = Locale.getDefault();
try {
generate(sink, locale);
} catch (MavenReportException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.doxia.siterenderer.sink.SiteRendererSink in project maven-plugins by apache.
the class JavadocReport method doExecute.
/** {@inheritDoc} */
public void doExecute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("Skipping javadoc generation");
return;
}
try {
RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html");
SiteRendererSink sink = new SiteRendererSink(context);
Locale locale = Locale.getDefault();
generate(sink, locale);
} catch (MavenReportException e) {
failOnError("An error has occurred in " + getName(Locale.ENGLISH) + " report generation", e);
} catch (RuntimeException e) {
failOnError("An error has occurred in " + getName(Locale.ENGLISH) + " report generation", e);
}
}
use of org.apache.maven.doxia.siterenderer.sink.SiteRendererSink in project maven-plugins by apache.
the class ReportDocumentRenderer method renderDocument.
public void renderDocument(Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext) throws RendererException, FileNotFoundException {
Locale locale = siteRenderingContext.getLocale();
String localReportName = report.getName(locale);
String msg = "Generating \"" + buffer().strong(localReportName) + "\" report";
// CHECKSTYLE_OFF: MagicNumber
log.info(reportMojoInfo == null ? (msg + '.') : (StringUtils.rightPad(msg, 40) + buffer().strong(" --- ").mojo(reportMojoInfo)));
// CHECKSTYLE_ON: MagicNumber
// main sink
SiteRendererSink mainSink = new SiteRendererSink(renderingContext);
// sink factory, for multi-page reports that need sub-sinks
MultiPageSinkFactory multiPageSinkFactory = new MultiPageSinkFactory(renderingContext);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
if (report instanceof MavenMultiPageReport) {
// extended multi-page API
((MavenMultiPageReport) report).generate(mainSink, multiPageSinkFactory, locale);
} else if (generateMultiPage(locale, multiPageSinkFactory, mainSink)) {
// extended multi-page API for Maven 2.2, only accessible by reflection API
} else {
// old single-page-only API
report.generate(mainSink, locale);
}
} catch (MavenReportException e) {
String report = (reportMojoInfo == null) ? ('"' + localReportName + "\" report") : reportMojoInfo;
throw new RendererException("Error generating " + report + ": " + e.getMessage(), e);
} catch (LinkageError e) {
String report = (reportMojoInfo == null) ? ('"' + localReportName + "\" report") : reportMojoInfo;
log.warn("An issue has occurred with " + report + ", skipping LinkageError " + e.getMessage() + ", please report an issue to Maven dev team.", e);
} finally {
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
mainSink.close();
}
if (report.isExternalReport()) {
// external reports are rendered from their own: no Doxia site rendering needed
return;
}
// render main sink
renderer.generateDocument(writer, mainSink, siteRenderingContext);
// render sub-sinks, eventually created by multi-page reports
try {
List<MultiPageSubSink> sinks = multiPageSinkFactory.sinks();
log.debug("Multipage report: " + sinks.size() + " subreports");
for (MultiPageSubSink mySink : sinks) {
mySink.enableLogging(new MojoLogWrapper(log));
log.debug(" Rendering " + mySink.getOutputName());
File outputFile = new File(mySink.getOutputDir(), mySink.getOutputName());
Writer out = null;
try {
out = WriterFactory.newWriter(outputFile, siteRenderingContext.getOutputEncoding());
renderer.generateDocument(out, mySink, siteRenderingContext);
mySink.close();
mySink = null;
out.close();
out = null;
} finally {
IOUtil.close(out);
if (mySink != null) {
mySink.close();
}
}
}
} catch (IOException e) {
throw new RendererException("Cannot create writer", e);
}
}
use of org.apache.maven.doxia.siterenderer.sink.SiteRendererSink in project maven-plugins by apache.
the class AbstractChangesReport method execute.
public void execute() throws MojoExecutionException {
if (!canGenerateReport()) {
return;
}
// TODO: push to a helper? Could still be improved by taking more of the site information from the site plugin
Writer writer = null;
try {
DecorationModel model = new DecorationModel();
model.setBody(new Body());
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("outputEncoding", getOutputEncoding());
Locale locale = Locale.getDefault();
SiteRenderingContext siteContext = siteRenderer.createContextForSkin(getSkinArtifactFile(), attributes, model, getName(locale), locale);
siteContext.setOutputEncoding(getOutputEncoding());
RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html");
SiteRendererSink sink = new SiteRendererSink(context);
generate(sink, null, locale);
outputDirectory.mkdirs();
File file = new File(outputDirectory, getOutputName() + ".html");
writer = new OutputStreamWriter(new FileOutputStream(file), getOutputEncoding());
siteRenderer.generateDocument(writer, sink, siteContext);
writer.close();
writer = null;
siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), outputDirectory);
} catch (RendererException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (IOException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} catch (MavenReportException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.apache.maven.doxia.siterenderer.sink.SiteRendererSink in project maven-plugins by apache.
the class CategorySummaryDocumentRenderer method renderDocument.
public void renderDocument(Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext) throws RendererException, FileNotFoundException {
SiteRendererSink sink = new SiteRendererSink(renderingContext);
if (log != null) {
sink.enableLogging(new MojoLogWrapper(log));
}
sink.head();
sink.title();
sink.text(title);
sink.title_();
sink.head_();
sink.body();
sink.section1();
sink.sectionTitle1();
sink.text(title);
sink.sectionTitle1_();
sink.paragraph();
sink.text(desc1 + " ");
sink.link("http://maven.apache.org");
sink.text("Maven");
sink.link_();
sink.text(" " + desc2);
sink.paragraph_();
sink.section2();
sink.sectionTitle2();
Locale locale = siteRenderingContext.getLocale();
sink.text(i18n.getString("site-plugin", locale, "report.category.sectionTitle"));
sink.sectionTitle2_();
sink.table();
sink.tableRows(new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT }, false);
String name = i18n.getString("site-plugin", locale, "report.category.column.document");
String description = i18n.getString("site-plugin", locale, "report.category.column.description");
sink.tableRow();
sink.tableHeaderCell();
sink.text(name);
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text(description);
sink.tableHeaderCell_();
sink.tableRow_();
if (categoryReports != null) {
for (MavenReport report : categoryReports) {
sink.tableRow();
sink.tableCell();
sink.link(report.getOutputName() + ".html");
sink.text(report.getName(locale));
sink.link_();
sink.tableCell_();
sink.tableCell();
sink.text(report.getDescription(locale));
sink.tableCell_();
sink.tableRow_();
}
}
sink.tableRows_();
sink.table_();
sink.section2_();
sink.section1_();
sink.body_();
sink.flush();
sink.close();
renderer.generateDocument(writer, sink, siteRenderingContext);
}
Aggregations