Search in sources :

Example 6 with MavenReport

use of org.apache.maven.reporting.MavenReport 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 7 with MavenReport

use of org.apache.maven.reporting.MavenReport in project maven-plugins by apache.

the class AbstractSiteRenderingMojo method getReports.

protected List<MavenReportExecution> getReports() throws MojoExecutionException {
    List<MavenReportExecution> allReports;
    if (isMaven3OrMore()) {
        // Maven 3
        MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
        mavenReportExecutorRequest.setLocalRepository(localRepository);
        mavenReportExecutorRequest.setMavenSession(mavenSession);
        mavenReportExecutorRequest.setProject(project);
        mavenReportExecutorRequest.setReportPlugins(reportingPlugins);
        MavenReportExecutor mavenReportExecutor;
        try {
            mavenReportExecutor = (MavenReportExecutor) container.lookup(MavenReportExecutor.class.getName());
        } catch (ComponentLookupException e) {
            throw new MojoExecutionException("could not get MavenReportExecutor component", e);
        }
        allReports = mavenReportExecutor.buildMavenReports(mavenReportExecutorRequest);
    } else {
        // Maven 2
        allReports = new ArrayList<MavenReportExecution>(reports.size());
        for (MavenReport report : reports) {
            allReports.add(new MavenReportExecution(report));
        }
    }
    // filter out reports that can't be generated
    List<MavenReportExecution> reportExecutions = new ArrayList<MavenReportExecution>(allReports.size());
    for (MavenReportExecution exec : allReports) {
        if (exec.canGenerateReport()) {
            reportExecutions.add(exec);
        }
    }
    return reportExecutions;
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MavenReportExecutor(org.apache.maven.reporting.exec.MavenReportExecutor) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenReportExecutorRequest(org.apache.maven.reporting.exec.MavenReportExecutorRequest)

Example 8 with MavenReport

use of org.apache.maven.reporting.MavenReport 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 9 with MavenReport

use of org.apache.maven.reporting.MavenReport in project maven-plugins by apache.

the class AbstractSiteRenderingMojo method populateItemRefs.

private void populateItemRefs(List<MenuItem> items, Locale locale, Map<String, MavenReport> reportsByOutputName) {
    for (Iterator<MenuItem> i = items.iterator(); i.hasNext(); ) {
        MenuItem item = i.next();
        if (item.getRef() != null) {
            MavenReport report = reportsByOutputName.get(item.getRef());
            if (report != null) {
                if (item.getName() == null) {
                    item.setName(report.getName(locale));
                }
                if (item.getHref() == null || item.getHref().length() == 0) {
                    item.setHref(report.getOutputName() + ".html");
                }
            } else {
                getLog().warn("Unrecognised reference: '" + item.getRef() + "'");
                i.remove();
            }
        }
        populateItemRefs(item.getItems(), locale, reportsByOutputName);
    }
}
Also used : MavenReport(org.apache.maven.reporting.MavenReport) MenuItem(org.apache.maven.doxia.site.decoration.MenuItem)

Example 10 with MavenReport

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

Aggregations

MavenReport (org.apache.maven.reporting.MavenReport)12 ArrayList (java.util.ArrayList)7 File (java.io.File)5 MavenReportExecution (org.apache.maven.reporting.exec.MavenReportExecution)4 List (java.util.List)3 DocumentRenderer (org.apache.maven.doxia.siterenderer.DocumentRenderer)3 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 StringWriter (java.io.StringWriter)2 LinkedHashMap (java.util.LinkedHashMap)2 RenderingContext (org.apache.maven.doxia.siterenderer.RenderingContext)2 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)2 MavenReportExecutor (org.apache.maven.reporting.exec.MavenReportExecutor)2 MavenReportExecutorRequest (org.apache.maven.reporting.exec.MavenReportExecutorRequest)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 IOException (java.io.IOException)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1 DocumentTOCItem (org.apache.maven.doxia.document.DocumentTOCItem)1 IndexingSink (org.apache.maven.doxia.index.IndexingSink)1