Search in sources :

Example 1 with RenderingContext

use of org.apache.maven.doxia.siterenderer.RenderingContext 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);
    }
}
Also used : Locale(java.util.Locale) RenderingContext(org.apache.maven.doxia.siterenderer.RenderingContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SiteRendererSink(org.apache.maven.doxia.siterenderer.sink.SiteRendererSink) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with RenderingContext

use of org.apache.maven.doxia.siterenderer.RenderingContext 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 3 with RenderingContext

use of org.apache.maven.doxia.siterenderer.RenderingContext in project maven-plugins by apache.

the class AbstractSiteRenderingMojo method locateReports.

/**
     * Go through the list of reports and process each one like this:
     * <ul>
     * <li>Add the report to a map of reports keyed by filename having the report itself as value
     * <li>If the report is not yet in the map of documents, add it together with a suitable renderer
     * </ul>
     *
     * @param reports A List of MavenReports
     * @param documents A Map of documents, keyed by filename
     * @param locale the Locale the reports are processed for.
     * @return A map with all reports keyed by filename having the report itself as value.
     * The map will be used to populate a menu.
     */
protected Map<String, MavenReport> locateReports(List<MavenReportExecution> reports, Map<String, DocumentRenderer> documents, Locale locale) {
    // copy Collection to prevent ConcurrentModificationException
    List<MavenReportExecution> filtered = new ArrayList<MavenReportExecution>(reports);
    Map<String, MavenReport> reportsByOutputName = new LinkedHashMap<String, MavenReport>();
    for (MavenReportExecution mavenReportExecution : filtered) {
        MavenReport report = mavenReportExecution.getMavenReport();
        String outputName = report.getOutputName() + ".html";
        // Always add the report to the menu, see MSITE-150
        reportsByOutputName.put(report.getOutputName(), report);
        if (documents.containsKey(outputName)) {
            String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);
            String reportMojoInfo = (mavenReportExecution.getGoal() == null) ? "" : (" (" + mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion() + ':' + mavenReportExecution.getGoal() + ')');
            getLog().info("Skipped \"" + report.getName(locale) + "\" report" + reportMojoInfo + ", file \"" + outputName + "\" already exists for the " + displayLanguage + " version.");
            reports.remove(mavenReportExecution);
        } else {
            RenderingContext renderingContext = new RenderingContext(siteDirectory, outputName);
            DocumentRenderer renderer = new ReportDocumentRenderer(mavenReportExecution, renderingContext, getLog());
            documents.put(outputName, renderer);
        }
    }
    return reportsByOutputName;
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) RenderingContext(org.apache.maven.doxia.siterenderer.RenderingContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) ArrayList(java.util.ArrayList) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RenderingContext

use of org.apache.maven.doxia.siterenderer.RenderingContext in project maven-plugins by apache.

the class AbstractProjectInfoReport method execute.

@Override
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 {
        String filename = getOutputName() + ".html";
        DecorationModel model = new DecorationModel();
        model.setBody(new Body());
        Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put("outputEncoding", "UTF-8");
        attributes.put("project", project);
        Locale locale = Locale.getDefault();
        Artifact defaultSkin = siteTool.getDefaultSkinArtifact(localRepository, project.getRemoteArtifactRepositories());
        SiteRenderingContext siteContext = siteRenderer.createContextForSkin(defaultSkin.getFile(), attributes, model, getName(locale), locale);
        RenderingContext context = new RenderingContext(outputDirectory, filename);
        SiteRendererSink sink = new SiteRendererSink(context);
        generate(sink, null, locale);
        outputDirectory.mkdirs();
        writer = new OutputStreamWriter(new FileOutputStream(new File(outputDirectory, filename)), "UTF-8");
        siteRenderer.generateDocument(writer, sink, siteContext);
        siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), outputDirectory);
        writer.close();
        writer = null;
    } 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 (SiteToolException 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 {
        IOUtil.close(writer);
    }
}
Also used : Locale(java.util.Locale) RenderingContext(org.apache.maven.doxia.siterenderer.RenderingContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) IOException(java.io.IOException) 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) SiteRendererSink(org.apache.maven.doxia.siterenderer.sink.SiteRendererSink) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Body(org.apache.maven.doxia.site.decoration.Body) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

RenderingContext (org.apache.maven.doxia.siterenderer.RenderingContext)4 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)3 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 DocumentRenderer (org.apache.maven.doxia.siterenderer.DocumentRenderer)2 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenReport (org.apache.maven.reporting.MavenReport)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Artifact (org.apache.maven.artifact.Artifact)1 Body (org.apache.maven.doxia.site.decoration.Body)1 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)1