Sonarqube simple rule: missing required CheckRegistrar
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 4 Aug 2016 18:58:02 +0000 (20:58 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 4 Aug 2016 18:58:02 +0000 (20:58 +0200)
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/HelloWorldPlugin.java
Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesCheckRegistrar.java [new file with mode: 0644]
Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldSensor.java [new file with mode: 0644]

index 673e836..226f174 100644 (file)
@@ -14,14 +14,31 @@ public final class CheckList {
        }
 
        public static List<Class> getChecks() {
-               return ImmutableList.<Class>builder().addAll(getJavaChecks())
+               return ImmutableList.<Class>builder()
+                               .addAll(getJavaChecks())
+                               .addAll(getJavaTestChecks())
+                               .addAll(getXmlChecks())
                                .build();
        }
 
-         public static List<Class<? extends JavaCheck>> getJavaChecks() {
-                   return ImmutableList.<Class<? extends JavaCheck>>builder()
-                     .add(HelloWorldCheck.class)
-                     .build();
-         }
+       public static List<Class<? extends JavaCheck>> getJavaChecks() {
+               return ImmutableList.<Class<? extends JavaCheck>>builder()
+                               .add(HelloWorldCheck.class)
+                               .build();
+       }
+
+       public static List<Class<? extends JavaCheck>> getJavaTestChecks() {
+               return ImmutableList.<Class<? extends JavaCheck>>builder()
+                               .build();
+       }
 
+       public static List<Class<? extends JavaCheck>> getXmlChecks() {
+               return ImmutableList.<Class<? extends JavaCheck>>builder()
+                               .build();
+       }
+
+       private static List<Class<? extends JavaCheck>> getMavenChecks() {
+               return ImmutableList.<Class<? extends JavaCheck>>builder()
+                               .build();
+       }
 }
index 554b672..3d4f2e2 100644 (file)
@@ -2,6 +2,8 @@ package de.example.helloworld.checks;
 
 import java.util.List;
 
+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.semantic.Symbol.MethodSymbol;
@@ -14,6 +16,8 @@ import com.google.common.collect.ImmutableList;
 
 @Rule(key = "HELLOWORLD0001")
 public class HelloWorldCheck extends IssuableSubscriptionVisitor {
+       private static final Logger LOG = Loggers.get(HelloWorldCheck.class);
+
 
        @Override
        public List<Kind> nodesToVisit() {
@@ -22,6 +26,8 @@ public class HelloWorldCheck extends IssuableSubscriptionVisitor {
 
        @Override
        public void visitNode(Tree tree) {
+               LOG.info("Visiting Node");
+
                MethodTree method = (MethodTree) tree;
                
                if (method.parameters().size() == 1) {
index b8edfcd..1c431ac 100644 (file)
@@ -12,8 +12,9 @@ public class HelloWorldPlugin implements Plugin {
     
     ImmutableList.Builder<Object> builder = ImmutableList.builder();
     builder.add(
-      HelloWorldRulesDefinition.class);
+               HelloWorldRulesDefinition.class,
+               HelloWorldRulesCheckRegistrar.class);
+    
     context.addExtensions(builder.build());
-
   }
 }
diff --git a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesCheckRegistrar.java b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesCheckRegistrar.java
new file mode 100644 (file)
index 0000000..c8e3700
--- /dev/null
@@ -0,0 +1,14 @@
+package de.example.plugins.helloworld;
+
+import org.sonar.plugins.java.api.CheckRegistrar;
+
+import de.example.helloworld.checks.CheckList;
+
+public class HelloWorldRulesCheckRegistrar implements CheckRegistrar {
+
+       @Override
+       public void register(RegistrarContext registrarContext) {
+           registrarContext.registerClassesForRepository(CheckList.REPOSITORY_KEY, CheckList.getJavaChecks(), CheckList.getJavaTestChecks());  
+       }
+
+}
diff --git a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldSensor.java b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldSensor.java
new file mode 100644 (file)
index 0000000..4019e1b
--- /dev/null
@@ -0,0 +1,21 @@
+package de.example.plugins.helloworld;
+
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.plugins.java.Java;
+
+public class HelloWorldSensor implements Sensor {
+
+       @Override
+       public void describe(SensorDescriptor descriptor) {
+           descriptor.onlyOnLanguage(Java.KEY);
+           descriptor.name("HelloWorld Sensor");
+       }
+
+       @Override
+       public void execute(SensorContext context) {
+               
+       }
+
+}