Search in sources :

Example 1 with MavenReportExecution

use of org.apache.maven.reporting.exec.MavenReportExecution in project maven-plugins by apache.

the class SiteMojo method renderLocale.

private void renderLocale(Locale locale, List<MavenReportExecution> reports) throws IOException, RendererException, MojoFailureException, MojoExecutionException {
    SiteRenderingContext context = createSiteRenderingContext(locale);
    // MSITE-723 add generated site directory, in case some content has been put in pre-site phase
    context.addSiteDirectory(generatedSiteDirectory);
    context.setInputEncoding(getInputEncoding());
    context.setOutputEncoding(getOutputEncoding());
    context.setValidate(validate);
    if (validate) {
        getLog().info("Validation is switched on, xml input documents will be validated!");
    }
    File outputDir = getOutputDirectory(locale);
    Map<String, DocumentRenderer> documents = locateDocuments(context, reports, locale);
    // copy resources
    siteRenderer.copyResources(context, outputDir);
    // 1. render Doxia documents first
    List<DocumentRenderer> reportDocuments = renderDoxiaDocuments(documents, context, outputDir, false);
    // prepare external reports
    for (MavenReportExecution mavenReportExecution : reports) {
        MavenReport report = mavenReportExecution.getMavenReport();
        report.setReportOutputDirectory(outputDir);
    }
    siteRenderer.render(reportDocuments, context, outputDir);
    if (generateSitemap) {
        getLog().info("Generating Sitemap.");
        new SiteMap(getOutputEncoding(), i18n).generate(context.getDecoration(), generatedSiteDirectory, locale);
    }
    // 3. Generated docs must be (re-)done afterwards as they are often generated by reports
    context.getSiteDirectories().clear();
    context.addSiteDirectory(generatedSiteDirectory);
    Map<String, DocumentRenderer> generatedDocuments = siteRenderer.locateDocumentFiles(context);
    renderDoxiaDocuments(generatedDocuments, context, outputDir, true);
    // copy generated resources also
    siteRenderer.copyResources(context, outputDir);
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) File(java.io.File) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) DoxiaDocumentRenderer(org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer)

Example 2 with MavenReportExecution

use of org.apache.maven.reporting.exec.MavenReportExecution in project maven-plugins by apache.

the class AbstractSiteRenderingMojo method getReports.

