Search in sources :

Example 6 with ReportPlugin

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

the class AntBuildWriterUtil method getMavenPluginConfigurationsImpl.

/**
     * Return a Map for the option <code>optionName</code> defined in a project with the given
     * <code>artifactId</code> plugin.
     * <br/>
     * Example:
     * <table>
     * <tr>
     * <td>Configuration</td>
     * <td>Result</td>
     * </tr>
     * <tr>
     * <td><pre>&lt;option&gt;value&lt;/option&gt;</pre></td>
     * <td><pre>{option=value}</pre></td>
     * </tr>
     * <tr>
     * <td><pre>
     * &lt;option&gt;
     *  &lt;param1&gt;value1&lt;/param1&gt;
     *  &lt;param2&gt;value2&lt;/param2&gt;
     * &lt;/option&gt;
     * </pre></td>
     * <td><pre>{option={param1=value1, param2=value2}}<pre></td>
     *   </tr>
     *   <tr>
     *     <td><pre>
     * &lt;options&gt;
     *   &lt;option&gt;
     *    &lt;param1&gt;value1&lt;/param1&gt;
     *    &lt;param2&gt;value2&lt;/param2&gt;
     *   &lt;/option&gt;
     *   &lt;option&gt;
     *    &lt;param1&gt;value1&lt;/param1&gt;
     *    &lt;param2&gt;value2&lt;/param2&gt;
     *   &lt;/option&gt;
     * &lt;/options&gt;
     * </pre></td>
     *     <td><pre>{options=[{option=[{param1=value1, param2=value2}]}, {option=[{param1=value1, param2=value2}]}]<pre>
     *     </td>
     *   </tr>
     * </table>
     *
     * @param project          not null
     * @param pluginArtifactId not null
     * @param optionName       an <code>Xpath</code> expression from the plugin <code>&lt;configuration/&gt;</code>
     * @param defaultValue     could be null
     * @return a map with the options found
     * @throws IOException if any
     */
