Search in sources :

Example 1 with DocumentRenderer

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

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

the class SiteMojo method renderDoxiaDocuments.

/**
     * Render Doxia documents from the list given, but not reports.
     * 
     * @param documents a collection of documents containing both Doxia source files and reports
     * @return the sublist of documents that are not Doxia source files
     */
private List<DocumentRenderer> renderDoxiaDocuments(Map<String, DocumentRenderer> documents, SiteRenderingContext context, File outputDir, boolean generated) throws RendererException, IOException {
    Map<String, DocumentRenderer> doxiaDocuments = new TreeMap<String, DocumentRenderer>();
    List<DocumentRenderer> nonDoxiaDocuments = new ArrayList<DocumentRenderer>();
    Map<String, Integer> counts = new TreeMap<String, Integer>();
    for (Map.Entry<String, DocumentRenderer> entry : documents.entrySet()) {
        DocumentRenderer doc = entry.getValue();
        if (doc instanceof DoxiaDocumentRenderer) {
            doxiaDocuments.put(entry.getKey(), doc);
            DoxiaDocumentRenderer doxia = (DoxiaDocumentRenderer) doc;
            // count documents per parserId
            String parserId = doxia.getRenderingContext().getParserId();
            Integer count = counts.get(parserId);
            if (count == null) {
                count = 1;
            } else {
                count++;
            }
            counts.put(parserId, count);
        } else {
            nonDoxiaDocuments.add(doc);
        }
    }
    if (doxiaDocuments.size() > 0) {
        StringBuilder sb = new StringBuilder(15 * counts.size());
        for (Map.Entry<String, Integer> entry : counts.entrySet()) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(entry.getValue());
            sb.append(' ');
            sb.append(entry.getKey());
        }
        getLog().info("Rendering " + doxiaDocuments.size() + (generated ? " generated" : "") + " Doxia document" + (doxiaDocuments.size() > 1 ? "s" : "") + ": " + sb.toString());
        siteRenderer.render(doxiaDocuments.values(), context, outputDir);
    }
    return nonDoxiaDocuments;
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) DoxiaDocumentRenderer(org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer) DoxiaDocumentRenderer(org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with DocumentRenderer

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

the class SiteMojo method renderLocale.

private void renderLocale(Locale locale, List<MavenReportExecution> reports) throws IOException, RendererException, MojoFailureException, MojoExecutionException {
    SiteRenderingContext context = createSiteRenderingContext(locale);
    // MSITE-723 add generated site directory, in case some content has been put in pre-site phase
    context.addSiteDirectory(generatedSiteDirectory);
    context.setInputEncoding(getInputEncoding());
    context.setOutputEncoding(getOutputEncoding());
    context.setValidate(validate);
    if (validate) {
        getLog().info("Validation is switched on, xml input documents will be validated!");
    }
    File outputDir = getOutputDirectory(locale);
    Map<String, DocumentRenderer> documents = locateDocuments(context, reports, locale);
    // copy resources
    siteRenderer.copyResources(context, outputDir);
    // 1. render Doxia documents first
    List<DocumentRenderer> reportDocuments = renderDoxiaDocuments(documents, context, outputDir, false);
    // prepare external reports
    for (MavenReportExecution mavenReportExecution : reports) {
        MavenReport report = mavenReportExecution.getMavenReport();
        report.setReportOutputDirectory(outputDir);
    }
    siteRenderer.render(reportDocuments, context, outputDir);
    if (generateSitemap) {
        getLog().info("Generating Sitemap.");
        new SiteMap(getOutputEncoding(), i18n).generate(context.getDecoration(), generatedSiteDirectory, locale);
    }
    // 3. Generated docs must be (re-)done afterwards as they are often generated by reports
    context.getSiteDirectories().clear();
    context.addSiteDirectory(generatedSiteDirectory);
    Map<String, DocumentRenderer> generatedDocuments = siteRenderer.locateDocumentFiles(context);
    renderDoxiaDocuments(generatedDocuments, context, outputDir, true);
    // copy generated resources also
    siteRenderer.copyResources(context, outputDir);
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) File(java.io.File) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) DoxiaDocumentRenderer(org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer)

