Search in sources :

Example 1 with MojoLogWrapper

use of org.apache.maven.doxia.tools.MojoLogWrapper in project maven-plugins by apache.

the class ReportDocumentRenderer method renderDocument.

public void renderDocument(Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext) throws RendererException, FileNotFoundException {
    Locale locale = siteRenderingContext.getLocale();
    String localReportName = report.getName(locale);
    String msg = "Generating \"" + buffer().strong(localReportName) + "\" report";
    // CHECKSTYLE_OFF: MagicNumber
    log.info(reportMojoInfo == null ? (msg + '.') : (StringUtils.rightPad(msg, 40) + buffer().strong(" --- ").mojo(reportMojoInfo)));
    // CHECKSTYLE_ON: MagicNumber
    // main sink
    SiteRendererSink mainSink = new SiteRendererSink(renderingContext);
    // sink factory, for multi-page reports that need sub-sinks
    MultiPageSinkFactory multiPageSinkFactory = new MultiPageSinkFactory(renderingContext);
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        if (report instanceof MavenMultiPageReport) {
            // extended multi-page API
            ((MavenMultiPageReport) report).generate(mainSink, multiPageSinkFactory, locale);
        } else if (generateMultiPage(locale, multiPageSinkFactory, mainSink)) {
        // extended multi-page API for Maven 2.2, only accessible by reflection API
        } else {
            // old single-page-only API
            report.generate(mainSink, locale);
        }
    } catch (MavenReportException e) {
        String report = (reportMojoInfo == null) ? ('"' + localReportName + "\" report") : reportMojoInfo;
        throw new RendererException("Error generating " + report + ": " + e.getMessage(), e);
    } catch (LinkageError e) {
        String report = (reportMojoInfo == null) ? ('"' + localReportName + "\" report") : reportMojoInfo;
        log.warn("An issue has occurred with " + report + ", skipping LinkageError " + e.getMessage() + ", please report an issue to Maven dev team.", e);
    } finally {
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(originalClassLoader);
        }
        mainSink.close();
    }
    if (report.isExternalReport()) {
        // external reports are rendered from their own: no Doxia site rendering needed
        return;
    }
    // render main sink
    renderer.generateDocument(writer, mainSink, siteRenderingContext);
    // render sub-sinks, eventually created by multi-page reports
    try {
        List<MultiPageSubSink> sinks = multiPageSinkFactory.sinks();
        log.debug("Multipage report: " + sinks.size() + " subreports");
        for (MultiPageSubSink mySink : sinks) {
            mySink.enableLogging(new MojoLogWrapper(log));
            log.debug("  Rendering " + mySink.getOutputName());
            File outputFile = new File(mySink.getOutputDir(), mySink.getOutputName());
            Writer out = null;
            try {
                out = WriterFactory.newWriter(outputFile, siteRenderingContext.getOutputEncoding());
                renderer.generateDocument(out, mySink, siteRenderingContext);
                mySink.close();
                mySink = null;
                out.close();
                out = null;
            } finally {
                IOUtil.close(out);
                if (mySink != null) {
                    mySink.close();
                }
            }
        }
    } catch (IOException e) {
        throw new RendererException("Cannot create writer", e);
    }
}
Also used : Locale(java.util.Locale) IOException(java.io.IOException) MavenMultiPageReport(org.apache.maven.reporting.MavenMultiPageReport) RendererException(org.apache.maven.doxia.siterenderer.RendererException) MojoLogWrapper(org.apache.maven.doxia.tools.MojoLogWrapper) SiteRendererSink(org.apache.maven.doxia.siterenderer.sink.SiteRendererSink) File(java.io.File) Writer(java.io.Writer) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with MojoLogWrapper

use of org.apache.maven.doxia.tools.MojoLogWrapper 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

Locale (java.util.Locale)2 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)2 MojoLogWrapper (org.apache.maven.doxia.tools.MojoLogWrapper)2 File (java.io.File)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 RendererException (org.apache.maven.doxia.siterenderer.RendererException)1 MavenMultiPageReport (org.apache.maven.reporting.MavenMultiPageReport)1 MavenReport (org.apache.maven.reporting.MavenReport)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1