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><option>value</option></pre></td>
* <td><pre>{option=value}</pre></td>
* </tr>
* <tr>
* <td><pre>
* <option>
* <param1>value1</param1>
* <param2>value2</param2>
* </option>
* </pre></td>
* <td><pre>{option={param1=value1, param2=value2}}<pre></td>
* </tr>
* <tr>
* <td><pre>
* <options>
* <option>
* <param1>value1</param1>
* <param2>value2</param2>
* </option>
* <option>
* <param1>value1</param1>
* <param2>value2</param2>
* </option>
* </options>
* </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><configuration/></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;
}
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);
}
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);
}
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();
}
}
}
}
Aggregations