From: Gustavo Martin Morcuende Date: Thu, 4 Aug 2016 18:58:02 +0000 (+0200) Subject: Sonarqube simple rule: missing required CheckRegistrar X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=356d640ff7e658195081010a0e7525fd33050b1f;p=JavaForFun Sonarqube simple rule: missing required CheckRegistrar --- 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 673e836..226f174 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 @@ -14,14 +14,31 @@ public final class CheckList { } public static List getChecks() { - return ImmutableList.builder().addAll(getJavaChecks()) + return ImmutableList.builder() + .addAll(getJavaChecks()) + .addAll(getJavaTestChecks()) + .addAll(getXmlChecks()) .build(); } - public static List> getJavaChecks() { - return ImmutableList.>builder() - .add(HelloWorldCheck.class) - .build(); - } + public static List> getJavaChecks() { + return ImmutableList.>builder() + .add(HelloWorldCheck.class) + .build(); + } + + public static List> getJavaTestChecks() { + return ImmutableList.>builder() + .build(); + } + public static List> getXmlChecks() { + return ImmutableList.>builder() + .build(); + } + + private static List> getMavenChecks() { + return ImmutableList.>builder() + .build(); + } } 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 554b672..3d4f2e2 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 @@ -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 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) { diff --git a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldPlugin.java b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldPlugin.java index b8edfcd..1c431ac 100644 --- a/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldPlugin.java +++ b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldPlugin.java @@ -12,8 +12,9 @@ public class HelloWorldPlugin implements Plugin { ImmutableList.Builder 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 index 0000000..c8e3700 --- /dev/null +++ b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldRulesCheckRegistrar.java @@ -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 index 0000000..4019e1b --- /dev/null +++ b/Sonar/Plugins/hello-world-plugin/src/main/java/de/example/plugins/helloworld/HelloWorldSensor.java @@ -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) { + + } + +}