Example 4 with DocumentRenderer

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

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

the class SiteRunMojo method createWebApplication.

private WebAppContext createWebApplication() throws MojoExecutionException {
    File webXml = new File(tempWebappDirectory, "WEB-INF/web.xml");
    webXml.getParentFile().mkdirs();
    InputStream inStream = null;
    FileOutputStream outStream = null;
    try {
        inStream = getClass().getResourceAsStream("/run/web.xml");
        outStream = new FileOutputStream(webXml);
        IOUtil.copy(inStream, outStream);
        outStream.close();
        outStream = null;
        inStream.close();
        inStream = null;
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Unable to construct temporary webapp for running site", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to construct temporary webapp for running site", e);
    } finally {
        IOUtil.close(outStream);
        IOUtil.close(inStream);
    }
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setResourceBase(tempWebappDirectory.getAbsolutePath());
    webapp.setAttribute(DoxiaFilter.SITE_RENDERER_KEY, siteRenderer);
    webapp.getInitParams().put("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false");
    // For external reports
    project.getReporting().setOutputDirectory(tempWebappDirectory.getAbsolutePath());
    for (MavenReportExecution mavenReportExecution : getReports()) {
        mavenReportExecution.getMavenReport().setReportOutputDirectory(tempWebappDirectory);
    }
    // TODO: is it sane to call getReports() method a second time?
    List<MavenReportExecution> reports = getReports();
    List<Locale> localesList = getLocales();
    webapp.setAttribute(DoxiaFilter.LOCALES_LIST_KEY, localesList);
    // Default is first in the list
    Locale defaultLocale = localesList.get(0);
    Locale.setDefault(defaultLocale);
    try {
        Map<String, DoxiaBean> i18nDoxiaContexts = new HashMap<String, DoxiaBean>();
        for (Locale locale : localesList) {
            SiteRenderingContext i18nContext = createSiteRenderingContext(locale);
            i18nContext.setInputEncoding(getInputEncoding());
            i18nContext.setOutputEncoding(getOutputEncoding());
            SiteRenderingContext i18nGeneratedSiteContext = createSiteRenderingContext(locale);
            i18nGeneratedSiteContext.setInputEncoding(getInputEncoding());
            i18nGeneratedSiteContext.setOutputEncoding(getOutputEncoding());
            i18nGeneratedSiteContext.getSiteDirectories().clear();
            Map<String, DocumentRenderer> i18nDocuments = locateDocuments(i18nContext, reports, locale);
            DoxiaBean doxiaBean;
            if (defaultLocale.equals(locale)) {
                i18nGeneratedSiteContext.addSiteDirectory(generatedSiteDirectory);
                doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
            } else {
                i18nGeneratedSiteContext.addSiteDirectory(new File(generatedSiteDirectory, locale.getLanguage()));
                doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
            }
            i18nDoxiaContexts.put(locale.getLanguage(), doxiaBean);
            if (defaultLocale.equals(locale)) {
                i18nDoxiaContexts.put("default", doxiaBean);
            }
            if (defaultLocale.equals(locale)) {
                siteRenderer.copyResources(i18nContext, tempWebappDirectory);
            } else {
                siteRenderer.copyResources(i18nContext, new File(tempWebappDirectory, locale.getLanguage()));
            }
        }
        webapp.setAttribute(DoxiaFilter.I18N_DOXIA_CONTEXTS_KEY, i18nDoxiaContexts);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to set up webapp", e);
    }
    return webapp;
}
Also used : Locale(java.util.Locale) MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

DocumentRenderer (org.apache.maven.doxia.siterenderer.DocumentRenderer)6 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)5 ArrayList (java.util.ArrayList)3 MavenReport (org.apache.maven.reporting.MavenReport)3 MavenReportExecution (org.apache.maven.reporting.exec.MavenReportExecution)3 File (java.io.File)2 IOException (java.io.IOException)2 Locale (java.util.Locale)2 Map (java.util.Map)2 DoxiaDocumentRenderer (org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer)2 RenderingContext (org.apache.maven.doxia.siterenderer.RenderingContext)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1