Search in sources :

Example 6 with SiteToolException

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

the class AbstractProjectInfoReport method execute.

@Override
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 {
        String filename = getOutputName() + ".html";
        DecorationModel model = new DecorationModel();
        model.setBody(new Body());
        Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put("outputEncoding", "UTF-8");
        attributes.put("project", project);
        Locale locale = Locale.getDefault();
        Artifact defaultSkin = siteTool.getDefaultSkinArtifact(localRepository, project.getRemoteArtifactRepositories());
        SiteRenderingContext siteContext = siteRenderer.createContextForSkin(defaultSkin.getFile(), attributes, model, getName(locale), locale);
        RenderingContext context = new RenderingContext(outputDirectory, filename);
        SiteRendererSink sink = new SiteRendererSink(context);
        generate(sink, null, locale);
        outputDirectory.mkdirs();
        writer = new OutputStreamWriter(new FileOutputStream(new File(outputDirectory, filename)), "UTF-8");
        siteRenderer.generateDocument(writer, sink, siteContext);
        siteRenderer.copyResources(siteContext, new File(project.getBasedir(), "src/site/resources"), outputDirectory);
        writer.close();
        writer = null;
    } 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 (SiteToolException 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 {
        IOUtil.close(writer);
    }
}
Also used : Locale(java.util.Locale) RenderingContext(org.apache.maven.doxia.siterenderer.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) 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) 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

DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)6 SiteToolException (org.apache.maven.doxia.tools.SiteToolException)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 File (java.io.File)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 Locale (java.util.Locale)3 RendererException (org.apache.maven.doxia.siterenderer.RendererException)3 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)3 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Artifact (org.apache.maven.artifact.Artifact)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1