Merge remote-tracking branch 'pmd-branch/master' into merge-pmd-branch
This commit is contained in:
commit
61decdc6cb
306 files changed
+6512
-8381
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# PMD
|
||||
|
||||
PMD is a source code analyzer. It finds unused variables,
|
||||
empty catch blocks, unnecessary object creation, and so forth.
|
||||
|
||||
For more information, visit http://pmd.sourceforge.net
|
||||
|
||||
To see the current status of this repo, visit https://buildhive.cloudbees.com/job/pmd/
|
||||
@@ -11,7 +11,7 @@
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-build</artifactId>
|
||||
<name>PMD Build Plugin</name>
|
||||
<version>0.7-SNAPSHOT</version>
|
||||
<version>0.8-SNAPSHOT</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<description>
|
||||
<![CDATA[
|
||||
@@ -38,9 +38,10 @@ only if you modify the java code.
|
||||
</licenses>
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:https://pmd.svn.sourceforge.net/svnroot/pmd/trunk/maven-plugin-pmd-build</connection>
|
||||
<developerConnection>scm:svn:https://pmd.svn.sourceforge.net/svnroot/pmd/trunk/maven-plugin-pmd-build</developerConnection>
|
||||
<url>http://pmd.svn.sourceforge.net/viewvc/pmd/trunk/maven-plugin-pmd-build</url>
|
||||
<connection>scm:git:git://github.com/pmd/pmd.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/pmd/pmd.git</developerConnection>
|
||||
<url>https://github.com/pmd/pmd</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<developers>
|
||||
@@ -73,13 +74,22 @@ only if you modify the java code.
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<tagBase>https://pmd.svn.sourceforge.net/svnroot/pmd/tags/maven-plugin-pmd-build</tagBase>
|
||||
<tagNameFormat>@{project.artifactId}/@{project.version}</tagNameFormat>
|
||||
<pushChanges>false</pushChanges>
|
||||
<localCheckout>true</localCheckout>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<mavenVersion>3.0.3</mavenVersion>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.ant</groupId>
|
||||
@@ -87,24 +97,48 @@ only if you modify the java code.
|
||||
<version>1.8.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-compat</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</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>
|
||||
<version>2.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
|
||||
@@ -3,7 +3,6 @@ Release Howto for pmd-build:
|
||||
|
||||
Prerequisites:
|
||||
--------------
|
||||
* You need to use SVN currently (git / git-svn is not supported at the moment)
|
||||
* You need to have a Jira account at Sonatype: https://issues.sonatype.org/
|
||||
* You need to have upload permissions to the staging repository for PMD at sonatype: https://issues.sonatype.org/browse/OSSRH-2295
|
||||
* For more infos: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
|
||||
@@ -12,15 +11,16 @@ Prerequisites:
|
||||
* You need to have your settings.xml filled:
|
||||
-> configure the property gpg.keyname and any other property for the maven-gpg-plugin (e.g. via a profile)
|
||||
-> configure the server section (you need to configure your sonatype jira account for server id "sonatype-nexus-staging").
|
||||
* You'll need at least maven 3.0.4, see http://jira.codehaus.org/browse/MRELEASE-756
|
||||
|
||||
Step by step:
|
||||
-------------
|
||||
1. Checkout trunk via svn:
|
||||
1. Checkout master branch:
|
||||
|
||||
svn co https://pmd.svn.sourceforge.net/svnroot/pmd/trunk/maven-plugin-pmd-build
|
||||
cd maven-plugin-pmd-build
|
||||
git clone https://github.com/pmd/pmd.git
|
||||
cd pmd/maven-plugin-pmd-build
|
||||
|
||||
2. Prepare the release (creates a new release tag in SVN).
|
||||
2. Prepare the release (creates a new release tag).
|
||||
This will be done for you: http://maven.apache.org/plugins/maven-release-plugin/examples/prepare-release.html
|
||||
Maven will ask you about the release version, the tag name and the new version. You can simply hit enter,
|
||||
to use the default values.
|
||||
@@ -32,7 +32,6 @@ mvn release:prepare
|
||||
|
||||
mvn release:perform
|
||||
|
||||
|
||||
4. Release it via Sonatype Nexus
|
||||
* Login to https://oss.sonatype.org/
|
||||
* Go to Staging Repositories page
|
||||
@@ -41,5 +40,8 @@ mvn release:perform
|
||||
* Now you can download the artifacts again and verify they are working.
|
||||
* Once you are sure they are working, click "Release" and the artifacts are eventually available through maven central.
|
||||
|
||||
5. Push your local changes if everything is fine
|
||||
|
||||
git push origin master
|
||||
git push origin tag pmd-build/<version>
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.ant;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import net.sourceforge.pmd.build.PmdBuildException;
|
||||
import net.sourceforge.pmd.build.PmdBuildTools;
|
||||
import net.sourceforge.pmd.build.RuleSetToDocs;
|
||||
@@ -20,7 +22,14 @@ public class PmdBuildTask extends Task {
|
||||
private String target;
|
||||
private String siteXml;
|
||||
private String siteXmlTarget;
|
||||
private URL[] runtimeClasspath;
|
||||
|
||||
public URL[] getRuntimeClasspath() {
|
||||
return runtimeClasspath;
|
||||
}
|
||||
public void setRuntimeClasspath(URL[] runtimeClasspath) {
|
||||
this.runtimeClasspath = runtimeClasspath;
|
||||
}
|
||||
public String getSiteXml() {
|
||||
return siteXml;
|
||||
}
|
||||
@@ -72,6 +81,7 @@ public class PmdBuildTask extends Task {
|
||||
tool.setSiteXml(siteXml);
|
||||
tool.setSiteXmlTarget(this.siteXmlTarget);
|
||||
tool.setRulesDirectory(this.rulesDirectory);
|
||||
tool.setRuntimeClasspath(runtimeClasspath);
|
||||
|
||||
try {
|
||||
tool.convertRulesets();
|
||||
@@ -90,6 +100,9 @@ public class PmdBuildTask extends Task {
|
||||
throw new BuildException("Attribute rulesDirectory is not optional");
|
||||
if ( this.siteXml == null ||"".equals(siteXml))
|
||||
throw new BuildException("Attribute siteXml is not optional");
|
||||
if ( this.runtimeClasspath == null || "".equals(runtimeClasspath)) {
|
||||
throw new BuildException("Attribute pmdClasspath is not optional");
|
||||
}
|
||||
// Optional Attributes
|
||||
if ( this.mergedRulesetFilename != null && ! "".equals(this.mergedRulesetFilename) )
|
||||
tool.setMergedRuleSetFilename(this.mergedRulesetFilename);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sourceforge.pmd.build;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
public interface PmdBuildTools {
|
||||
|
||||
@@ -42,4 +44,12 @@ public interface PmdBuildTools {
|
||||
* @param siteXmlTaget
|
||||
*/
|
||||
public abstract void setSiteXmlTarget(String siteXmlTarget);
|
||||
|
||||
/**
|
||||
* Configures the classpath to use to analyze the properties of rules.
|
||||
* @param runtimeClasspath
|
||||
* @see RuntimeRulePropertiesAnalyzer
|
||||
*/
|
||||
public void setRuntimeClasspath(URL[] runtimeClasspath);
|
||||
|
||||
}
|
||||
@@ -7,6 +7,9 @@ import static net.sourceforge.pmd.build.util.ConfigUtil.getString;
|
||||
import static net.sourceforge.pmd.build.util.XmlUtil.createXmlBackbone;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
@@ -19,6 +22,10 @@ import net.sourceforge.pmd.build.util.FileUtil;
|
||||
import net.sourceforge.pmd.build.util.XmlUtil;
|
||||
import net.sourceforge.pmd.build.xml.RulesetFileTemplater;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* A small class to convert files from pmd rulesets fmt to xdoc fmt
|
||||
*
|
||||
@@ -36,6 +43,16 @@ public class RuleSetToDocs implements PmdBuildTools {
|
||||
private String targetDirectory;
|
||||
private String siteXml;
|
||||
private String siteXmlTarget;
|
||||
private URL[] runtimeClasspath;
|
||||
private RuntimeRulePropertiesAnalyzer ruleAnalyzer;
|
||||
|
||||
public URL[] getRuntimeClasspath() {
|
||||
return runtimeClasspath;
|
||||
}
|
||||
|
||||
public void setRuntimeClasspath(URL[] runtimeClasspath) {
|
||||
this.runtimeClasspath = runtimeClasspath;
|
||||
}
|
||||
|
||||
public String getSiteXmlTarget() {
|
||||
return siteXmlTarget;
|
||||
@@ -104,6 +121,7 @@ public class RuleSetToDocs implements PmdBuildTools {
|
||||
private void init() throws PmdBuildException {
|
||||
FileUtil.createDirIfMissing(targetDirectory);
|
||||
xmlFileTemplater = new RulesetFileTemplater(rulesDirectory);
|
||||
ruleAnalyzer = new RuntimeRulePropertiesAnalyzer(runtimeClasspath);
|
||||
logger.fine("Merge xsl:" + xmlFileTemplater.getMergeRulesetXsl());
|
||||
}
|
||||
|
||||
@@ -145,7 +163,19 @@ public class RuleSetToDocs implements PmdBuildTools {
|
||||
}
|
||||
|
||||
private void convertRuleSetFile(File ruleset,File target) throws PmdBuildException {
|
||||
xmlFileTemplater.transform(ruleset,target,xmlFileTemplater.getRulesetToDocsXsl());
|
||||
try {
|
||||
DOMSource dom = XmlUtil.createDomSourceFrom(new FileInputStream(ruleset));
|
||||
Document document = (Document)dom.getNode();
|
||||
NodeList rules = document.getElementsByTagName("rule");
|
||||
for (int i = 0; i < rules.getLength(); i++) {
|
||||
Node rule = rules.item(i);
|
||||
ruleAnalyzer.analyze(document, rule);
|
||||
}
|
||||
|
||||
xmlFileTemplater.transform(dom,target,xmlFileTemplater.getRulesetToDocsXsl());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addRulesetsToSiteXml(DOMSource backbone) {
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.build;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class RuntimeRulePropertiesAnalyzer {
|
||||
private static final String XPATH_RULE_CLASSNAME = "net.sourceforge.pmd.lang.rule.XPathRule";
|
||||
private ClassLoader cl;
|
||||
private Class<?> propertySource;
|
||||
private Class<?> propertyDesc;
|
||||
private Method nameMethod;
|
||||
private Method descMethod;
|
||||
private Method defaultValueMethod;
|
||||
private Field propertiesField;
|
||||
private Field propertiesValues;
|
||||
|
||||
public RuntimeRulePropertiesAnalyzer(URL[] runtimeClasspath) {
|
||||
init(runtimeClasspath);
|
||||
}
|
||||
|
||||
private void init(URL[] runtimeClasspath) {
|
||||
try {
|
||||
cl = new URLClassLoader(runtimeClasspath);
|
||||
propertySource = cl.loadClass("net.sourceforge.pmd.AbstractPropertySource");
|
||||
propertyDesc = cl.loadClass("net.sourceforge.pmd.PropertyDescriptor");
|
||||
nameMethod = propertyDesc.getDeclaredMethod("name");
|
||||
descMethod = propertyDesc.getDeclaredMethod("description");
|
||||
defaultValueMethod = propertyDesc.getDeclaredMethod("defaultValue");
|
||||
propertiesField = propertySource.getDeclaredField("propertyDescriptors");
|
||||
propertiesValues = propertySource.getDeclaredField("propertyValuesByDescriptor");
|
||||
propertiesField.setAccessible(true);
|
||||
propertiesValues.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes the class of the given rule definition to find the properties
|
||||
* this rule supports.
|
||||
* The properties are directly added to the rule node.
|
||||
* @param document the document, used to create new property nodes
|
||||
* @param rule the rule to analyze
|
||||
*/
|
||||
public void analyze(Document document, Node rule) {
|
||||
Node classAttribute = rule.getAttributes().getNamedItem("class");
|
||||
if (classAttribute == null) {
|
||||
// some rule definitions, like <rule ref="..."/> have no class attribute
|
||||
return;
|
||||
}
|
||||
String classAtt = classAttribute.getTextContent();
|
||||
if (XPATH_RULE_CLASSNAME.equals(classAtt)) {
|
||||
// xpath rules are ignored - they have there properties defined already in the rule definition xml
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> clazz = cl.loadClass(classAtt);
|
||||
Object ruleInstance = clazz.newInstance();
|
||||
@SuppressWarnings("rawtypes")
|
||||
List properties = (List)propertiesField.get(ruleInstance);
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map values = (Map)propertiesValues.get(ruleInstance);
|
||||
Element propsElem = null;
|
||||
NodeList ruleChilds = rule.getChildNodes();
|
||||
for (int j = 0; j < ruleChilds.getLength(); j++) {
|
||||
Node item = ruleChilds.item(j);
|
||||
if (item.getNodeType() == Node.ELEMENT_NODE && "properties".equals(item.getNodeName())) {
|
||||
propsElem = (Element)item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propsElem == null) {
|
||||
propsElem = document.createElement("properties");
|
||||
rule.appendChild(propsElem);
|
||||
}
|
||||
|
||||
for (Object o : properties) {
|
||||
Object value = values.get(o);
|
||||
if (value == null) {
|
||||
value = defaultValueMethod.invoke(o);
|
||||
}
|
||||
|
||||
Element propElem = document.createElement("property");
|
||||
propElem.setAttribute("name", (String)nameMethod.invoke(o));
|
||||
propElem.setAttribute("description", (String)descMethod.invoke(o));
|
||||
if (value != null) {
|
||||
String valueString = String.valueOf(value);
|
||||
if (value.getClass().isArray()) {
|
||||
valueString = Arrays.toString((Object[])value);
|
||||
}
|
||||
propElem.setAttribute("value", valueString);
|
||||
}
|
||||
propsElem.appendChild(propElem);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -5,6 +5,7 @@ package net.sourceforge.pmd.build.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,8 +16,13 @@ import java.io.FilenameFilter;
|
||||
public class RulesetFilenameFilter implements FilenameFilter {
|
||||
|
||||
// FUTURE: Make this somehow configurable ? Turn into an array passed by constructor ?
|
||||
// TODO: move to compiled regex to improve perf.
|
||||
private static final String[] patterns = { "^[0-9][0-9].*\\.xml", "^.*dogfood.*\\.xml", "^all-.*\\.xml", "^migrating_.*\\.xml", "^pmdspecific.xml"} ;
|
||||
private static final Pattern EXCLUDE = Pattern.compile(
|
||||
"(^[0-9][0-9].*\\.xml)" +
|
||||
"|(^.*dogfood.*\\.xml)" +
|
||||
"|(^all-.*\\.xml)" +
|
||||
"|(^migrating_.*\\.xml)" +
|
||||
"|(^pmdspecific.xml)"
|
||||
);
|
||||
|
||||
public boolean accept(File file, String name) {
|
||||
if ( doesNotMatchExcludeNames(name) )
|
||||
@@ -26,10 +32,6 @@ public class RulesetFilenameFilter implements FilenameFilter {
|
||||
}
|
||||
|
||||
private boolean doesNotMatchExcludeNames(String name) {
|
||||
for ( String pattern : patterns ) {
|
||||
if ( name.matches(pattern))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !EXCLUDE.matcher(name).matches();
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,10 @@ import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.build.PmdBuildException;
|
||||
|
||||
@@ -28,20 +30,20 @@ public final class FileUtil {
|
||||
|
||||
public static String pathToParent = "..";
|
||||
|
||||
private FileUtil() {};
|
||||
private FileUtil() {}
|
||||
|
||||
public static Set<File> listFilesFrom(File dir) {
|
||||
public static List<File> listFilesFrom(File dir) {
|
||||
return filterFilesFrom(dir, null);
|
||||
}
|
||||
|
||||
public static Set<File> filterFilesFrom(File dir, FilenameFilter filter) {
|
||||
Set<File> filteredFiles = new HashSet<File>(0);
|
||||
public static List<File> filterFilesFrom(File dir, FilenameFilter filter) {
|
||||
List<File> filteredFiles = new LinkedList<File>();
|
||||
if ( dir != null ) {
|
||||
File[] files = dir.listFiles(filter);
|
||||
if ( files != null && files.length > 0 )
|
||||
for ( int fileIterator = 0 ; fileIterator < files.length ; fileIterator++ )
|
||||
filteredFiles.add(files[fileIterator]);
|
||||
filteredFiles.addAll(Arrays.asList(files));
|
||||
}
|
||||
Collections.sort(filteredFiles);
|
||||
return filteredFiles;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
package net.sourceforge.pmd.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.build.PmdBuildException;
|
||||
import net.sourceforge.pmd.build.PmdBuildTools;
|
||||
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.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Says "Hi" to the user.
|
||||
* @goal pmd-pre-site
|
||||
* @requiresDependencyResolution runtime
|
||||
*/
|
||||
public class PmdPreSite extends AbstractMojo
|
||||
{
|
||||
@@ -37,28 +46,56 @@ public class PmdPreSite extends AbstractMojo
|
||||
/**
|
||||
* Path to the existing site descriptor
|
||||
*
|
||||
* @parameter expression="${pmd.rulesets}" default-value="src/main/resources/rulesets/
|
||||
* @parameter expression="${pmd.rulesets}" default-value="src/main/resources/rulesets/"
|
||||
*/
|
||||
private String rulesetsDirectory;
|
||||
private String rulesetsDirectory;
|
||||
|
||||
/**
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
public void execute() throws MojoExecutionException {
|
||||
getLog().info("PMD: site generation preparation");
|
||||
getLog().debug("- target:" + target);
|
||||
getLog().debug("- siteXml:" + siteXml);
|
||||
getLog().debug("- rulesets:" + rulesetsDirectory);
|
||||
getLog().debug(" -siteXmlTarget" + siteXmlTarget);
|
||||
PmdBuildTools tool = new RuleSetToDocs();
|
||||
tool.setTargetDirectory(target);
|
||||
tool.setSiteXml(siteXml);
|
||||
tool.setRulesDirectory(rulesetsDirectory);
|
||||
tool.setSiteXmlTarget(siteXmlTarget);
|
||||
List<URL> runtimeClasspath = determineRuntimeClasspath();
|
||||
|
||||
getLog().info("PMD: site generation preparation");
|
||||
getLog().debug("- target:" + target);
|
||||
getLog().debug("- siteXml:" + siteXml);
|
||||
getLog().debug("- rulesets:" + rulesetsDirectory);
|
||||
getLog().debug(" -siteXmlTarget" + siteXmlTarget);
|
||||
|
||||
try {
|
||||
tool.convertRulesets();
|
||||
tool.preSiteGeneration();
|
||||
}
|
||||
catch ( PmdBuildException e) {
|
||||
throw new MojoExecutionException(e.getMessage());
|
||||
PmdBuildTools tool = new RuleSetToDocs();
|
||||
tool.setTargetDirectory(target);
|
||||
tool.setSiteXml(siteXml);
|
||||
tool.setRulesDirectory(rulesetsDirectory);
|
||||
tool.setSiteXmlTarget(siteXmlTarget);
|
||||
tool.setRuntimeClasspath(runtimeClasspath.toArray(new URL[runtimeClasspath.size()]));
|
||||
|
||||
try {
|
||||
tool.convertRulesets();
|
||||
tool.preSiteGeneration();
|
||||
}
|
||||
catch ( PmdBuildException e) {
|
||||
throw new MojoExecutionException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private List<URL> determineRuntimeClasspath() {
|
||||
List<URL> runtimeClasspath;
|
||||
try {
|
||||
runtimeClasspath = new ArrayList<URL>();
|
||||
runtimeClasspath.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL());
|
||||
Set<Artifact> runtimeArtifacts = project.getArtifacts();
|
||||
for (Artifact a : runtimeArtifacts) {
|
||||
if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()) ) {
|
||||
runtimeClasspath.add(a.getFile().toURI().toURL());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return runtimeClasspath;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
<?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:template match="root">
|
||||
<xsl:comment>
|
||||
THIS FILE HAS BEEN AUTOMATICLY GENERATED.
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</document>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="rule">
|
||||
<xsl:template match="rule[@name]">
|
||||
<xsl:variable name="rulename" select="@name"/>
|
||||
<xsl:variable name="classname" select="@class"/>
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
<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="$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:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
</li>
|
||||
</xsl:for-each>
|
||||
</ul>
|
||||
|
||||
<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"><xsl:value-of select="@name"/></xsl:variable>
|
||||
<xsl:for-each select="ruleset">
|
||||
@@ -40,8 +43,12 @@
|
||||
<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:value-of select="@name"/>: <xsl:value-of select="description"/></li>
|
||||
<xsl:for-each select="./rule[@name]">
|
||||
<li>
|
||||
<a>
|
||||
<xsl:attribute name="href"><xsl:value-of select="substring(@externalInfoUrl,$urlPrefixLength + 1)"/></xsl:attribute>
|
||||
<xsl:value-of select="@name"/>
|
||||
</a>: <xsl:value-of select="description"/></li>
|
||||
</xsl:for-each>
|
||||
</ul>
|
||||
</subsection>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd;
|
||||
|
||||
/*
|
||||
* Note: This class is here in pmd-build to test the RuntimeRulePropertiesAnalyzer
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AbstractPropertySource {
|
||||
|
||||
protected List<PropertyDescriptor> propertyDescriptors = new ArrayList<PropertyDescriptor>();
|
||||
protected Map<PropertyDescriptor, Object> propertyValuesByDescriptor = new HashMap<PropertyDescriptor, Object>();
|
||||
|
||||
protected void defineProperty(final String name, final String description, final Object defaultValue) {
|
||||
net.sourceforge.pmd.PropertyDescriptor descriptor = new net.sourceforge.pmd.PropertyDescriptor() {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object defaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
propertyDescriptors.add(descriptor);
|
||||
propertyValuesByDescriptor.put(descriptor, defaultValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd;
|
||||
|
||||
/*
|
||||
* Note: This class is here in pmd-build to test the RuntimeRulePropertiesAnalyzer
|
||||
*/
|
||||
|
||||
public interface PropertyDescriptor {
|
||||
|
||||
String name();
|
||||
String description();
|
||||
Object defaultValue();
|
||||
}
|
||||
@@ -5,10 +5,7 @@ package net.sourceforge.pmd;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sourceforge.pmd.build.PmdBuildException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
@@ -19,31 +16,14 @@ import org.junit.Before;
|
||||
public abstract class TestBase {
|
||||
|
||||
protected static String TEST_DIR = "target/test-environment/";
|
||||
protected static File testDir = null;
|
||||
protected static File testDir = new File(TEST_DIR);
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testDir = new File(TEST_DIR);
|
||||
if (! testDir.exists() && ! testDir.mkdir() )
|
||||
{
|
||||
throw new PmdBuildException("Can't create " + TEST_DIR);
|
||||
}
|
||||
else if ( ! testDir.isDirectory() )
|
||||
{
|
||||
throw new PmdBuildException("testdir " + TEST_DIR + " exist !");
|
||||
}
|
||||
|
||||
FileUtils.copyDirectory(new File("src/test/resources/sample-pmd"), testDir);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (testDir != null) {
|
||||
FileUtils.deleteDirectory(testDir);
|
||||
}
|
||||
testDir = null;
|
||||
FileUtils.deleteDirectory(testDir);
|
||||
FileUtils.copyDirectoryStructure(new File("src/test/resources/sample-pmd"), testDir);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,14 @@
|
||||
|
||||
package net.sourceforge.pmd.ant;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import net.sourceforge.pmd.TestBase;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -17,10 +23,16 @@ public class PmdBuildTaskTest extends TestBase {
|
||||
@Test
|
||||
public void antTask() throws Exception {
|
||||
PmdBuildTask task = new PmdBuildTask();
|
||||
task.setRulesDirectory(TEST_DIR + "rulesets");
|
||||
task.setRulesDirectory(TEST_DIR + "src/main/resources/rulesets");
|
||||
task.setTarget(TEST_DIR + "target");
|
||||
task.setSiteXml(TEST_DIR + "site/site.pre.xml");
|
||||
task.setSiteXmlTarget(TEST_DIR + "site/site.xml");
|
||||
task.setSiteXml(TEST_DIR + "src/site/site.pre.xml");
|
||||
task.setSiteXmlTarget(TEST_DIR + "src/site/site.xml");
|
||||
task.setRuntimeClasspath(new URL[] {new File("target/test-classes").toURI().toURL()});
|
||||
task.execute();
|
||||
|
||||
String site = IOUtils.toString(new File(TEST_DIR + "src/site/site.xml").toURI());
|
||||
assertTrue(site.contains("<item name=\"Basic\""));
|
||||
assertTrue(site.contains("<item name=\"Code Size\""));
|
||||
assertTrue(site.indexOf("<item name=\"Basic\"") < site.indexOf("<item name=\"Code Size\""));
|
||||
}
|
||||
}
|
||||
+39
-1
@@ -3,8 +3,19 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.build;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.TestBase;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -16,9 +27,36 @@ public class RuleSetToDocsTest extends TestBase {
|
||||
@Test
|
||||
public void convertRulesetsTest() throws Exception {
|
||||
RuleSetToDocs builder = new RuleSetToDocs();
|
||||
builder.setRulesDirectory(TEST_DIR + "rulesets");
|
||||
builder.setRulesDirectory(TEST_DIR + "src/main/resources/rulesets");
|
||||
builder.setTargetDirectory(TEST_DIR + "target");
|
||||
builder.setRuntimeClasspath(new URL[] {new File("target/test-classes").toURI().toURL()});
|
||||
|
||||
builder.convertRulesets();
|
||||
|
||||
String codeSizeRuleset = IOUtils.toString(new File(TEST_DIR + "target/java/codesize.xml").toURI());
|
||||
assertTrue(codeSizeRuleset.contains("minimum"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readPropertyDescriptors() throws Exception {
|
||||
ClassLoader cl = RuleSetToDocsTest.class.getClassLoader();
|
||||
Class<?> clazz = cl.loadClass("net.sourceforge.pmd.lang.java.rule.codesize.NPathComplexityRule");
|
||||
Object ruleInstance = clazz.newInstance();
|
||||
Class<?> propertySource = cl.loadClass("net.sourceforge.pmd.AbstractPropertySource");
|
||||
Class<?> propertyDesc = cl.loadClass("net.sourceforge.pmd.PropertyDescriptor");
|
||||
Method nameMethod = propertyDesc.getDeclaredMethod("name");
|
||||
Method descMethod = propertyDesc.getDeclaredMethod("description");
|
||||
Field propertiesField = propertySource.getDeclaredField("propertyDescriptors");
|
||||
Field propertiesValues = propertySource.getDeclaredField("propertyValuesByDescriptor");
|
||||
propertiesField.setAccessible(true);
|
||||
propertiesValues.setAccessible(true);
|
||||
@SuppressWarnings("rawtypes")
|
||||
List properties = (List)propertiesField.get(ruleInstance);
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map values = (Map)propertiesValues.get(ruleInstance);
|
||||
assertEquals(1, properties.size());
|
||||
assertEquals("minimum", nameMethod.invoke(properties.get(0)));
|
||||
assertEquals("The minimum threshold property.", descMethod.invoke(properties.get(0)));
|
||||
assertEquals("200.0", String.valueOf(values.get(properties.get(0))));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.build;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sourceforge.pmd.build.filefilter.RulesetFilenameFilter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RulesetFilenameFilterTest {
|
||||
|
||||
@Test
|
||||
public void testAccept() {
|
||||
RulesetFilenameFilter filter = new RulesetFilenameFilter();
|
||||
File directory = new File(".");
|
||||
|
||||
assertTrue(filter.accept(directory, "codesize.xml"));
|
||||
|
||||
assertFalse(filter.accept(directory, "some-text-file.txt"));
|
||||
assertFalse(filter.accept(directory, "all-java.xml"));
|
||||
assertFalse(filter.accept(directory, "dogfood.xml"));
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.codesize;
|
||||
|
||||
/*
|
||||
* Note: This class is here in pmd-build to test the RuntimeRulePropertiesAnalyzer
|
||||
*/
|
||||
|
||||
import net.sourceforge.pmd.AbstractPropertySource;
|
||||
|
||||
public class NPathComplexityRule extends AbstractPropertySource {
|
||||
|
||||
public NPathComplexityRule() {
|
||||
defineProperty("minimum", "The minimum threshold property.", 200.0d);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.sourceforge.pmd.maven;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PmdPreSiteTest extends AbstractMojoTestCase {
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
FileUtils.deleteDirectory( new File( getBasedir(), "target/unit/sample-pmd" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMojo() throws Exception {
|
||||
FileUtils.copyDirectoryStructure(new File("src/test/resources/sample-pmd"),
|
||||
new File("target/unit/sample-pmd"));
|
||||
|
||||
File pom = getTestFile( "target/unit/sample-pmd/pom.xml" );
|
||||
assertNotNull( pom );
|
||||
assertTrue( pom.exists() );
|
||||
|
||||
PmdPreSite myMojo = (PmdPreSite) lookupMojo( "pmd-pre-site", pom );
|
||||
assertNotNull( myMojo );
|
||||
myMojo.execute();
|
||||
|
||||
|
||||
String codeSizeRuleset = IOUtils.toString(new File("target/unit/sample-pmd/target/generated-xdocs/rules/java/codesize.xml").toURI());
|
||||
assertTrue(codeSizeRuleset.contains("minimum"));
|
||||
|
||||
String basicRuleset = IOUtils.toString(new File("target/unit/sample-pmd/target/generated-xdocs/rules/java/basic.xml").toURI());
|
||||
assertEquals(1, StringUtils.countMatches(basicRuleset, "<subsection"));
|
||||
|
||||
String indexPage = IOUtils.toString(new File("target/unit/sample-pmd/target/generated-xdocs/rules/index.xml").toURI());
|
||||
assertFalse(indexPage.contains("<li>: </li>"));
|
||||
|
||||
String site = IOUtils.toString(new File("target/unit/sample-pmd/src/site/site.xml").toURI());
|
||||
assertTrue(site.contains("<item name=\"Basic\""));
|
||||
assertTrue(site.contains("<item name=\"Code Size\""));
|
||||
assertTrue(site.indexOf("<item name=\"Basic\"") < site.indexOf("<item name=\"Code Size\""));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package net.sourceforge.pmd.maven.stubs;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
|
||||
public class ProjectStub extends MavenProjectStub {
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ProjectStub()
|
||||
{
|
||||
MavenXpp3Reader pomReader = new MavenXpp3Reader();
|
||||
Model model;
|
||||
try
|
||||
{
|
||||
model = pomReader.read( ReaderFactory.newXmlReader( new File( getBasedir(), "pom.xml" ) ) );
|
||||
setModel( model );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
|
||||
setGroupId( model.getGroupId() );
|
||||
setArtifactId( model.getArtifactId() );
|
||||
setVersion( model.getVersion() );
|
||||
setName( model.getName() );
|
||||
setUrl( model.getUrl() );
|
||||
setPackaging( model.getPackaging() );
|
||||
|
||||
Build build = new Build();
|
||||
build.setFinalName( model.getArtifactId() );
|
||||
build.setDirectory( getBasedir() + "/target" );
|
||||
build.setSourceDirectory( getBasedir() + "/src/main/java" );
|
||||
build.setOutputDirectory( getBasedir() + "/target/classes" );
|
||||
build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
|
||||
build.setTestOutputDirectory( getBasedir() + "/target/test-classes" );
|
||||
setBuild( build );
|
||||
|
||||
List<String> compileSourceRoots = new ArrayList<String>();
|
||||
compileSourceRoots.add( getBasedir() + "/src/main/java" );
|
||||
setCompileSourceRoots( compileSourceRoots );
|
||||
|
||||
List<String> testCompileSourceRoots = new ArrayList<String>();
|
||||
testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
|
||||
setTestCompileSourceRoots( testCompileSourceRoots );
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public File getBasedir()
|
||||
{
|
||||
return new File( super.getBasedir() + "/target/unit/sample-pmd/" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Artifact> getRuntimeArtifacts() {
|
||||
return new ArrayList<Artifact>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd</artifactId>
|
||||
<name>PMD</name>
|
||||
<version>5.1.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-build</artifactId>
|
||||
<version>0.7-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<siteXml>${basedir}/target/unit/sample-pmd/src/site/site.pre.xml</siteXml>
|
||||
<siteXmlTarget>${basedir}/target/unit/sample-pmd/src/site/site.xml</siteXmlTarget>
|
||||
<target>${basedir}/target/unit/sample-pmd/target/generated-xdocs/rules</target>
|
||||
<rulesetsDirectory>${basedir}/target/unit/sample-pmd/src/main/resources/rulesets/</rulesetsDirectory>
|
||||
|
||||
<!-- The defined stubs -->
|
||||
<project implementation="net.sourceforge.pmd.maven.stubs.ProjectStub"/>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>pre-site</phase>
|
||||
<goals>
|
||||
<goal>pmd-pre-site</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
+2
@@ -47,4 +47,6 @@ public class JumbledIncrementerRule1 {
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule deprecated="true" ref="rulesets/java/codesize.xml/NPathComplexity"/>
|
||||
</ruleset>
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Code Size"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
|
||||
<description>
|
||||
The Code Size ruleset contains rules that find problems related to code size or complexity.
|
||||
</description>
|
||||
|
||||
<rule name="NPathComplexity"
|
||||
since="3.9"
|
||||
message="The method {0}() has an NPath complexity of {1}"
|
||||
class="net.sourceforge.pmd.lang.java.rule.codesize.NPathComplexityRule"
|
||||
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>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
void bar() { // this is something more complex than it needs to be,
|
||||
if (y) { // it should be broken down into smaller methods or functions
|
||||
for (j = 0; j < m; j++) {
|
||||
if (j > r) {
|
||||
doSomething();
|
||||
while (f < 5 ) {
|
||||
anotherThing();
|
||||
f -= 27;
|
||||
}
|
||||
} else {
|
||||
tryThis();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( r - n > 45) {
|
||||
while (doMagic()) {
|
||||
findRabbits();
|
||||
}
|
||||
}
|
||||
try {
|
||||
doSomethingDangerous();
|
||||
} catch (Exception ex) {
|
||||
makeAmends();
|
||||
} finally {
|
||||
dontDoItAgain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
File renamed without changes.
@@ -1,2 +0,0 @@
|
||||
http://cougaar.org/docman/view.php/17/58/license.html
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
#
|
||||
# Plugin properties
|
||||
#
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.name=PMDPlugin
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.author=Jiger Patel, Tom Copeland, Alan Ezust, Dale Anson
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=3.4
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.docs=doc/jedit.html
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.0=jdk 1.5
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.03.99.00
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.9
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.3=plugin CommonControlsPlugin 1.2
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-4.2.6.jar jaxen-1.1.1.jar asm-3.2.jar
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.description=The PMD plugin is a Java source code analysis tool.
|
||||
|
||||
|
||||
#
|
||||
# Menu properties
|
||||
#
|
||||
|
||||
# set activate on startup so that PMD can check automatically on save. If the
|
||||
# user unchecks the option to run on save, this setting will change to 'defer'.
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.activate=startup
|
||||
|
||||
# default is to run on save
|
||||
pmd.runPMDOnSave=true
|
||||
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu.label=$PMD
|
||||
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu=pmd-check-current-buffer pmd-check-all-open-buffers pmd-check-directory pmd-clear-errorlist pmd-run-designer %pmd-cpd
|
||||
pmd-cpd=cpd-currentfile cpd-dir
|
||||
browser-pmd-cpd=cpd-currentfile cpd-dir cpd-dir-recursively
|
||||
|
||||
#Dockables and Menu Labels
|
||||
pmd-check-current-buffer.label=Check current buffer
|
||||
pmd-check-all-open-buffers.label=Check all open buffers
|
||||
pmd-check-directory.label=Check all files in directory
|
||||
pmd-check-directory-recursively.label=Check all files in directory recursively
|
||||
pmd-clear-errorlist.label=Clear ErrorList
|
||||
pmd-run-designer.label=Run Rule Designer
|
||||
pmd-cpd.label=Detect Duplicate Code
|
||||
browser-pmd-cpd.label=Detect Duplicate Code
|
||||
cpd-currentfile.label=In Current File
|
||||
cpd-dir.label=In Directory
|
||||
cpd-dir-recursively.label=In Directory Recursively
|
||||
pmd-check-file.label=Check selected file(s)
|
||||
cpd-viewer.label=Copy/Paste Detector
|
||||
|
||||
|
||||
#
|
||||
# Option pane properties
|
||||
#
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.option-group=pmd.general pmd.rules pmd.cpd.general
|
||||
|
||||
#plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.option-pane=pmd
|
||||
options.pmd.general.label=PMD Settings
|
||||
options.pmd.general.code=new net.sourceforge.pmd.jedit.PMDGeneralOptionPane()
|
||||
options.pmd.rules.label=PMD Rules
|
||||
options.pmd.rules.code=new net.sourceforge.pmd.jedit.PMDRulesOptionPane()
|
||||
options.pmd.printRule=false
|
||||
options.pmd.cpd.general.label=CPD Settings
|
||||
options.pmd.cpd.general.code=new net.sourceforge.pmd.jedit.CPDOptionPane()
|
||||
|
||||
#Dockables properties.
|
||||
cpd-viewer.title=Copy/Paste Detector
|
||||
|
||||
#FS Browser properties
|
||||
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.browser-menu=pmd-check-file pmd-check-directory pmd-check-directory-recursively %browser-pmd-cpd
|
||||
|
||||
#pmd properties
|
||||
pmd.renderer=None
|
||||
pmd.showprogress=true
|
||||
pmd.progressbar.foreground=#000000
|
||||
pmd.progressbar.background=#FFC800
|
||||
|
||||
|
||||
|
||||
# various strings
|
||||
net.sf.pmd.CPD,_Select_File_Type=CPD, Select File Type
|
||||
net.sf.pmd.CPD_does_not_yet_support_this_file_type>_=CPD does not yet support this file type:
|
||||
net.sf.pmd.Cannot_run_CPD_on_Invalid_directory/files.=Cannot run CPD on Invalid directory/files.
|
||||
net.sf.pmd.Copy/Paste_Detector=Copy/Paste Detector
|
||||
net.sf.pmd.Copy/Paste_detection_can_not_be_performed_on_this_file\nbecause_the_mode_can_not_be_determined.=Copy/Paste detection can not be performed on this file\nbecause the mode can not be determined.
|
||||
net.sf.pmd.Description=Description
|
||||
net.sf.pmd.Error_Loading_Custom_Ruleset=Error Loading Custom Ruleset
|
||||
net.sf.pmd.Error_Loading_Rules=Error Loading Rules
|
||||
net.sf.pmd.Error_loading_rules._Check_any_custom_rulesets_for_errors.=Error loading rules. Check any custom rulesets for errors.
|
||||
net.sf.pmd.Error_while_processing_=Error while processing
|
||||
net.sf.pmd.Example=Example
|
||||
net.sf.pmd.Exclusions=Exclusions
|
||||
net.sf.pmd.Export_Output_as_=Export Output as:
|
||||
net.sf.pmd.Ignore_Literals_&_identifiers_when_detecting_Duplicate_Code=Ignore Literals & identifiers when detecting Duplicate Code
|
||||
net.sf.pmb.Inclustions=Inclusions
|
||||
net.sf.pmd.Invalid_Renderer=Invalid Renderer
|
||||
net.sf.pmd.Minimum_Tile_Size>=Minimum Tile Size:
|
||||
net.sf.pmd.Minimum_Tile_size_>=Minimum Tile size :
|
||||
net.sf.pmd.No_duplicates_found.=No duplicates found.
|
||||
net.sf.pmd.No_problems_found=No problems found
|
||||
net.sf.pmd.One_Directory_has_to_be_selected_in_which_to_detect_duplicate_code.=One Directory has to be selected in which to detect duplicate code.
|
||||
net.sf.pmd.One_file_must_be_selected=One file must be selected
|
||||
net.sf.pmd.PMD_Check_in_Progress=PMD Check in Progress
|
||||
net.sf.pmd.PMD_General_Options=PMD General Options
|
||||
net.sf.pmd.Please_see_http>//pmd.sf.net/_for_more_information=Please see http://pmd.sf.net/ for more information
|
||||
net.sf.pmd.Print_Rulename_in_ErrorList=Print Rulename in ErrorList
|
||||
net.sf.pmd.Recursive=Recursive
|
||||
net.sf.pmd.Rules=Rules
|
||||
net.sf.pmd.Run_PMD_on_Save=Run PMD on Save
|
||||
net.sf.pmd.Select_default_rules=Select default rules
|
||||
net.sf.pmd.Select_type_of_files_to_check>=Select type of files to check:
|
||||
net.sf.pmd.Selected_file_cannot_be_a_Directory.=Selected file cannot be a Directory.
|
||||
net.sf.pmd.Selected_file_must_be_a_Directory.=Selected file must be a Directory.
|
||||
net.sf.pmd.Selection_must_be_a_directory=Selection must be a directory
|
||||
net.sf.pmd.Selection_not_a_directory.=Selection not a directory.
|
||||
net.sf.pmd.Show_PMD_Progress_Bar=Show PMD Progress Bar
|
||||
net.sf.pmd.There_was_an_error_loading_one_or_more_custom_rulesets,_so_no_custom_rulesets_were_loaded=There was an error loading one or more custom rulesets, so no custom rulesets were loaded
|
||||
net.sf.pmd.Unable_to_find_rulesets,_halting_PMD=Unable to find rulesets, halting PMD
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE ACTIONS SYSTEM "actions.dtd">
|
||||
<ACTIONS>
|
||||
<ACTION NAME="pmd-check-current-buffer">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.check(buffer, view);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-check-all-open-buffers">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkAllOpenBuffers(view);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-check-directory">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-clear-errorlist">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.clearErrorList();
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-run-designer">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.runDesigner();
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-currentfile">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-dir">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
</ACTIONS>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE ACTIONS SYSTEM "actions.dtd">
|
||||
<ACTIONS>
|
||||
<ACTION NAME="pmd-check-file">
|
||||
<CODE>net.sourceforge.pmd.jedit.PMDJEditPlugin.checkFile(view,browser);</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-check-directory">
|
||||
<CODE>net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,false);</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-check-directory-recursively">
|
||||
<CODE>net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,true);</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-currentfile">
|
||||
<CODE>net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view, browser);</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-dir">
|
||||
<CODE>net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,browser, false);</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-dir-recursively">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,browser, true);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
</ACTIONS>
|
||||
Loaded 30 of 306 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user