protected List<MavenReportExecution> getReports() throws MojoExecutionException {
    List<MavenReportExecution> allReports;
    if (isMaven3OrMore()) {
        // Maven 3
        MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
        mavenReportExecutorRequest.setLocalRepository(localRepository);
        mavenReportExecutorRequest.setMavenSession(mavenSession);
        mavenReportExecutorRequest.setProject(project);
        mavenReportExecutorRequest.setReportPlugins(reportingPlugins);
        MavenReportExecutor mavenReportExecutor;
        try {
            mavenReportExecutor = (MavenReportExecutor) container.lookup(MavenReportExecutor.class.getName());
        } catch (ComponentLookupException e) {
            throw new MojoExecutionException("could not get MavenReportExecutor component", e);
        }
        allReports = mavenReportExecutor.buildMavenReports(mavenReportExecutorRequest);
    } else {
        // Maven 2
        allReports = new ArrayList<MavenReportExecution>(reports.size());
        for (MavenReport report : reports) {
            allReports.add(new MavenReportExecution(report));
        }
    }
    // filter out reports that can't be generated
    List<MavenReportExecution> reportExecutions = new ArrayList<MavenReportExecution>(allReports.size());
    for (MavenReportExecution exec : allReports) {
        if (exec.canGenerateReport()) {
            reportExecutions.add(exec);
        }
    }
    return reportExecutions;
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MavenReportExecutor(org.apache.maven.reporting.exec.MavenReportExecutor) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenReportExecutorRequest(org.apache.maven.reporting.exec.MavenReportExecutorRequest)

Example 3 with MavenReportExecution

use of org.apache.maven.reporting.exec.MavenReportExecution in project maven-plugins by apache.

the class AbstractSiteRenderingMojo method locateReports.

/**
     * Go through the list of reports and process each one like this:
     * <ul>
     * <li>Add the report to a map of reports keyed by filename having the report itself as value
     * <li>If the report is not yet in the map of documents, add it together with a suitable renderer
     * </ul>
     *
     * @param reports A List of MavenReports
     * @param documents A Map of documents, keyed by filename
     * @param locale the Locale the reports are processed for.
     * @return A map with all reports keyed by filename having the report itself as value.
     * The map will be used to populate a menu.
     */
protected Map<String, MavenReport> locateReports(List<MavenReportExecution> reports, Map<String, DocumentRenderer> documents, Locale locale) {
    // copy Collection to prevent ConcurrentModificationException
    List<MavenReportExecution> filtered = new ArrayList<MavenReportExecution>(reports);
    Map<String, MavenReport> reportsByOutputName = new LinkedHashMap<String, MavenReport>();
    for (MavenReportExecution mavenReportExecution : filtered) {
        MavenReport report = mavenReportExecution.getMavenReport();
        String outputName = report.getOutputName() + ".html";
        // Always add the report to the menu, see MSITE-150
        reportsByOutputName.put(report.getOutputName(), report);
        if (documents.containsKey(outputName)) {
            String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);
            String reportMojoInfo = (mavenReportExecution.getGoal() == null) ? "" : (" (" + mavenReportExecution.getPlugin().getArtifactId() + ':' + mavenReportExecution.getPlugin().getVersion() + ':' + mavenReportExecution.getGoal() + ')');
            getLog().info("Skipped \"" + report.getName(locale) + "\" report" + reportMojoInfo + ", file \"" + outputName + "\" already exists for the " + displayLanguage + " version.");
            reports.remove(mavenReportExecution);
        } else {
            RenderingContext renderingContext = new RenderingContext(siteDirectory, outputName);
            DocumentRenderer renderer = new ReportDocumentRenderer(mavenReportExecution, renderingContext, getLog());
            documents.put(outputName, renderer);
        }
    }
    return reportsByOutputName;
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) RenderingContext(org.apache.maven.doxia.siterenderer.RenderingContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) ArrayList(java.util.ArrayList) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with MavenReportExecution

use of org.apache.maven.reporting.exec.MavenReportExecution in project maven-plugins by apache.

the class SiteRunMojo method createWebApplication.