private static Map getMavenPluginConfigurationsImpl(MavenProject project, String pluginArtifactId, String optionName, String defaultValue) throws IOException {
    List plugins = new ArrayList();
    for (ReportPlugin reportPlugin1 : project.getModel().getReporting().getPlugins()) {
        plugins.add(reportPlugin1);
    }
    for (Plugin plugin1 : project.getModel().getBuild().getPlugins()) {
        plugins.add(plugin1);
    }
    if (project.getBuild().getPluginManagement() != null) {
        for (Plugin plugin : project.getBuild().getPluginManagement().getPlugins()) {
            plugins.add(plugin);
        }
    }
    for (Object next : plugins) {
        Object pluginConf = null;
        if (next instanceof Plugin) {
            Plugin plugin = (Plugin) next;
            // using out-of-box Maven plugins
            if (!((plugin.getGroupId().equals("org.apache.maven.plugins")) && (plugin.getArtifactId().equals(pluginArtifactId)))) {
                continue;
            }
            pluginConf = plugin.getConfiguration();
        }
        if (next instanceof ReportPlugin) {
            ReportPlugin reportPlugin = (ReportPlugin) next;
            // using out-of-box Maven plugins
            if (!((reportPlugin.getGroupId().equals("org.apache.maven.plugins")) && (reportPlugin.getArtifactId().equals(pluginArtifactId)))) {
                continue;
            }
            pluginConf = reportPlugin.getConfiguration();
        }
        if (pluginConf == null) {
            continue;
        }
        try {
            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(pluginConf.toString().getBytes("UTF-8")));
            NodeList nodeList = XPathAPI.eval(doc, "//configuration/" + optionName).nodelist();
            if (nodeList.getLength() > 0) {
                Node optionNode = nodeList.item(0);
                if (isList(optionNode)) {
                    /*
                         * <optionNames>
                         *   <optionName>
                         *    <param1>value1</param1>
                         *    <param2>value2</param2>
                         *   </optionName>
                         * </optionNames>
                         */
                    Map options = new HashMap();
                    List optionNames = new ArrayList();
                    NodeList childs = optionNode.getChildNodes();
                    for (int i = 0; i < childs.getLength(); i++) {
                        Node child = childs.item(i);
                        if (child.getNodeType() == Node.ELEMENT_NODE) {
                            Map<String, Object> option = new HashMap<String, Object>();
                            if (isElementContent(child)) {
                                Map<String, String> properties = new HashMap<String, String>();
                                NodeList childs2 = child.getChildNodes();
                                if (childs2.getLength() > 0) {
                                    for (int j = 0; j < childs2.getLength(); j++) {
                                        Node child2 = childs2.item(j);
                                        if (child2.getNodeType() == Node.ELEMENT_NODE) {
                                            properties.put(child2.getNodeName(), getTextContent(child2));
                                        }
                                    }
                                    option.put(child.getNodeName(), properties);
                                }
                            } else {
                                option.put(child.getNodeName(), getTextContent(child));
                            }
                            optionNames.add(option);
                        }
                    }
                    options.put(optionName, optionNames.toArray(new Map[optionNames.size()]));
                    return options;
                }
                if (isElementContent(optionNode)) {
                    /*
                         * <optionName>
                         *  <param1>value1</param1>
                         *  <param2>value2</param2>
                         * </optionName>
                         */
                    Map option = new HashMap();
                    NodeList childs = optionNode.getChildNodes();
                    if (childs.getLength() > 1) {
                        Map parameters = new HashMap();
                        for (int i = 0; i < childs.getLength(); i++) {
                            Node child = childs.item(i);
                            if (child.getNodeType() == Node.ELEMENT_NODE) {
                                parameters.put(child.getNodeName(), getTextContent(child));
                            }
                        }
                        option.put(optionName, parameters);
                    }
                    return option;
                } else {
                    /*
                         * <optionName>value1</optionName>
                         */
                    Map option = new HashMap();
                    option.put(optionName, getTextContent(optionNode));
                    return option;
                }
            }
        } catch (Exception e) {
            throw new IOException("Exception occured: " + e.getMessage());
        }
    }
    Map properties = new HashMap();
    properties.put(optionName, defaultValue);
    return properties;
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) ReportPlugin(org.apache.maven.model.ReportPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ReportPlugin(org.apache.maven.model.ReportPlugin) Plugin(org.apache.maven.model.Plugin)

Example 7 with ReportPlugin

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

the class AbstractCheckstyleReport method generateMainReport.

private void generateMainReport(CheckstyleResults results, ResourceBundle bundle) {
    CheckstyleReportGenerator generator = new CheckstyleReportGenerator(getSink(), bundle, project.getBasedir(), siteTool, configLocation);
    generator.setLog(getLog());
    generator.setEnableRulesSummary(enableRulesSummary);
    generator.setEnableSeveritySummary(enableSeveritySummary);
    generator.setEnableFilesSummary(enableFilesSummary);
    generator.setEnableRSS(enableRSS);
    generator.setCheckstyleConfig(results.getConfiguration());
    if (linkXRef) {
        String relativePath = PathTool.getRelativePath(getOutputDirectory(), xrefLocation.getAbsolutePath());
        if (StringUtils.isEmpty(relativePath)) {
            relativePath = ".";
        }
        relativePath = relativePath + "/" + xrefLocation.getName();
        if (xrefLocation.exists()) {
            // XRef was already generated by manual execution of a lifecycle
            // binding
            generator.setXrefLocation(relativePath);
        } else {
            // Not yet generated - check if the report is on its way
            for (ReportPlugin report : (Iterable<ReportPlugin>) getProject().getReportPlugins()) {
                String artifactId = report.getArtifactId();
                if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
                    generator.setXrefLocation(relativePath);
                }
            }
        }
        if (generator.getXrefLocation() == null && results.getFileCount() > 0) {
            getLog().warn("Unable to locate Source XRef to link to - DISABLED");
        }
    }
    if (treeWalkerNames != null) {
        generator.setTreeWalkerNames(treeWalkerNames);
    }
    generator.generateReport(results);
}
Also used : ReportPlugin(org.apache.maven.model.ReportPlugin)

Example 8 with ReportPlugin

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

the class ModuleMavenProjectStub method getReportPlugins.

/** {@inheritDoc} */
public List<ReportPlugin> getReportPlugins() {
    ReportPlugin jxrPlugin = new ReportPlugin();
    jxrPlugin.setArtifactId("maven-jxr-plugin");
    return Collections.singletonList(jxrPlugin);
}
Also used : ReportPlugin(org.apache.maven.model.ReportPlugin)

Example 9 with ReportPlugin

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

the class MavenJDOMWriter method iterateReportPlugin.

// -- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
     * Method iterateReportPlugin
     *
     * @param counter
     * @param childTag
     * @param parentTag
     * @param list
     * @param parent
     */
protected void iterateReportPlugin(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()) {
            ReportPlugin value = (ReportPlugin) 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);
            }
            updateReportPlugin(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : ReportPlugin(org.apache.maven.model.ReportPlugin) Element(org.jdom.Element) Iterator(java.util.Iterator)

Aggregations

ReportPlugin (org.apache.maven.model.ReportPlugin)9 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 MailingList (org.apache.maven.model.MailingList)1 Plugin (org.apache.maven.model.Plugin)1 ReportSet (org.apache.maven.model.ReportSet)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 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1