Search in sources :

Example 1 with RenderingContext

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

the class JavadocReport method doExecute.

/** {@inheritDoc} */
public void doExecute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping javadoc generation");
        return;
    }
    try {
        RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html");
        SiteRendererSink sink = new SiteRendererSink(context);
        Locale locale = Locale.getDefault();
        generate(sink, locale);
    } catch (MavenReportException e) {
        failOnError("An error has occurred in " + getName(Locale.ENGLISH) + " report generation", e);
    } catch (RuntimeException e) {
        failOnError("An error has occurred in " + getName(Locale.ENGLISH) + " report generation", e);
    }
}
Also used : Locale(java.util.Locale) RenderingContext(org.apache.maven.doxia.sink.render.RenderingContext) SiteRendererSink(org.apache.maven.doxia.siterenderer.sink.SiteRendererSink) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with RenderingContext

use of org.apache.maven.doxia.sink.render.RenderingContext 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)

Aggregations

Locale (java.util.Locale)2 RenderingContext (org.apache.maven.doxia.sink.render.RenderingContext)2 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)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 Body (org.apache.maven.doxia.site.decoration.Body)1 DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)1 RendererException (org.apache.maven.doxia.siterenderer.RendererException)1 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1