From: Gustavo Martin Morcuende Date: Sun, 7 Aug 2016 22:51:20 +0000 (+0200) Subject: no time for comments X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=1626541b95d3878a047e437c360b40679c784b09;p=JavaForFun no time for comments --- diff --git a/Sonar/Plugins/sonar-custom-java-plugin/pom.xml b/Sonar/Plugins/sonar-custom-java-plugin/pom.xml index 1b83a66..3f10d86 100644 --- a/Sonar/Plugins/sonar-custom-java-plugin/pom.xml +++ b/Sonar/Plugins/sonar-custom-java-plugin/pom.xml @@ -29,7 +29,7 @@ ${sonar.apiVersion} provided - + org.sonarsource.java sonar-java-plugin sonar-plugin diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/ParameterCheck.java b/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/ParameterCheck.java index a5ed7b8..914d345 100644 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/ParameterCheck.java +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/ParameterCheck.java @@ -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); diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheck.java b/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheck.java index c3fc929..f9d5c29 100644 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheck.java +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheck.java @@ -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) { + } + } } diff --git a/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/plugins/custom/java/CustomSensor.java b/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/plugins/custom/java/CustomSensor.java index d34c92f..a00c662 100644 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/plugins/custom/java/CustomSensor.java +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/main/java/de/example/plugins/custom/java/CustomSensor.java @@ -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/Custom_profile.json b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/Custom_profile.json index c110c1a..e4debbe 100644 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/Custom_profile.json +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/Custom_profile.json @@ -1,7 +1,7 @@ { "name": "Custom profile", "ruleKeys": [ - "GU0001", - "GU0002" + "GUJ0001", + "GUJ0002" ] } 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 index ab6882f..0000000 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.html +++ /dev/null @@ -1,18 +0,0 @@ -

Custom rule description.

-

Noncompliant Code Example

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

See

- - 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 index eadcd7a..0000000 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GU0001_java.json +++ /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 index 0000000..ab6882f --- /dev/null +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.html @@ -0,0 +1,18 @@ +

Custom rule description.

+

Noncompliant Code Example

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

See

+ + 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 index 0000000..eadcd7a --- /dev/null +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/main/resources/de/example/l10n/java/rules/custom/GUJ0001_java.json @@ -0,0 +1,12 @@ +{ + "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/test/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheckTest.java b/Sonar/Plugins/sonar-custom-java-plugin/src/test/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheckTest.java index aab3549..8b3c478 100644 --- a/Sonar/Plugins/sonar-custom-java-plugin/src/test/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheckTest.java +++ b/Sonar/Plugins/sonar-custom-java-plugin/src/test/java/de/example/custom/java/checks/SpringServiceInstanceFieldCheckTest.java @@ -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()); }