use of org.apache.maven.doxia.siterenderer.SiteRenderingContext in project maven-plugins by apache.
the class AbstractPmdReportTest method renderer.
/**
* Renderer the sink from the report mojo.
*
* @param mojo not null
* @param outputHtml not null
* @throws RendererException if any
* @throws IOException if any
*/
protected void renderer(AbstractPmdReport mojo, File outputHtml) throws RendererException, IOException {
SiteRenderingContext context = new SiteRenderingContext();
context.setDecoration(new DecorationModel());
context.setTemplateName("org/apache/maven/doxia/siterenderer/resources/default-site.vm");
context.setLocale(Locale.ENGLISH);
outputHtml.getParentFile().mkdirs();
try (Writer writer = WriterFactory.newXmlWriter(outputHtml)) {
mojo.getSiteRenderer().generateDocument(writer, (SiteRendererSink) mojo.getSink(), context);
}
}
use of org.apache.maven.doxia.siterenderer.SiteRenderingContext in project maven-plugins by apache.
the class PdfMojo method copyResources.
/**
* Parse the decoration model to find the skin artifact and copy its resources to the output dir.
*
* @param locale not null
* @throws MojoExecutionException if any
* @see #getDefaultDecorationModel()
*/
private void copyResources(Locale locale) throws MojoExecutionException {
final DecorationModel decorationModel = getDefaultDecorationModel();
if (decorationModel == null) {
return;
}
File skinFile;
try {
skinFile = siteTool.getSkinArtifactFromRepository(localRepository, project.getRemoteArtifactRepositories(), decorationModel).getFile();
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException: " + e.getMessage(), e);
}
if (skinFile == null) {
return;
}
if (getLog().isDebugEnabled()) {
getLog().debug("Copy resources from skin artifact: '" + skinFile + "'...");
}
try {
final SiteRenderingContext context = siteRenderer.createContextForSkin(skinFile, new HashMap<String, Object>(2), decorationModel, project.getName(), locale);
context.addSiteDirectory(new File(siteDirectory, locale.getLanguage()));
siteRenderer.copyResources(context, workingDirectory);
} catch (IOException e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
} catch (RendererException e) {
throw new MojoExecutionException("RendererException: " + e.getMessage(), e);
}
}
use of org.apache.maven.doxia.siterenderer.SiteRenderingContext in project maven-plugins by apache.
the class CheckstyleReportTest method renderer.
/**
* Renderer the sink from the report mojo.
*
* @param mojo not null
* @param outputHtml not null
* @throws RendererException if any
* @throws IOException if any
*/
private void renderer(CheckstyleReport mojo, File outputHtml) throws RendererException, Exception {
Writer writer = null;
SiteRenderingContext context = new SiteRenderingContext();
context.setDecoration(new DecorationModel());
context.setTemplateName("org/apache/maven/doxia/siterenderer/resources/default-site.vm");
context.setLocale(Locale.ENGLISH);
try {
outputHtml.getParentFile().mkdirs();
writer = WriterFactory.newXmlWriter(outputHtml);
mojo.execute();
writer.close();
writer = null;
} finally {
IOUtil.close(writer);
}
}
use of org.apache.maven.doxia.siterenderer.SiteRenderingContext in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method locateDocuments.
/**
* Locate every document to be rendered for given locale:<ul>
* <li>handwritten content, ie Doxia files,</li>
* <li>reports,</li>
* <li>"Project Information" and "Project Reports" category summaries.</li>
* </ul>
* @see CategorySummaryDocumentRenderer
*/
protected Map<String, DocumentRenderer> locateDocuments(SiteRenderingContext context, List<MavenReportExecution> reports, Locale locale) throws IOException, RendererException {
Map<String, DocumentRenderer> documents = siteRenderer.locateDocumentFiles(context);
Map<String, MavenReport> reportsByOutputName = locateReports(reports, documents, locale);
// TODO: I want to get rid of categories eventually. There's no way to add your own in a fully i18n manner
Map<String, List<MavenReport>> categories = categoriseReports(reportsByOutputName.values());
siteTool.populateReportsMenu(context.getDecoration(), locale, categories);
populateReportItems(context.getDecoration(), locale, reportsByOutputName);
if (categories.containsKey(MavenReport.CATEGORY_PROJECT_INFORMATION) && generateProjectInfo) {
// add "Project Information" category summary document
List<MavenReport> categoryReports = categories.get(MavenReport.CATEGORY_PROJECT_INFORMATION);
RenderingContext renderingContext = new RenderingContext(siteDirectory, "project-info.html");
String title = i18n.getString("site-plugin", locale, "report.information.title");
String desc1 = i18n.getString("site-plugin", locale, "report.information.description1");
String desc2 = i18n.getString("site-plugin", locale, "report.information.description2");
DocumentRenderer renderer = new CategorySummaryDocumentRenderer(renderingContext, title, desc1, desc2, i18n, categoryReports, getLog());
if (!documents.containsKey(renderer.getOutputName())) {
documents.put(renderer.getOutputName(), renderer);
} else {
getLog().info("Category summary '" + renderer.getOutputName() + "' skipped; already exists");
}
}
if (categories.containsKey(MavenReport.CATEGORY_PROJECT_REPORTS)) {
// add "Project Reports" category summary document
List<MavenReport> categoryReports = categories.get(MavenReport.CATEGORY_PROJECT_REPORTS);
RenderingContext renderingContext = new RenderingContext(siteDirectory, "project-reports.html");
String title = i18n.getString("site-plugin", locale, "report.project.title");
String desc1 = i18n.getString("site-plugin", locale, "report.project.description1");
String desc2 = i18n.getString("site-plugin", locale, "report.project.description2");
DocumentRenderer renderer = new CategorySummaryDocumentRenderer(renderingContext, title, desc1, desc2, i18n, categoryReports, getLog());
if (!documents.containsKey(renderer.getOutputName())) {
documents.put(renderer.getOutputName(), renderer);
} else {
getLog().info("Category summary '" + renderer.getOutputName() + "' skipped; already exists");
}
}
return documents;
}
use of org.apache.maven.doxia.siterenderer.SiteRenderingContext in project maven-plugins by apache.
the class AbstractSiteRenderingMojo method createSiteRenderingContext.
protected SiteRenderingContext createSiteRenderingContext(Locale locale) throws MojoExecutionException, IOException, MojoFailureException {
DecorationModel decorationModel = prepareDecorationModel(locale);
if (attributes == null) {
attributes = new HashMap<String, Object>();
}
if (attributes.get("project") == null) {
attributes.put("project", project);
}
if (attributes.get("inputEncoding") == null) {
attributes.put("inputEncoding", getInputEncoding());
}
if (attributes.get("outputEncoding") == null) {
attributes.put("outputEncoding", getOutputEncoding());
}
// Put any of the properties in directly into the Velocity context
for (Map.Entry<Object, Object> entry : project.getProperties().entrySet()) {
attributes.put((String) entry.getKey(), entry.getValue());
}
SiteRenderingContext context;
if (templateFile != null) {
getLog().info("Rendering site with " + templateFile + " template file.");
if (!templateFile.exists()) {
throw new MojoFailureException("Template file '" + templateFile + "' does not exist");
}
context = siteRenderer.createContextForTemplate(templateFile, attributes, decorationModel, project.getName(), locale);
} else {
try {
Artifact skinArtifact = siteTool.getSkinArtifactFromRepository(localRepository, repositories, decorationModel);
getLog().info("Rendering site with " + skinArtifact.getId() + " skin.");
context = siteRenderer.createContextForSkin(skinArtifact, attributes, decorationModel, project.getName(), locale);
} catch (SiteToolException e) {
throw new MojoExecutionException("SiteToolException while preparing skin: " + e.getMessage(), e);
} catch (RendererException e) {
throw new MojoExecutionException("RendererException while preparing context for skin: " + e.getMessage(), e);
}
}
// Generate static site
if (!locale.getLanguage().equals(Locale.getDefault().getLanguage())) {
context.addSiteDirectory(new File(siteDirectory, locale.getLanguage()));
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "xdoc");
context.addModuleDirectory(new File(xdocDirectory, locale.getLanguage()), "fml");
} else {
context.addSiteDirectory(siteDirectory);
context.addModuleDirectory(xdocDirectory, "xdoc");
context.addModuleDirectory(xdocDirectory, "fml");
}
if (moduleExcludes != null) {
context.setModuleExcludes(moduleExcludes);
}
if (saveProcessedContent) {
context.setProcessedContentOutput(new File(generatedSiteDirectory, "processed"));
}
return context;
}
Aggregations