private WebAppContext createWebApplication() throws MojoExecutionException {
    File webXml = new File(tempWebappDirectory, "WEB-INF/web.xml");
    webXml.getParentFile().mkdirs();
    InputStream inStream = null;
    FileOutputStream outStream = null;
    try {
        inStream = getClass().getResourceAsStream("/run/web.xml");
        outStream = new FileOutputStream(webXml);
        IOUtil.copy(inStream, outStream);
        outStream.close();
        outStream = null;
        inStream.close();
        inStream = null;
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Unable to construct temporary webapp for running site", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to construct temporary webapp for running site", e);
    } finally {
        IOUtil.close(outStream);
        IOUtil.close(inStream);
    }
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setResourceBase(tempWebappDirectory.getAbsolutePath());
    webapp.setAttribute(DoxiaFilter.SITE_RENDERER_KEY, siteRenderer);
    webapp.getInitParams().put("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false");
    // For external reports
    project.getReporting().setOutputDirectory(tempWebappDirectory.getAbsolutePath());
    for (MavenReportExecution mavenReportExecution : getReports()) {
        mavenReportExecution.getMavenReport().setReportOutputDirectory(tempWebappDirectory);
    }
    // TODO: is it sane to call getReports() method a second time?
    List<MavenReportExecution> reports = getReports();
    List<Locale> localesList = getLocales();
    webapp.setAttribute(DoxiaFilter.LOCALES_LIST_KEY, localesList);
    // Default is first in the list
    Locale defaultLocale = localesList.get(0);
    Locale.setDefault(defaultLocale);
    try {
        Map<String, DoxiaBean> i18nDoxiaContexts = new HashMap<String, DoxiaBean>();
        for (Locale locale : localesList) {
            SiteRenderingContext i18nContext = createSiteRenderingContext(locale);
            i18nContext.setInputEncoding(getInputEncoding());
            i18nContext.setOutputEncoding(getOutputEncoding());
            SiteRenderingContext i18nGeneratedSiteContext = createSiteRenderingContext(locale);
            i18nGeneratedSiteContext.setInputEncoding(getInputEncoding());
            i18nGeneratedSiteContext.setOutputEncoding(getOutputEncoding());
            i18nGeneratedSiteContext.getSiteDirectories().clear();
            Map<String, DocumentRenderer> i18nDocuments = locateDocuments(i18nContext, reports, locale);
            DoxiaBean doxiaBean;
            if (defaultLocale.equals(locale)) {
                i18nGeneratedSiteContext.addSiteDirectory(generatedSiteDirectory);
                doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
            } else {
                i18nGeneratedSiteContext.addSiteDirectory(new File(generatedSiteDirectory, locale.getLanguage()));
                doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
            }
            i18nDoxiaContexts.put(locale.getLanguage(), doxiaBean);
            if (defaultLocale.equals(locale)) {
                i18nDoxiaContexts.put("default", doxiaBean);
            }
            if (defaultLocale.equals(locale)) {
                siteRenderer.copyResources(i18nContext, tempWebappDirectory);
            } else {
                siteRenderer.copyResources(i18nContext, new File(tempWebappDirectory, locale.getLanguage()));
            }
        }
        webapp.setAttribute(DoxiaFilter.I18N_DOXIA_CONTEXTS_KEY, i18nDoxiaContexts);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to set up webapp", e);
    }
    return webapp;
}
Also used : Locale(java.util.Locale) MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 5 with MavenReportExecution

use of org.apache.maven.reporting.exec.MavenReportExecution in project maven-plugins by apache.

the class SiteMojo method execute.

/**
     * {@inheritDoc} Generate the project site
     * <p/>
     * throws MojoExecutionException if any
     *
     * @see org.apache.maven.plugin.Mojo#execute()
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("maven.site.skip = true: Skipping site generation");
        return;
    }
    if (getLog().isDebugEnabled()) {
        getLog().debug("executing Site Mojo");
    }
    checkInputEncoding();
    List<MavenReportExecution> reports;
    if (generateReports) {
        reports = getReports();
    } else {
        reports = Collections.emptyList();
    }
    try {
        List<Locale> localesList = getLocales();
        // Default is first in the list
        Locale defaultLocale = localesList.get(0);
        Locale.setDefault(defaultLocale);
        for (Locale locale : localesList) {
            renderLocale(locale, reports);
        }
    } catch (RendererException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error during site generation", e);
    }
}
Also used : Locale(java.util.Locale) MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) RendererException(org.apache.maven.doxia.siterenderer.RendererException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException)

Aggregations

MavenReportExecution (org.apache.maven.reporting.exec.MavenReportExecution)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 MavenReport (org.apache.maven.reporting.MavenReport)4 ArrayList (java.util.ArrayList)3 DocumentRenderer (org.apache.maven.doxia.siterenderer.DocumentRenderer)3 SiteRenderingContext (org.apache.maven.doxia.siterenderer.SiteRenderingContext)3 File (java.io.File)2 IOException (java.io.IOException)2 Locale (java.util.Locale)2 MavenReportExecutor (org.apache.maven.reporting.exec.MavenReportExecutor)2 MavenReportExecutorRequest (org.apache.maven.reporting.exec.MavenReportExecutorRequest)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 DoxiaDocumentRenderer (org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer)1 RendererException (org.apache.maven.doxia.siterenderer.RendererException)1 RenderingContext (org.apache.maven.doxia.siterenderer.RenderingContext)1