From: Gustavo Martin Morcuende Date: Wed, 3 Aug 2016 18:36:36 +0000 (+0200) Subject: Sonarqube rule: improvements X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=6d92e65a76d49631058eb3183bc883df9fd5e39c;p=JavaForFun Sonarqube rule: improvements --- diff --git a/Sonar/Plugins/hello-world-plugin/pom.xml b/Sonar/Plugins/hello-world-plugin/pom.xml index 8851c7c..0a00508 100644 --- a/Sonar/Plugins/hello-world-plugin/pom.xml +++ b/Sonar/Plugins/hello-world-plugin/pom.xml @@ -7,7 +7,7 @@ sonar-plugin 0.1-SNAPSHOT - HelloWorld Plugin for SonarQube + HelloWorld HelloWorld example plugin for SonarQube https://gumartinm.name/ @@ -37,6 +37,53 @@ ${java.plugin.version} provided + + com.google.code.gson + gson + 2.6.2 + compile + + + com.google.guava + guava + 19.0 + + + commons-lang + commons-lang + 2.6 + + + org.sonarsource.sslr-squid-bridge + sslr-squid-bridge + 2.6.1 + + + org.codehaus.sonar.sslr + sslr-core + + + org.codehaus.sonar + sonar-plugin-api + + + org.codehaus.sonar.sslr + sslr-xpath + + + org.slf4j + jcl-over-slf4j + + + + + org.sonarsource.java + java-frontend + 4.0 + + + + diff --git a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/CheckList.java b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/CheckList.java index d93b33d..673e836 100644 --- a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/CheckList.java +++ b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/CheckList.java @@ -2,11 +2,13 @@ package de.example.helloworld.checks; import java.util.List; -import org.sonar.api.internal.google.common.collect.ImmutableList; import org.sonar.plugins.java.api.JavaCheck; +import com.google.common.collect.ImmutableList; + public final class CheckList { - public static final String REPOSITORY_KEY = "gushelloworld"; + public static final String REPOSITORY_KEY = "helloworld"; + public static final String REPOSITORY_NAME = "Hello World"; private CheckList() { } diff --git a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/HelloWorldCheck.java b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/HelloWorldCheck.java index 901ce08..554b672 100644 --- a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/HelloWorldCheck.java +++ b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/HelloWorldCheck.java @@ -12,7 +12,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind; import com.google.common.collect.ImmutableList; -@Rule(key = "HELLOWORLDO001") +@Rule(key = "HELLOWORLD0001") public class HelloWorldCheck extends IssuableSubscriptionVisitor { @Override diff --git a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesDefinition.java b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesDefinition.java index 41ec76c..e88f017 100644 --- a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesDefinition.java +++ b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesDefinition.java @@ -29,12 +29,15 @@ import de.example.helloworld.checks.CheckList; * Definition of rules. */ public class HelloWorldRulesDefinition implements RulesDefinition { - private static final String RESOURCE_BASE_PATH = "/de/example/l10n/helloworld/rules/gushelloworld"; + private static final String RESOURCE_BASE_PATH = "/de/example/l10n/helloworld/rules/helloworld"; + private final Gson gson = new Gson(); @Override public void define(Context context) { - NewRepository repository = context.createRepository(CheckList.REPOSITORY_KEY, Java.KEY).setName("Gus HelloWorld Definition"); + NewRepository repository = context + .createRepository(CheckList.REPOSITORY_KEY, Java.KEY) + .setName(CheckList.REPOSITORY_NAME); List checks = CheckList.getChecks(); new RulesDefinitionAnnotationLoader().load(repository, Iterables.toArray(checks, Class.class)); for (Class ruleClass : checks) { diff --git a/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.html b/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.html deleted file mode 100644 index 73bff1b..0000000 --- a/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.html +++ /dev/null @@ -1,20 +0,0 @@ -

HelloWorld rule description.

-

Noncompliant Code Example

-
-public class MyServlet extends HttpServlet {
-  private String userName;  //As this field is shared by all users, it's obvious that this piece of information should be managed differently
-  ...
-}
-
-

or

-
-public class MyAction extends Action {
-  private String userName;  //Same reason
-  ...
-}
-
-

See

-
    -
  • CERT, MSC11-J. - Do not let session information leak within a servlet
  • -
- diff --git a/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.json b/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.json deleted file mode 100644 index 4421cd9..0000000 --- a/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "title": "HelloWorld SonarQube rule", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "5min" - }, - "tags": [ - "bad-practice" - ], - "defaultSeverity": "Major" -} diff --git a/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.html b/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.html new file mode 100644 index 0000000..d0f8e3f --- /dev/null +++ b/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.html @@ -0,0 +1,18 @@ +

HelloWorld rule description.

+

Noncompliant Code Example

+
+class MyClass {
+	
+	int foo1(int value) { return 0; }
+		
+	MyClass foo2(MyClass value) { return null; }
+	
+	...
+ 
+}
+
+

See

+
    +
  • CERT, MSC11-J. - Do not let session information leak within a servlet
  • +
+ diff --git a/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.json b/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.json new file mode 100644 index 0000000..4421cd9 --- /dev/null +++ b/Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.json @@ -0,0 +1,12 @@ +{ + "title": "HelloWorld SonarQube rule", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + "bad-practice" + ], + "defaultSeverity": "Major" +}