Search in sources :

Example 1 with ReportSet

use of org.apache.maven.model.ReportSet in project maven-plugins by apache.

the class PdfMojo method generateMavenReports.

/**
     * Generate all Maven reports defined in <code>${project.reporting}</code> part
     * only if <code>generateReports</code> is enabled.
     *
     * @param locale not null
     * @throws MojoExecutionException if any
     * @throws IOException if any
     * @since 1.1
     */
private void generateMavenReports(Locale locale) throws MojoExecutionException, IOException {
    if (!includeReports) {
        getLog().info("Skipped report generation.");
        return;
    }
    if (project.getReporting() == null) {
        getLog().info("No report was specified.");
        return;
    }
    for (final ReportPlugin reportPlugin : project.getReporting().getPlugins()) {
        final PluginDescriptor pluginDescriptor = getPluginDescriptor(reportPlugin);
        if (pluginDescriptor != null) {
            List<String> goals = new ArrayList<String>(8);
            for (final ReportSet reportSet : reportPlugin.getReportSets()) {
                for (String goal : reportSet.getReports()) {
                    goals.add(goal);
                }
            }
            List mojoDescriptors = pluginDescriptor.getMojos();
            for (Object mojoDescriptor1 : mojoDescriptors) {
                final MojoDescriptor mojoDescriptor = (MojoDescriptor) mojoDescriptor1;
                if (goals.isEmpty() || (!goals.isEmpty() && goals.contains(mojoDescriptor.getGoal()))) {
                    MavenReport report = getMavenReport(mojoDescriptor);
                    generateMavenReport(report, mojoDescriptor.getPluginDescriptor().getPluginArtifact(), locale);
                }
            }
        }
    }
    // generate project-info report
    if (!getGeneratedMavenReports(locale).isEmpty()) {
        File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
        if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
            outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
        }
        outDir.mkdirs();
        File piReport = new File(outDir, "project-info.xml");
        StringWriter sw = new StringWriter();
        PdfSink sink = new PdfSink(sw);
        ProjectInfoRenderer r = new ProjectInfoRenderer(sink, getGeneratedMavenReports(locale), i18n, locale);
        r.render();
        writeGeneratedReport(sw.toString(), piReport);
    }
    // copy generated site
    copySiteDir(getGeneratedSiteDirectoryTmp(), getSiteDirectoryTmp());
    copySiteDir(generatedSiteDirectory, getSiteDirectoryTmp());
}
Also used : MavenReport(org.apache.maven.reporting.MavenReport) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) ArrayList(java.util.ArrayList) ReportSet(org.apache.maven.model.ReportSet) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ReportPlugin(org.apache.maven.model.ReportPlugin) StringWriter(java.io.StringWriter) List(java.util.List) ArrayList(java.util.ArrayList) MailingList(org.apache.maven.model.MailingList) File(java.io.File)

Example 2 with ReportSet

use of org.apache.maven.model.ReportSet in project maven-plugins by apache.

the class MavenJDOMWriter method iterateReportSet.

// -- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
     * Method iterateReportSet
     *
     * @param counter
     * @param childTag
     * @param parentTag
     * @param list
     * @param parent
     */
protected void iterateReportSet(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
    boolean shouldExist = list != null && list.size() > 0;
    Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        Counter innerCount = new Counter(counter.getDepth() + 1);
        while (it.hasNext()) {
            ReportSet value = (ReportSet) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updateReportSet(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : Element(org.jdom.Element) Iterator(java.util.Iterator) ReportSet(org.apache.maven.model.ReportSet)

Aggregations

ReportSet (org.apache.maven.model.ReportSet)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 MailingList (org.apache.maven.model.MailingList)1 ReportPlugin (org.apache.maven.model.ReportPlugin)1 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 MavenReport (org.apache.maven.reporting.MavenReport)1 Element (org.jdom.Element)1