forked from phoedos/pmd
maven-plugin-pmd-build: generate markdown files for the rules
* simplify the configuration of the plugin * use better default values
This commit is contained in:
@ -98,6 +98,12 @@ only if you modify the java code.
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.ant</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
@ -140,13 +146,6 @@ only if you modify the java code.
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-testing</groupId>
|
||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||
|
@ -10,7 +10,10 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -23,7 +26,9 @@ import net.sourceforge.pmd.build.util.FileUtil;
|
||||
import net.sourceforge.pmd.build.util.XmlUtil;
|
||||
import net.sourceforge.pmd.build.xml.RulesetFileTemplater;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
@ -153,7 +158,7 @@ public class RuleSetToDocs implements PmdBuildTools {
|
||||
|
||||
private File buildTransformedRulesetDirectory(File ruleset) {
|
||||
return new File(this.targetDirectory + File.separator + ruleset.getParentFile().getName() + File.separator
|
||||
+ ruleset.getName());
|
||||
+ FilenameUtils.getBaseName(ruleset.getName()) + ".md");
|
||||
}
|
||||
|
||||
private void processXDocFile(File ruleset) throws PmdBuildException {
|
||||
@ -173,6 +178,17 @@ public class RuleSetToDocs implements PmdBuildTools {
|
||||
for (int i = 0; i < rules.getLength(); i++) {
|
||||
Node rule = rules.item(i);
|
||||
ruleAnalyzer.analyze(document, rule);
|
||||
|
||||
escapeTextContent(findChildren(rule, "example"));
|
||||
List<Node> properties = findChildren(rule, "properties");
|
||||
for (Node prop : properties) {
|
||||
List<Node> property = findChildren(prop, "property");
|
||||
for (Node n : property) {
|
||||
if (((Element)n).getAttribute("name").equals("xpath")) {
|
||||
escapeTextContent(findChildren(n, "value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlFileTemplater.transform(dom, target, xmlFileTemplater.getRulesetToDocsXsl());
|
||||
@ -181,6 +197,32 @@ public class RuleSetToDocs implements PmdBuildTools {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Node> findChildren(Node parent, String childName) {
|
||||
List<Node> result = new ArrayList<Node>();
|
||||
NodeList children = parent.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node child = children.item(i);
|
||||
if (isElement(child, childName)) {
|
||||
result.add(child);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private static boolean isElement(Node node, String name) {
|
||||
return node.getNodeType() == Node.ELEMENT_NODE && name.equals(node.getNodeName());
|
||||
}
|
||||
private static void escapeTextContent(Collection<Node> nodes) {
|
||||
for (Node node : nodes) {
|
||||
escapeTextContent(node);
|
||||
}
|
||||
}
|
||||
private static void escapeTextContent(Node node) {
|
||||
String content = node.getTextContent();
|
||||
content = content.replaceAll("&", "&");
|
||||
content = content.replaceAll("<", "<");
|
||||
node.setTextContent(content);
|
||||
}
|
||||
|
||||
private void addRulesetsToSiteXml(DOMSource backbone) {
|
||||
File menu = FileUtil.createTempFile("menu.xml");
|
||||
if (LOGGER.isLoggable(Level.FINE)) {
|
||||
|
@ -64,7 +64,7 @@ public class RuntimeRulePropertiesAnalyzer {
|
||||
}
|
||||
String classAtt = classAttribute.getTextContent();
|
||||
if (XPATH_RULE_CLASSNAME.equals(classAtt)) {
|
||||
// xpath rules are ignored - they have there properties defined
|
||||
// xpath rules are ignored - they have their properties defined
|
||||
// already in the rule definition xml
|
||||
return;
|
||||
}
|
||||
|
@ -16,38 +16,39 @@ import net.sourceforge.pmd.build.RuleSetToDocs;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Generates xdoc sites for each ruleset.
|
||||
* Generates markdown sites for each ruleset.
|
||||
*/
|
||||
@Mojo( name = "pmd-pre-site", requiresDependencyResolution = ResolutionScope.RUNTIME )
|
||||
@Mojo( name = "pmd-pre-site", requiresDependencyResolution = ResolutionScope.RUNTIME, defaultPhase = LifecyclePhase.PRE_SITE )
|
||||
public class PmdPreSite extends AbstractMojo {
|
||||
/**
|
||||
* Path to the existing site descriptor
|
||||
*/
|
||||
@Parameter(property = "pmd.siteXml", defaultValue = "src/site/site.pre.xml")
|
||||
@Parameter(property = "pmd.siteXml", defaultValue = "${basedir}/src/site/site.pre.xml")
|
||||
private String siteXml;
|
||||
|
||||
/**
|
||||
* Path to the existing site descriptor
|
||||
*/
|
||||
@Parameter(property = "pmd.siteXml.target", defaultValue = "src/site/site.xml")
|
||||
@Parameter(property = "pmd.siteXml.target", defaultValue = "${basedir}/src/site/site.xml")
|
||||
private String siteXmlTarget;
|
||||
|
||||
/**
|
||||
* Path to the existing site descriptor
|
||||
*/
|
||||
@Parameter(property = "pmd.siteTarget", defaultValue = "${project.build.directory}/generated-xdocs/rules")
|
||||
@Parameter(property = "pmd.siteTarget", defaultValue = "${basedir}/src/site/markdown/rules")
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* Path to the existing site descriptor
|
||||
*/
|
||||
@Parameter(property = "pmd.rulesets", defaultValue = "src/main/resources/rulesets/")
|
||||
@Parameter(property = "pmd.rulesets", defaultValue = "${basedir}/src/main/resources/rulesets")
|
||||
private String rulesetsDirectory;
|
||||
|
||||
@Parameter(defaultValue = "${project}", readonly = true, required = true)
|
||||
|
@ -3,5 +3,5 @@ pmd.build.config.xsl.mergeRuleset=xslt/merge-rulesets.xsl
|
||||
pmd.build.config.xsl.rulesIndex=xslt/rules-index.xsl
|
||||
pmd.build.config.xsl.createRulesetMenu=xslt/create-rules-menu.xsl
|
||||
pmd.build.config.xsladdToSiteDescriptor=xslt/add-menu-to-site-descriptor.xsl
|
||||
pmd.build.config.index.filename=index.xml
|
||||
pmd.build.config.index.filename=index.md
|
||||
pmd.build.config.mergedRuleset.filename=mergedruleset.xml
|
||||
|
@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- BSD-style license; for more info see http://pmd.sourceforge.net/license.html -->
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
|
||||
<xsl:output method="text" encoding="UTF-8" omit-xml-declaration="true" />
|
||||
|
||||
<!--
|
||||
<author email="tom@infoether.com">Tom Copeland</author>
|
||||
-->
|
||||
|
||||
<!-- FUTURE: Externalising text to allow i18n generation -->
|
||||
<xsl:variable name="Since" select="'Since: PMD '" />
|
||||
@ -12,57 +16,39 @@
|
||||
<xsl:variable name="Property.Name" select="'Name'" />
|
||||
<xsl:variable name="Property.DefaultValue" select="'Default Value'" />
|
||||
<xsl:variable name="Property.Desc" select="'Description'" />
|
||||
<xsl:variable name="RuleSet" select="'Ruleset'" />
|
||||
|
||||
<xsl:variable name='newline'><xsl:text>
</xsl:text></xsl:variable>
|
||||
|
||||
<xsl:template match="ruleset">
|
||||
<document>
|
||||
<xsl:variable name="rulesetname" select="@name" />
|
||||
<properties>
|
||||
<author email="tom@infoether.com">Tom Copeland</author>
|
||||
<title>
|
||||
<xsl:value-of select="$RuleSet" />: <xsl:value-of select="$rulesetname" />
|
||||
</title>
|
||||
</properties>
|
||||
<body>
|
||||
<section>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="$rulesetname" />
|
||||
</xsl:attribute>
|
||||
<xsl:apply-templates />
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
|
||||
# <xsl:value-of select="$rulesetname" />
|
||||
|
||||
<xsl:apply-templates />
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rule[@name][not(@ref)]">
|
||||
<xsl:variable name="rulename" select="@name" />
|
||||
<xsl:variable name="classname" select="@class" />
|
||||
|
||||
<subsection>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="$rulename" />
|
||||
</xsl:attribute>
|
||||
<p>
|
||||
<xsl:value-of select="$Since" />
|
||||
<xsl:value-of select="@since" />
|
||||
</p>
|
||||
<p>
|
||||
<xsl:value-of select="$Priority" />: <xsl:value-of select="priority" />
|
||||
</p>
|
||||
<p>
|
||||
## <xsl:value-of select="concat($rulename, $newline, $newline)" />
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="@deprecated='true'">
|
||||
<xsl:attribute name="style">border-radius: 3px; border-style: solid; border-width: 1px 1px 1px 5px; margin: 20px 0px; padding: 20px; border-color: #eee; border-left-color: #ce4844</xsl:attribute>
|
||||
<strong>Deprecated</strong><br/>
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f;">Deprecated</span>
|
||||
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:value-of select="description" />
|
||||
</p>
|
||||
|
||||
<xsl:value-of select="$newline"/><xsl:value-of select="$Since" /> <xsl:value-of select="concat(@since, $newline, $newline)" />
|
||||
<xsl:value-of select="$newline"/><xsl:value-of select="$Priority" />: <xsl:value-of select="concat(priority, $newline, $newline)" />
|
||||
<xsl:value-of select="$newline"/><xsl:value-of select="description" />
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="count(properties/property[@name='xpath']) != 0">
|
||||
<source>
|
||||
<xsl:value-of select="properties/property/value" />
|
||||
</source>
|
||||
<xsl:value-of select="$newline"/>
|
||||
<xsl:value-of select="$newline"/>
|
||||
<pre><xsl:value-of select="properties/property/value" /></pre>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:variable name="classfile">
|
||||
@ -70,76 +56,61 @@
|
||||
<xsl:with-param name="classname" select="$classname" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<p>
|
||||
<xsl:value-of select="$definedByJavaClass" />
|
||||
:
|
||||
<a>
|
||||
<xsl:attribute name="href"><xsl:value-of
|
||||
select="concat(concat('../../xref/',$classfile),'.html')" /></xsl:attribute>
|
||||
<xsl:value-of select="@class" />
|
||||
</a>
|
||||
</p>
|
||||
<xsl:value-of select="$newline"/>
|
||||
<xsl:value-of select="$definedByJavaClass" />: [<xsl:value-of select="@class" />](<xsl:value-of select="concat(concat('../../xref/',$classfile),'.html')" />)
|
||||
<xsl:value-of select="$newline"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
<xsl:for-each select="./example">
|
||||
<xsl:value-of select="$newline"/>
|
||||
<xsl:value-of select="$newline"/>
|
||||
<xsl:value-of select="$ExampleLabel" />:
|
||||
|
||||
<xsl:value-of select="$ExampleLabel" />:
|
||||
<source>
|
||||
<xsl:value-of select="." />
|
||||
</source>
|
||||
<pre><xsl:value-of select="." /></pre>
|
||||
</xsl:for-each>
|
||||
|
||||
<xsl:variable name="hasproperties" select="count(properties/property[@name!='xpath'])" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="$hasproperties != 0">
|
||||
<p>
|
||||
<xsl:value-of select="$PropertiesLabel" />:
|
||||
</p>
|
||||
<table>
|
||||
<th>
|
||||
<xsl:value-of select="$Property.Name" />
|
||||
</th>
|
||||
<th>
|
||||
<xsl:value-of select="$Property.DefaultValue" />
|
||||
</th>
|
||||
<th>
|
||||
<xsl:value-of select="$Property.Desc" />
|
||||
</th>
|
||||
<xsl:for-each select="properties/property[@name != 'xpath']">
|
||||
<tr>
|
||||
<td>
|
||||
<xsl:value-of select="@name" />
|
||||
</td>
|
||||
<td>
|
||||
<xsl:value-of select="@value" />
|
||||
</td>
|
||||
<td>
|
||||
<xsl:value-of select="@description" />
|
||||
</td>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
<xsl:value-of select="$newline"/>
|
||||
<xsl:value-of select="$PropertiesLabel" />:<xsl:value-of select="concat($newline, $newline)"/>
|
||||
|
||||
<table>
|
||||
<th>
|
||||
<xsl:value-of select="$Property.Name" />
|
||||
</th>
|
||||
<th>
|
||||
<xsl:value-of select="$Property.DefaultValue" />
|
||||
</th>
|
||||
<th>
|
||||
<xsl:value-of select="$Property.Desc" />
|
||||
</th>
|
||||
<xsl:for-each select="properties/property[@name != 'xpath']">
|
||||
<tr>
|
||||
<td>
|
||||
<xsl:value-of select="@name" />
|
||||
</td>
|
||||
<td>
|
||||
<xsl:value-of select="@value" />
|
||||
</td>
|
||||
<td>
|
||||
<xsl:value-of select="@description" />
|
||||
</td>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
|
||||
</subsection>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rule[@name][@deprecated='true'][@ref][not(contains(@ref, '.xml'))]">
|
||||
<subsection>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name" />
|
||||
</xsl:attribute>
|
||||
<p style="border-radius: 3px; border-style: solid; border-width: 1px 1px 1px 5px; margin: 20px 0px; padding: 20px; border-color: #eee; border-left-color: #ce4844">
|
||||
<strong>Deprecated</strong><br />
|
||||
This rule has been renamed. Use instead:
|
||||
<a>
|
||||
<xsl:attribute name="href">#<xsl:value-of select="@ref" /></xsl:attribute>
|
||||
<xsl:value-of select="@ref"/>
|
||||
</a>
|
||||
</p>
|
||||
</subsection>
|
||||
## <xsl:value-of select="concat(@name, $newline, $newline)" />
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f;">Deprecated</span>
|
||||
|
||||
This rule has been renamed. Use instead: [<xsl:value-of select="@ref"/>](#<xsl:value-of select="@ref" />)
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rule[@deprecated='true'][@ref][contains(@ref, '.xml')][not(@name)]">
|
||||
@ -156,19 +127,12 @@
|
||||
</xsl:variable>
|
||||
<xsl:variable name="ruleset" select="substring($ruleset-with-extension, 1, string-length($ruleset-with-extension) - 4)"/>
|
||||
|
||||
<subsection>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="$rulename" />
|
||||
</xsl:attribute>
|
||||
<p style="border-radius: 3px; border-style: solid; border-width: 1px 1px 1px 5px; margin: 20px 0px; padding: 20px; border-color: #eee; border-left-color: #ce4844">
|
||||
<strong>Deprecated</strong><br />
|
||||
This rule has been moved to another ruleset. Use instead:
|
||||
<a>
|
||||
<xsl:attribute name="href"><xsl:value-of select="concat($ruleset, '.html#', $rulename)" /></xsl:attribute>
|
||||
<xsl:value-of select="$rulename"/>
|
||||
</a>
|
||||
</p>
|
||||
</subsection>
|
||||
## <xsl:value-of select="concat($rulename, $newline, $newline)" />
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f;">Deprecated</span>
|
||||
|
||||
This rule has been moved to another ruleset. Use instead: [<xsl:value-of select="$rulename"/>](<xsl:value-of select="concat($ruleset, '.html#', $rulename)" />)
|
||||
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="last-token-after-last-slash">
|
||||
@ -202,5 +166,4 @@
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
@ -1,98 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- BSD-style license; for more info see http://pmd.sourceforge.net/license.html -->
|
||||
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
|
||||
<xsl:output method="text" encoding="UTF-8" omit-xml-declaration="true" />
|
||||
|
||||
<!-- <author email="mikkey@sourceforge.net">Miguel Griffa</author> -->
|
||||
|
||||
<!-- FUTURE: Externalising text to allow i18n documnetation -->
|
||||
<xsl:variable name="Title" select="'PMD Rulesets index'" />
|
||||
<xsl:variable name="PageDesc" select="'List of rulesets and rules contained in each ruleset.'" />
|
||||
|
||||
<xsl:variable name='newline'><xsl:text>
</xsl:text></xsl:variable>
|
||||
|
||||
<xsl:template match="rulesets">
|
||||
<document>
|
||||
<properties>
|
||||
<author email="mikkey@sourceforge.net">Miguel Griffa</author>
|
||||
<title>
|
||||
<xsl:value-of select="$Title" />
|
||||
</title>
|
||||
</properties>
|
||||
<body>
|
||||
<section name="Current Rulesets">
|
||||
<p>
|
||||
<xsl:value-of select="$PageDesc" />
|
||||
</p>
|
||||
<ul>
|
||||
<xsl:for-each select="./language/ruleset">
|
||||
<xsl:sort select="@name" />
|
||||
<li>
|
||||
<a>
|
||||
<xsl:attribute name="href">#<xsl:value-of
|
||||
select="translate(normalize-space(@name),' ','_')" /></xsl:attribute>
|
||||
<xsl:value-of select="@name" />
|
||||
</a>: <xsl:value-of select="description" />
|
||||
</li>
|
||||
</xsl:for-each>
|
||||
</ul>
|
||||
# <xsl:value-of select="$Title" />: Current Rulesets
|
||||
|
||||
<xsl:variable name="urlPrefixLength">
|
||||
<xsl:value-of select="string-length('${pmd.website.baseurl}/rules/')" />
|
||||
<xsl:value-of select="$PageDesc" />
|
||||
<xsl:value-of select="$newline" />
|
||||
|
||||
<xsl:for-each select="./language/ruleset">
|
||||
<xsl:sort select="@name" />
|
||||
* [<xsl:value-of select="@name" />](#<xsl:value-of select="translate(normalize-space(@name),' ','_')" />): <xsl:value-of select="description" />
|
||||
<xsl:value-of select="$newline"/>
|
||||
<xsl:value-of select="$newline"/>
|
||||
</xsl:for-each>
|
||||
|
||||
|
||||
|
||||
<xsl:variable name="urlPrefixLength">
|
||||
<xsl:value-of select="string-length('${pmd.website.baseurl}/rules/')" />
|
||||
</xsl:variable>
|
||||
|
||||
|
||||
<xsl:for-each select="language">
|
||||
<xsl:variable name="language" select="@name" />
|
||||
<xsl:for-each select="ruleset">
|
||||
<xsl:variable name="rulesetname" select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ', 'abcdefghijklmnopqrstuvwxyz_')" />
|
||||
|
||||
<a name="<xsl:value-of select="translate(normalize-space(@name),' ','_')" />" />
|
||||
## <xsl:value-of select="@name" /> (<xsl:value-of select="$language" />)
|
||||
|
||||
<xsl:for-each select="./rule">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@name and not(@ref)">
|
||||
* [<xsl:value-of select="@name" />](<xsl:value-of select="substring(@externalInfoUrl,$urlPrefixLength + 1)" />): <xsl:choose>
|
||||
<xsl:when test="@deprecated='true'">
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span>
|
||||
</xsl:when>
|
||||
</xsl:choose><xsl:value-of select="description" /><xsl:value-of select="$newline"/><xsl:value-of select="$newline"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="@name and @deprecated='true' and @ref and not(contains(@ref, '.xml'))">
|
||||
* [<xsl:value-of select="@name" />](<xsl:value-of select="concat($language, '/', $rulesetname, '.html#', @name)" />):
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span>
|
||||
<xsl:value-of select="$newline"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="not(@name) and @deprecated='true' and contains(@ref, '.xml')">
|
||||
<xsl:variable name="rulename">
|
||||
<xsl:call-template name="last-token-after-last-slash">
|
||||
<xsl:with-param name="ref" select="@ref"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:for-each select="language">
|
||||
<xsl:variable name="language" select="@name" />
|
||||
<xsl:for-each select="ruleset">
|
||||
<xsl:variable name="rulesetname" select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ', 'abcdefghijklmnopqrstuvwxyz_')" />
|
||||
<xsl:element name="a">
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="translate(normalize-space(@name),' ','_')" />
|
||||
</xsl:attribute>
|
||||
</xsl:element>
|
||||
<subsection>
|
||||
<xsl:attribute name="name"><xsl:value-of select="@name" /> (<xsl:value-of
|
||||
select="$language" />)</xsl:attribute>
|
||||
<ul>
|
||||
<xsl:for-each select="./rule">
|
||||
<li>
|
||||
<xsl:choose>
|
||||
<xsl:when test="@name and not(@ref)">
|
||||
<a>
|
||||
<xsl:attribute name="href"><xsl:value-of
|
||||
select="substring(@externalInfoUrl,$urlPrefixLength + 1)" /></xsl:attribute>
|
||||
<xsl:value-of select="@name" />
|
||||
</a>:
|
||||
<xsl:choose>
|
||||
<xsl:when test="@deprecated='true'">
|
||||
Deprecated rule.
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:value-of select="description" />
|
||||
</xsl:when>
|
||||
<xsl:when test="@name and @deprecated='true' and @ref and not(contains(@ref, '.xml'))">
|
||||
<a>
|
||||
<xsl:attribute name="href"><xsl:value-of select="concat($language, '/', $rulesetname, '.html#', @name)" /></xsl:attribute>
|
||||
<xsl:value-of select="@name" />
|
||||
</a>: Deprecated rule.
|
||||
</xsl:when>
|
||||
<xsl:when test="not(@name) and @deprecated='true' and contains(@ref, '.xml')">
|
||||
<xsl:variable name="rulename">
|
||||
<xsl:call-template name="last-token-after-last-slash">
|
||||
<xsl:with-param name="ref" select="@ref"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<a>
|
||||
<xsl:attribute name="href"><xsl:value-of select="concat($language, '/', $rulesetname, '.html#', $rulename)" /></xsl:attribute>
|
||||
<xsl:value-of select="$rulename"/>
|
||||
</a>: Deprecated rule.
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</li>
|
||||
</xsl:for-each>
|
||||
</ul>
|
||||
</subsection>
|
||||
</xsl:for-each>
|
||||
</xsl:for-each>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
||||
* [<xsl:value-of select="$rulename"/>](<xsl:value-of select="concat($language, '/', $rulesetname, '.html#', $rulename)" />):
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span>
|
||||
<xsl:value-of select="$newline"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:for-each>
|
||||
</xsl:for-each>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="last-token-after-last-slash">
|
||||
|
@ -33,17 +33,21 @@ public class RuleSetToDocsTest extends TestBase {
|
||||
|
||||
builder.convertRulesets();
|
||||
|
||||
String codeSizeRuleset = IOUtils.toString(new File(TEST_DIR + "target/java/codesize.xml").toURI());
|
||||
assertTrue(codeSizeRuleset.contains("<section name=\"Code Size\">"));
|
||||
String codeSizeRuleset = IOUtils.toString(new File(TEST_DIR + "target/java/codesize.md").toURI());
|
||||
|
||||
assertTrue(codeSizeRuleset.contains("# Code Size"));
|
||||
assertTrue(codeSizeRuleset.contains("minimum"));
|
||||
assertTrue(codeSizeRuleset.contains("Priority: 3"));
|
||||
|
||||
assertTrue(codeSizeRuleset.contains("OldNameOfNPathComplexity"));
|
||||
assertTrue(codeSizeRuleset.contains("<a href=\"#NPathComplexity\">NPathComplexity</a>"));
|
||||
assertTrue(codeSizeRuleset.contains("[NPathComplexity](#NPathComplexity)"));
|
||||
assertTrue(codeSizeRuleset.contains("JumbledIncrementer"));
|
||||
assertTrue(codeSizeRuleset.contains("<a href=\"basic.html#JumbledIncrementer\">JumbledIncrementer</a>"));
|
||||
assertTrue(codeSizeRuleset.contains("[JumbledIncrementer](basic.html#JumbledIncrementer)"));
|
||||
|
||||
assertTrue(codeSizeRuleset.contains("SoonToBeRemoved"));
|
||||
|
||||
String basicRuleset = IOUtils.toString(new File(TEST_DIR + "target/java/basic.md").toURI());
|
||||
assertTrue(basicRuleset.contains("t i = 0; i < 10; i++)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -34,14 +34,14 @@ public class PmdPreSiteTest extends AbstractMojoTestCase {
|
||||
myMojo.execute();
|
||||
|
||||
String codeSizeRuleset = IOUtils.toString(new File(
|
||||
"target/unit/sample-pmd/target/generated-xdocs/rules/java/codesize.xml").toURI());
|
||||
"target/unit/sample-pmd/target/generated-xdocs/rules/java/codesize.md").toURI());
|
||||
assertTrue(codeSizeRuleset.contains("minimum"));
|
||||
|
||||
String basicRuleset = IOUtils.toString(new File(
|
||||
"target/unit/sample-pmd/target/generated-xdocs/rules/java/basic.xml").toURI());
|
||||
assertEquals(2, StringUtils.countMatches(basicRuleset, "<subsection"));
|
||||
"target/unit/sample-pmd/target/generated-xdocs/rules/java/basic.md").toURI());
|
||||
assertEquals(2, StringUtils.countMatches(basicRuleset, "## "));
|
||||
|
||||
String indexPage = IOUtils.toString(new File("target/unit/sample-pmd/target/generated-xdocs/rules/index.xml")
|
||||
String indexPage = IOUtils.toString(new File("target/unit/sample-pmd/target/generated-xdocs/rules/index.md")
|
||||
.toURI());
|
||||
assertFalse(indexPage.contains("<li>: </li>"));
|
||||
|
||||
|
@ -16,6 +16,7 @@ The Code Size ruleset contains rules that find problems related to code size or
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/java/codesize.html#NPathComplexity">
|
||||
<description>
|
||||
The NPath complexity of a method is the number of acyclic execution paths through that method.
|
||||
|
||||
A threshold of 200 is generally considered the point where measures should be taken to reduce
|
||||
complexity and increase readability.
|
||||
</description>
|
||||
@ -60,7 +61,12 @@ void bar() { // this is something more complex than it needs to be,
|
||||
<rule deprecated="true" ref="rulesets/java/basic.xml/JumbledIncrementer" />
|
||||
|
||||
<rule deprecated="true" name="SoonToBeRemoved" language="java" since="1.0" message="Foo">
|
||||
<description>This rule will be removed with the next version.</description>
|
||||
<description>
|
||||
<![CDATA[
|
||||
This rule will be removed with the next version.
|
||||
|
||||
You can use **markdown** here!
|
||||
]]></description>
|
||||
<priority>3</priority>
|
||||
</rule>
|
||||
</ruleset>
|
Reference in New Issue
Block a user