aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/pmd-extensions
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-06 14:08:06 +0000
commitaeadc1f9129274949daaa57738c7c4550bdfbc7b (patch)
tree08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /tests/integration/pmd-extensions
downloadsonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz
sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'tests/integration/pmd-extensions')
-rw-r--r--tests/integration/pmd-extensions/pmd-extensions.xml17
-rw-r--r--tests/integration/pmd-extensions/pom.xml34
-rw-r--r--tests/integration/pmd-extensions/src/main/java/org/sonar/it/pmd/MaximumMethodsCountCheck.java25
-rw-r--r--tests/integration/pmd-extensions/src/main/resources/rulesets/extensions.xml51
4 files changed, 127 insertions, 0 deletions
diff --git a/tests/integration/pmd-extensions/pmd-extensions.xml b/tests/integration/pmd-extensions/pmd-extensions.xml
new file mode 100644
index 00000000000..abafbd45832
--- /dev/null
+++ b/tests/integration/pmd-extensions/pmd-extensions.xml
@@ -0,0 +1,17 @@
+<rules>
+ <rule key="MaximumMethodsCountCheck">
+ <name>Maximum Methods Count Check</name>
+ <configKey>rulesets/extensions.xml/MaximumMethodsCountCheck</configKey>
+ <category name="Usability"/>
+ <description>Maximum number of methods authorised</description>
+ <param key="maxAuthorisedMethodsCount" type="i">
+ <description>Maximum number of methods authorised. Default is 2.</description>
+ </param>
+ </rule>
+ <rule key="AvoidIfWithoutBrace">
+ <name>Avoid if without using brace</name>
+ <configKey>rulesets/extensions.xml/AvoidIfWithoutBrace</configKey>
+ <category name="Usability"/>
+ <description>éviter les if sans crochet.</description>
+ </rule>
+ </rules> \ No newline at end of file
diff --git a/tests/integration/pmd-extensions/pom.xml b/tests/integration/pmd-extensions/pom.xml
new file mode 100644
index 00000000000..a306799c4f7
--- /dev/null
+++ b/tests/integration/pmd-extensions/pom.xml
@@ -0,0 +1,34 @@
+<?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>
+ <parent>
+ <groupId>org.codehaus.sonar.tests</groupId>
+ <artifactId>integration</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>pmd-extensions</artifactId>
+ <name>Sonar :: Integration Tests :: PMD Extensions</name>
+ <description>Samples of PMD extensions</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>pmd</groupId>
+ <artifactId>pmd</artifactId>
+ <version>4.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/tests/integration/pmd-extensions/src/main/java/org/sonar/it/pmd/MaximumMethodsCountCheck.java b/tests/integration/pmd-extensions/src/main/java/org/sonar/it/pmd/MaximumMethodsCountCheck.java
new file mode 100644
index 00000000000..2d8abb00f49
--- /dev/null
+++ b/tests/integration/pmd-extensions/src/main/java/org/sonar/it/pmd/MaximumMethodsCountCheck.java
@@ -0,0 +1,25 @@
+package org.sonar.it.pmd;
+
+import java.util.ArrayList;
+import java.util.List;
+import net.sourceforge.pmd.AbstractRule;
+import net.sourceforge.pmd.ast.ASTClassOrInterfaceBody;
+import net.sourceforge.pmd.ast.ASTMethodDeclaration;
+import net.sourceforge.pmd.properties.IntegerProperty;
+
+public class MaximumMethodsCountCheck extends AbstractRule {
+
+ private static final IntegerProperty propertyDescriptor = new IntegerProperty(
+ "maxAuthorisedMethodsCount", "Maximum number of methods authorised", 2, 1.0f);
+
+ public Object visit(ASTClassOrInterfaceBody node, Object data) {
+ List<ASTMethodDeclaration> methods = new ArrayList<ASTMethodDeclaration>();
+ methods = (List<ASTMethodDeclaration>)node.findChildrenOfType(ASTMethodDeclaration.class);
+
+ if (methods.size() > getIntProperty(propertyDescriptor)) {
+ addViolation(data, node);
+ }
+ return super.visit(node,data);
+ }
+
+}
diff --git a/tests/integration/pmd-extensions/src/main/resources/rulesets/extensions.xml b/tests/integration/pmd-extensions/src/main/resources/rulesets/extensions.xml
new file mode 100644
index 00000000000..6997ed4406b
--- /dev/null
+++ b/tests/integration/pmd-extensions/src/main/resources/rulesets/extensions.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<ruleset name="PMD extensions"
+ xmlns="http://pmd.sf.net/ruleset/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+ <rule name="MaximumMethodsCountCheck"
+ message="Avoid too many methods"
+ class="org.sonar.it.pmd.MaximumMethodsCountCheck">
+ <description>
+ Avoid too many methods
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="maxAuthorisedMethodsCount" description="Maximum number of methods authorised" value="3"/>
+ </properties>
+ <example>
+ <![CDATA[
+ // too many methods!
+ public void doSomething() {}
+ public void doSomething2() {}
+ public void doSomething3() {}
+ public void doSomething4() {}
+
+ ]]>
+ </example>
+ </rule>
+ <rule name="AvoidIfWithoutBrace"
+ message="Avoid if without using brace"
+ class="net.sourceforge.pmd.rules.XPathRule">
+ <description>
+ Avoid if without using brace
+ </description>
+ <properties>
+ <property name="xpath">
+ <value>
+ <![CDATA[
+ //IfStatement[not(Statement/Block)]
+ ]]>
+ </value>
+ </property>
+ </properties>
+ <example>
+ <![CDATA[
+ // don't do this!
+ if (true)
+ test = "test";
+ ]]>
+ </example>
+ </rule>
+</ruleset> \ No newline at end of file