Search in sources :

Example 6 with DecorationModel

use of org.apache.maven.doxia.site.decoration.DecorationModel in project maven-plugins by apache.

the class CheckstyleReportTest method renderer.

/**
     * Renderer the sink from the report mojo.
     *
     * @param mojo not null
     * @param outputHtml not null
     * @throws RendererException if any
     * @throws IOException if any
     */
private void renderer(CheckstyleReport mojo, File outputHtml) throws RendererException, Exception {
    Writer writer = null;
    SiteRenderingContext context = new SiteRenderingContext();
    context.setDecoration(new DecorationModel());
    context.setTemplateName("org/apache/maven/doxia/siterenderer/resources/default-site.vm");
    context.setLocale(Locale.ENGLISH);
    try {
        outputHtml.getParentFile().mkdirs();
        writer = WriterFactory.newXmlWriter(outputHtml);
        mojo.execute();
        writer.close();
        writer = null;
    } finally {
        IOUtil.close(writer);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) Writer(java.io.Writer)

Example 7 with DecorationModel

use of org.apache.maven.doxia.site.decoration.DecorationModel in project maven-plugins by apache.

the class AbstractPmdReportTest method renderer.

/**
     * Renderer the sink from the report mojo.
     *
     * @param mojo not null
     * @param outputHtml not null
     * @throws RendererException if any
     * @throws IOException if any
     */
protected void renderer(AbstractPmdReport mojo, File outputHtml) throws RendererException, IOException {
    SiteRenderingContext context = new SiteRenderingContext();
    context.setDecoration(new DecorationModel());
    context.setTemplateName("org/apache/maven/doxia/siterenderer/resources/default-site.vm");
    context.setLocale(Locale.ENGLISH);
    outputHtml.getParentFile().mkdirs();
    try (Writer writer = WriterFactory.newXmlWriter(outputHtml)) {
        mojo.getSiteRenderer().generateDocument(writer, (SiteRendererSink) mojo.getSink(), context);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) Writer(java.io.Writer)

Example 8 with DecorationModel

use of org.apache.maven.doxia.site.decoration.DecorationModel in project webservices-axiom by apache.

the class PostProcessMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    DecorationModel decorationModel;
    try {
        decorationModel = siteTool.getDecorationModel(siteDirectory, siteTool.getSiteLocales(locales).get(0), project, reactorProjects, localRepository, repositories);
    } catch (SiteToolException ex) {
        throw new MojoExecutionException("SiteToolException: " + ex.getMessage(), ex);
    }
    String head = decorationModel.getBody().getHead();
    DirectoryScanner ds = new DirectoryScanner();
    ds.setIncludes(new String[] { "**/*.html" });
    ds.setBasedir(javadocDirectory);
    ds.scan();
    for (String relativePath : ds.getIncludedFiles()) {
        File file = new File(javadocDirectory, relativePath);
        File tmpFile = new File(javadocDirectory, relativePath + ".tmp");
        file.renameTo(tmpFile);
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(tmpFile), "UTF-8"));
            try {
                PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
                try {
                    String line;
                    while ((line = in.readLine()) != null) {
                        if (line.equals("</head>")) {
                            out.println(head);
                        }
                        out.println(line);
                    }
                } finally {
                    out.close();
                }
            } finally {
                in.close();
            }
        } catch (IOException ex) {
            throw new MojoExecutionException("Failed to process " + relativePath + ": " + ex.getMessage(), ex);
        }
        tmpFile.delete();
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SiteToolException(org.apache.maven.doxia.tools.SiteToolException) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 9 with DecorationModel

use of org.apache.maven.doxia.site.decoration.DecorationModel in project maven-plugins by apache.

the class AbstractChangeLogReportTest method renderer.

/**
     * Renderer the sink from the report mojo.
     *
     * @param mojo       not null
     * @param outputHtml not null
     * @throws RendererException if any
     * @throws IOException       if any
     */
protected void renderer(ChangeLogReport mojo, File outputHtml) throws RendererException, IOException {
    Writer writer = null;
    SiteRenderingContext context = new SiteRenderingContext();
    context.setDecoration(new DecorationModel());
    context.setTemplateName("org/apache/maven/doxia/siterenderer/resources/default-site.vm");
    try {
        outputHtml.getParentFile().mkdirs();
        writer = WriterFactory.newXmlWriter(outputHtml);
        mojo.getSiteRenderer().generateDocument(writer, (SiteRendererSink) mojo.getSink(), context);
        writer.close();
        writer = null;
    } finally {
        IOUtil.close(writer);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) Writer(java.io.Writer)

Example 10 with DecorationModel

use of org.apache.maven.doxia.site.decoration.DecorationModel in project maven-plugins by apache.

the class PdfMojo method getDefaultDecorationModel.

/**
     * @return the DecorationModel instance from <code>site.xml</code>
     * @throws MojoExecutionException if any
     */
private DecorationModel getDefaultDecorationModel() throws MojoExecutionException {
    if (this.defaultDecorationModel == null) {
        final Locale locale = getDefaultLocale();
        final File descriptorFile = siteTool.getSiteDescriptor(siteDirectory, locale);
        DecorationModel decoration = null;
        if (descriptorFile.exists()) {
            XmlStreamReader reader = null;
            try {
                reader = new XmlStreamReader(descriptorFile);
                String siteDescriptorContent = IOUtil.toString(reader);
                reader.close();
                reader = null;
                siteDescriptorContent = siteTool.getInterpolatedSiteDescriptorContent(new HashMap<String, String>(2), project, siteDescriptorContent);
                decoration = new DecorationXpp3Reader().read(new StringReader(siteDescriptorContent));
            } catch (XmlPullParserException e) {
                throw new MojoExecutionException("Error parsing site descriptor", e);
            } catch (IOException e) {
                throw new MojoExecutionException("Error reading site descriptor", e);
            } catch (SiteToolException e) {
                throw new MojoExecutionException("Error when interpoling site descriptor", e);
            } finally {
                IOUtil.close(reader);
            }
        }
        this.defaultDecorationModel = decoration;
    }
    return this.defaultDecorationModel;
}
Also used : Locale(java.util.Locale) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) StringReader(java.io.StringReader) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) File(java.io.File) SiteToolException(org.apache.maven.doxia.tools.SiteToolException)

Aggregations

DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)13 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 File (java.io.File)7 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)7 IOException (java.io.IOException)6 SiteToolException (org.apache.maven.doxia.tools.SiteToolException)6 Writer (java.io.Writer)5 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 RendererException (org.apache.maven.doxia.siterenderer.RendererException)4 FileOutputStream (java.io.FileOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Artifact (org.apache.maven.artifact.Artifact)2 Body (org.apache.maven.doxia.site.decoration.Body)2 DecorationXpp3Reader (org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader)2 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1