Search in sources :

Example 1 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 2 with DecorationModel

use of org.apache.maven.doxia.site.decoration.DecorationModel 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 3 with DecorationModel

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

the class DocumentModelBuilderTest method getDecorationModelFromFile.

private DecorationModel getDecorationModelFromFile(File descriptorFile) throws IOException, XmlPullParserException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(descriptorFile);
        final DecorationModel decorationModel = new DecorationXpp3Reader().read(reader);
        reader.close();
        reader = null;
        return decorationModel;
    } finally {
        IOUtil.close(reader);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) Reader(java.io.Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader)

Example 4 with DecorationModel

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

the class DocumentModelBuilderTest method testGetDocumentModelWithSiteDescriptor.

/**
     * Test of getDocumentModel method, of class DocumentModelBuilder.
     * @throws Exception if something happens.
     */
public void testGetDocumentModelWithSiteDescriptor() throws Exception {
    File descriptorFile = new File(testBaseDir() + "src/site/", "model_builder_site.xml");
    DecorationModel dModel = getDecorationModelFromFile(descriptorFile);
    DocumentModel model = new DocumentModelBuilder(new ModelBuilderMavenProjectStub(), dModel).getDocumentModel();
    DocumentTOC toc = model.getToc();
    assertEquals(1, toc.getItems().size());
    assertEquals("Intro", toc.getItems().get(0).getName());
    assertEquals("index.html", toc.getItems().get(0).getRef());
}
Also used : DocumentTOC(org.apache.maven.doxia.document.DocumentTOC) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) ModelBuilderMavenProjectStub(org.apache.maven.plugins.pdf.stubs.ModelBuilderMavenProjectStub) File(java.io.File) DocumentModel(org.apache.maven.doxia.document.DocumentModel)

Example 5 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)

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