Search in sources :

Example 1 with RendererException

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

use of org.apache.maven.doxia.siterenderer.RendererException 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)

Example 3 with RendererException

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

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

the class AbstractChangesReport method execute.

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 {
        DecorationModel model = new DecorationModel();
        model.setBody(new Body());
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put("outputEncoding", getOutputEncoding());
        Locale locale = Locale.getDefault();
        SiteRenderingContext siteContext = siteRenderer.createContextForSkin(getSkinArtifactFile(), attributes, model, getName(locale), locale);
        siteContext.setOutputEncoding(getOutputEncoding());
        RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html");
        SiteRendererSink sink = new SiteRendererSink(context);
        generate(sink, null, locale);
        outputDirectory.mkdirs();
        File file = new File(outputDirectory, getOutputName() + ".html");
        writer = new OutputStreamWriter(new FileOutputStream(file), getOutputEncoding());
        siteRenderer.generateDocument(writer, sink, siteContext);
        writer.close();
        writer = null;
        siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), outputDirectory);
    } 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 (MavenReportException e) {
        throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : Locale(java.util.Locale) RenderingContext(org.apache.maven.doxia.sink.render.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) 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)

Example 5 with RendererException

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

the class SiteMojo method execute.

/**
     * {@inheritDoc} Generate the project site
     * <p/>
     * throws MojoExecutionException if any
     *
     * @see org.apache.maven.plugin.Mojo#execute()
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("maven.site.skip = true: Skipping site generation");
        return;
    }
    if (getLog().isDebugEnabled()) {
        getLog().debug("executing Site Mojo");
    }
    checkInputEncoding();
    List<MavenReportExecution> reports;
    if (generateReports) {
        reports = getReports();
    } else {
        reports = Collections.emptyList();
    }
    try {
        List<Locale> localesList = getLocales();
        // Default is first in the list
        Locale defaultLocale = localesList.get(0);
        Locale.setDefault(defaultLocale);
        for (Locale locale : localesList) {
            renderLocale(locale, reports);
        }
    } catch (RendererException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error during site generation", e);
    }
}
Also used : Locale(java.util.Locale) MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) RendererException(org.apache.maven.doxia.siterenderer.RendererException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException)

Aggregations

RendererException (org.apache.maven.doxia.siterenderer.RendererException)7 IOException (java.io.IOException)6 File (java.io.File)5 Locale (java.util.Locale)5 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)4 Writer (java.io.Writer)3 HashMap (java.util.HashMap)3 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)3 SiteToolException (org.apache.maven.doxia.tools.SiteToolException)3 MavenReportException (org.apache.maven.reporting.MavenReportException)3 FileOutputStream (java.io.FileOutputStream)2 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 LinkedHashMap (java.util.LinkedHashMap)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1