Sonarqube rule: improvements
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 3 Aug 2016 18:36:36 +0000 (20:36 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 3 Aug 2016 18:36:36 +0000 (20:36 +0200)
Sonar/Plugins/hello-world-plugin/pom.xml
Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/CheckList.java
Sonar/Plugins/hello-world-plugin/src/main/java/de/example/helloworld/checks/HelloWorldCheck.java
Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesDefinition.java
Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.html [deleted file]
Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/gushelloworld/HELLOWORLDO001_java.json [deleted file]
Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.html [new file with mode: 0644]
Sonar/Plugins/hello-world-plugin/src/main/resources/de/example/l10n/helloworld/rules/helloworld/HELLOWORLD0001_java.json [new file with mode: 0644]

index 8851c7c..0a00508 100644 (file)
@@ -7,7 +7,7 @@
   <packaging>sonar-plugin</packaging>
   <version>0.1-SNAPSHOT</version>
 
-  <name>HelloWorld Plugin for SonarQube</name>
+  <name>HelloWorld</name>
   <description>HelloWorld example plugin for SonarQube</description>
   <url>https://gumartinm.name/</url>
   <organization>
       <version>${java.plugin.version}</version>
       <scope>provided</scope>
     </dependency>
+      <dependency>
+        <groupId>com.google.code.gson</groupId>
+        <artifactId>gson</artifactId>
+        <version>2.6.2</version>
+        <scope>compile</scope>
+      </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>19.0</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.6</version>
+    </dependency>
+    <dependency>
+        <groupId>org.sonarsource.sslr-squid-bridge</groupId>
+        <artifactId>sslr-squid-bridge</artifactId>
+        <version>2.6.1</version>
+        <exclusions>
+          <exclusion>
+            <groupId>org.codehaus.sonar.sslr</groupId>
+            <artifactId>sslr-core</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.codehaus.sonar</groupId>
+            <artifactId>sonar-plugin-api</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.codehaus.sonar.sslr</groupId>
+            <artifactId>sslr-xpath</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+          <dependency>
+      <groupId>org.sonarsource.java</groupId>
+      <artifactId>java-frontend</artifactId>
+      <version>4.0</version>
+    </dependency>
+      
+    
+
 
     <!-- unit tests -->
     <dependency>
index d93b33d..673e836 100644 (file)
@@ -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() {
        }
index 901ce08..554b672 100644 (file)
@@ -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
index 41ec76c..e88f017 100644 (file)
@@ -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<Class> 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 (file)
index 73bff1b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<p>HelloWorld rule description.</p>
-<h2>Noncompliant Code Example</h2>
-<pre>
-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
-  ...
-}
-</pre>
-<p>or </p>
-<pre>
-public class MyAction extends Action {
-  private String userName;  //Same reason
-  ...
-}
-</pre>
-<h2>See</h2>
-<ul>
-  <li> <a href="https://www.securecoding.cert.org/confluence/x/EYBUC">CERT, MSC11-J.</a> - Do not let session information leak within a servlet </li>
-</ul>
-
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 (file)
index 4421cd9..0000000
+++ /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 (file)
index 0000000..d0f8e3f
--- /dev/null
@@ -0,0 +1,18 @@
+<p>HelloWorld rule description.</p>
+<h2>Noncompliant Code Example</h2>
+<pre>
+class MyClass {
+       
+       int foo1(int value) { return 0; }
+               
+       MyClass foo2(MyClass value) { return null; }
+       
+       ...
+}
+</pre>
+<h2>See</h2>
+<ul>
+  <li> <a href="https://www.securecoding.cert.org/confluence/x/EYBUC">CERT, MSC11-J.</a> - Do not let session information leak within a servlet </li>
+</ul>
+
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 (file)
index 0000000..4421cd9
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "title": "HelloWorld SonarQube rule",
+  "status": "ready",
+  "remediation": {
+    "func": "Constant\/Issue",
+    "constantCost": "5min"
+  },
+  "tags": [
+    "bad-practice"
+  ],
+  "defaultSeverity": "Major"
+}