Search in sources :

Example 1 with SiteRenderingContext

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);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) Writer(java.io.Writer)

Example 2 with SiteRenderingContext

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);
    }
}
Also used : RendererException(org.apache.maven.doxia.siterenderer.RendererException) DocumentRendererException(org.apache.maven.doxia.docrenderer.DocumentRendererException) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) IOException(java.io.IOException) File(java.io.File) SiteToolException(org.apache.maven.doxia.tools.SiteToolException)

Example 3 with SiteRenderingContext

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);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) Writer(java.io.Writer)

Example 4 with SiteRenderingContext

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;
}
Also used : MavenReport(org.apache.maven.reporting.MavenReport) RenderingContext(org.apache.maven.doxia.siterenderer.RenderingContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) ArrayList(java.util.ArrayList) List(java.util.List) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer)

Example 5 with SiteRenderingContext

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;
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Artifact(org.apache.maven.artifact.Artifact) SiteToolException(org.apache.maven.doxia.tools.SiteToolException) RendererException(org.apache.maven.doxia.siterenderer.RendererException) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Aggregations

SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)11 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)7 File (java.io.File)6 IOException (java.io.IOException)5 Writer (java.io.Writer)5 RendererException (org.apache.maven.doxia.siterenderer.RendererException)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 DocumentRenderer (org.apache.maven.doxia.siterenderer.DocumentRenderer)4 FileOutputStream (java.io.FileOutputStream)3 SiteToolException (org.apache.maven.doxia.tools.SiteToolException)3 OutputStreamWriter (java.io.OutputStreamWriter)2 Map (java.util.Map)2 Artifact (org.apache.maven.artifact.Artifact)2 Body (org.apache.maven.doxia.site.decoration.Body)2 RenderingContext (org.apache.maven.doxia.siterenderer.RenderingContext)2 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenReport (org.apache.maven.reporting.MavenReport)2