Search in sources :

Example 1 with SiteToolException

use of org.apache.maven.doxia.tools.SiteToolException 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 SiteToolException

use of org.apache.maven.doxia.tools.SiteToolException 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 SiteToolException

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

the class AbstractSiteDescriptorMojo method prepareDecorationModel.

protected DecorationModel prepareDecorationModel(Locale locale) throws MojoExecutionException {
    DecorationModel decorationModel;
    try {
        decorationModel = siteTool.getDecorationModel(siteDirectory, locale, project, reactorProjects, localRepository, repositories);
    } catch (SiteToolException e) {
        throw new MojoExecutionException("SiteToolException: " + e.getMessage(), e);
    }
    if (relativizeDecorationLinks) {
        final String url = project.getUrl();
        if (url == null) {
            getLog().warn("No project URL defined - decoration links will not be relativized!");
        } else {
            List<Locale> localesList = getLocales();
            // Default is first in the list
            Locale defaultLocale = localesList.get(0);
            // MSITE-658
            final String localeUrl = locale.equals(defaultLocale) ? url : append(url, locale.getLanguage());
            getLog().info("Relativizing decoration links with respect to localized project URL: " + localeUrl);
            assembler.resolvePaths(decorationModel, localeUrl);
        }
    }
    return decorationModel;
}
Also used : Locale(java.util.Locale) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SiteToolException(org.apache.maven.doxia.tools.SiteToolException)

Example 4 with SiteToolException

use of org.apache.maven.doxia.tools.SiteToolException 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 5 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