no time for comments
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 7 Aug 2016 22:51:20 +0000 (00:51 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 7 Aug 2016 22:51:20 +0000 (00:51 +0200)
Sonar/Plugins/sonar-custom-java-plugin/pom.xml
Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/ParameterCheck.java
Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheck.java
Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/plugins/custom/java/CustomSensor.java
Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/Custom_profile.json
Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.html [deleted file]
Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.json [deleted file]
Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.html [new file with mode: 0644]
Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.json [new file with mode: 0644]
Sonar/Plugins/sonar-custom-java-plugin/src/test/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheckTest.java

index 1b83a66..3f10d86 100644 (file)
@@ -29,7 +29,7 @@
       <version>${sonar.apiVersion}</version>
       <scope>provided</scope>
     </dependency>
-        <dependency>
+    <dependency>
       <groupId>org.sonarsource.java</groupId>
       <artifactId>sonar-java-plugin</artifactId>
       <type>sonar-plugin</type>
index a5ed7b8..914d345 100644 (file)
@@ -14,7 +14,7 @@ import org.sonar.plugins.java.api.tree.Tree.Kind;
 
 import com.google.common.collect.ImmutableList;
 
-@Rule(key = "GU0001")
+@Rule(key = "GUJ0001")
 public class ParameterCheck extends IssuableSubscriptionVisitor {
        private static final Logger LOG = Loggers.get(ParameterCheck.class);
 
index c3fc929..f9d5c29 100644 (file)
@@ -2,12 +2,15 @@ package de.example.custom.java.checks;
 
 import java.util.List;
 
+import javax.annotation.Nullable;
+
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.check.Rule;
 import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
 import org.sonar.plugins.java.api.JavaFileScannerContext;
 import org.sonar.plugins.java.api.semantic.Symbol;
+import org.sonar.plugins.java.api.tree.AnnotationTree;
 import org.sonar.plugins.java.api.tree.ClassTree;
 import org.sonar.plugins.java.api.tree.Tree;
 import org.sonar.plugins.java.api.tree.Tree.Kind;
@@ -15,7 +18,7 @@ import org.sonar.plugins.java.api.tree.VariableTree;
 
 import com.google.common.collect.ImmutableList;
 
-@Rule(key = "GU0002")
+@Rule(key = "GUJ0002")
 public class SpringServiceInstanceFieldCheck extends IssuableSubscriptionVisitor {
        private static final Logger LOG = Loggers.get(SpringServiceInstanceFieldCheck.class);
        
@@ -29,11 +32,18 @@ public class SpringServiceInstanceFieldCheck extends IssuableSubscriptionVisitor
 
        @Override
        public void visitNode(Tree tree) {
+               
                if (tree.is(Kind.CLASS) && isSpringService((ClassTree) tree)) {
                        
                }
                
        }
+       
+       
+         public void visitAnnotation(AnnotationTree annotationTree) {
+                   scan(annotationTree.annotationType());
+                   scan(annotationTree.arguments());
+                 }
         
        
          private static boolean isOwnedByASpringService(VariableTree variable) {
@@ -43,9 +53,14 @@ public class SpringServiceInstanceFieldCheck extends IssuableSubscriptionVisitor
          
          private static boolean isSpringService(ClassTree tree) {
                  tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
+                 tree.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
                  return true;
                  
         }
 
+         protected void scan(@Nullable Tree tree) {
+                   if (tree != null) {
+                   }
+                 }
 
 }
index d34c92f..a00c662 100644 (file)
@@ -10,7 +10,7 @@ public class CustomSensor implements Sensor {
        @Override
        public void describe(SensorDescriptor descriptor) {
            descriptor.onlyOnLanguage(Java.KEY);
-           descriptor.name("Custom Sensor");
+           descriptor.name("Custom Java Sensor");
        }
 
        @Override
diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.html b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.html
deleted file mode 100644 (file)
index ab6882f..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<p>Custom 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> - You are doing wrong!!! </li>
-</ul>
-
diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.json b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.json
deleted file mode 100644 (file)
index eadcd7a..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "title": "Custom SonarQube rule",
-  "status": "ready",
-  "remediation": {
-    "func": "Constant\/Issue",
-    "constantCost": "5min"
-  },
-  "tags": [
-    "bad-practice"
-  ],
-  "defaultSeverity": "Major"
-}
diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.html b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.html
new file mode 100644 (file)
index 0000000..ab6882f
--- /dev/null
@@ -0,0 +1,18 @@
+<p>Custom 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> - You are doing wrong!!! </li>
+</ul>
+
diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.json b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.json
new file mode 100644 (file)
index 0000000..eadcd7a
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "title": "Custom SonarQube rule",
+  "status": "ready",
+  "remediation": {
+    "func": "Constant\/Issue",
+    "constantCost": "5min"
+  },
+  "tags": [
+    "bad-practice"
+  ],
+  "defaultSeverity": "Major"
+}
index aab3549..8b3c478 100644 (file)
@@ -6,7 +6,7 @@ import org.sonar.java.checks.verifier.JavaCheckVerifier;
 public class SpringServiceInstanceFieldCheckTest {
          private static final String FILENAME = "src/test/files/checks/SpringServiceInstanceFieldCheck.java";
 
-         //@Test
+         @Test
          public void test() {
            JavaCheckVerifier.verify(FILENAME, new SpringServiceInstanceFieldCheck());
          }