Sonarlint for Eclipse not reporting issues on custom java rules

1,256 views
Skip to first unread message

gnir...@gmail.com

unread,
Jun 13, 2016, 8:08:22 AM6/13/16
to SonarLint
Hi Team,

We started using SonarQube in our team, we needed some custom rules for Java so we implemented them following the guide here (http://docs.sonarqube.org/display/PLUG/Writing+Custom+Java+Rules+101). It is working fine when we use sonar scanner, issues are reported based on these custom rules in the dashboard. However when we use the sonarlint plugin for eclipse we do not see these warning on the IDE, only the default warnings are reported. Is this by design or are we doing something wrong?

Thanks,
Nirujan

Julien HENRY

unread,
Jun 13, 2016, 8:16:03 AM6/13/16
to gnir...@gmail.com, SonarLint
Hi Nirujan,

This is a current limitation we are working on.

++

Julien

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/7028a9ce-b438-421a-b207-d8850e42c849%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

petrj...@gmail.com

unread,
Aug 23, 2016, 6:36:10 AM8/23/16
to SonarLint, gnir...@gmail.com
Hi Julien

My custom rule violation is not show in Eclipse. I have updated sonar products to versions mentioned in items involved in MMF-248.
SonarQube 6.0
SonarLint for Eclipse 2.2.0 (includes Sonarlint core 2.4.0)
Eclipse Neon 4.6.0

The custom rule (from 101 tutorial) is visible in Sonar server. I have added this rule to a profile. Maven sonar:sonar reports custom rule violation on my sample project.

In Eclipse the same project is correctly bound to the profile. Violations of standard rules from the profile are visible, but the custom rule is never violated.

Eclipse log does not contain any exceptions or related messages. The plugin jar file is downloaded to ${USERHOME}\.sonarlint\plugins\{randomid}\java-custom-rules-template-1.0-SNAPSHOT.jar and contained libraries are unpacked.

Plugin manifest contains:
Sonar-Version: 6.0.0
SonarLint-Supported: true

I have followed the same custom plugin tutorial mentioned by Nirujan, but I had to tweak a few steps to make everything work. Maybe I have made something wrong in this part.

Regards
Petr

Julien HENRY

unread,
Aug 24, 2016, 3:36:45 AM8/24/16
to petrj...@gmail.com, SonarLint
Hi Petr,

Thanks for testing this feature. We still need to cleanup things and publish an official documentation.

I don't see any obvious mistake in what you did. Could you please enable verbose output in SonarLint console, and then go to SonarQube server view and right click -> "Update all project bindings" on your server. This should log "enabled" plugins and you can see if your custom plugin is loaded or not.

On my side I get:

Plugin github is not compatible with SonarLint. Skip it.
Plugin scmsvn is not compatible with SonarLint. Skip it.
Plugin csharp is not compatible with SonarLint. Skip it.
Plugin groovy is not compatible with SonarLint. Skip it.
Download plugin sonar-java-plugin-4.2-build6590.jar to /home/julien/.sonarlint/plugins/_tmp/261153808192380208.tmp
Create : /home/julien/.sonarlint/plugins/ed6c639467dbd8f4385568462d9381f8
Plugin ldap is not compatible with SonarLint. Skip it.
Plugin scmgit is not compatible with SonarLint. Skip it.
Plugin genericcoverage is not compatible with SonarLint. Skip it.
[...]
Load plugins
Load plugins (done) | time=0ms
Plugins:
  * JavaScript 2.15-build2729 (javascript)
  * Java 4.2-build6590 (java)
Using storage for server 'dory' (last update 24/08/16 09:32)

++

Julien

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/5fd482ba-a6ad-4bd4-a001-32342ec61e3c%40googlegroups.com.

petr....@wallstreetsystems.com

unread,
Aug 24, 2016, 5:21:24 AM8/24/16
to SonarLint, petrj...@gmail.com
Hi Julien

Here is output of the "Update all project bindings" action:

Create : {MYUSERHOME}\.sonarlint\plugins
Plugin cache: {MYUSERHOME}\.sonarlint\plugins
Create : {MYUSERHOME}\.sonarlint\plugins\_tmp
GET 200 http://localhost:9000/api/system/status | time=43ms
GET 200 http://localhost:9000/api/properties?format=json | time=54ms
GET 200 http://localhost:9000/deploy/plugins/index.txt | time=5ms

Plugin csharp is not compatible with SonarLint. Skip it.
Download plugin sonar-java-plugin-4.0.jar to {MYUSERHOME}\.sonarlint\plugins\_tmp\1846434254736442283.tmp
GET 200 http://localhost:9000/deploy/plugins/java/sonar-java-plugin-4.0.jar | time=19ms
Create : {MYUSERHOME}\.sonarlint\plugins\de15554d72648a16048d2a4d87df64c3

Plugin scmgit is not compatible with SonarLint. Skip it.
Download plugin java-custom-rules-template-1.0-SNAPSHOT.jar to {MYUSERHOME}\.sonarlint\plugins\_tmp\3826946844210096711.tmp
GET 200 http://localhost:9000/deploy/plugins/javacustomrulestemplate/java-custom-rules-template-1.0-SNAPSHOT.jar | time=4ms

Create : {MYUSERHOME}\.sonarlint\plugins\3324e8743c50a59c1504230c1ea59b90

Plugin scmsvn is not compatible with SonarLint. Skip it.
Download plugin sonar-javascript-plugin-2.14.jar to {MYUSERHOME}\.sonarlint\plugins\_tmp\8185119548389972210.tmp
GET 200 http://localhost:9000/deploy/plugins/javascript/sonar-javascript-plugin-2.14.jar | time=70ms
Create : {MYUSERHOME}\.sonarlint\plugins\946ba9ca384b000e94008da1797e3984
GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,htmlDesc,internalKey,isTemplate,templateKey,actives&statuses=BETA,DEPRECATED,READY&p=1&ps=500 | time=145ms
GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,htmlDesc,internalKey,isTemplate,templateKey,actives&statuses=BETA,DEPRECATED,READY&p=2&ps=500 | time=140ms
GET 200 http://localhost:9000/api/qualityprofiles/search.protobuf | time=26ms
GET 200 http://localhost:9000/api/projects/index?format=json&subprojects=true | time=27ms
Create : {MYUSERHOME}\.sonarlint\plugins
Plugin cache: {MYUSERHOME}\.sonarlint\plugins
Create : {MYUSERHOME}\.sonarlint\plugins\_tmp
Load plugins
Load plugins (done) | time=9ms
Plugins:
  * Java 4.0 (java)
  * JavaScript 2.14 (javascript)
  * Java Custom Rules - Template 1.0-SNAPSHOT (javacustomrulestemplate)
Using storage for server 'localhost' (last update 8/24/16 10:09 AM)

The plugin is downloaded and dependencies unpacked. There are no problems reported later during source code analysis.

Petr

Julien HENRY

unread,
Aug 24, 2016, 5:26:34 AM8/24/16
to petr....@wallstreetsystems.com, SonarLint, Petr Janata
Can you try to annotate the class in your custom plugin that implements CheckRegistrar with @SonarLintSide?

Then rebuild your plugin, install it in your SQ server, and execute "Update all project bindings" in SonarLint.

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.

petr....@wallstreetsystems.com

unread,
Aug 24, 2016, 7:37:48 AM8/24/16
to SonarLint, petr....@wallstreetsystems.com, petrj...@gmail.com
Perfect, the @SonarLintSide annotation on CheckRegistrar solved the problem.
Now I can see my custom validations in Eclipse.

Thanks a lot
Petr

Btw. The sonar-packaging-maven-plugin produces some unnecessary maven internal libraries in META-INF/lib of sonar plugin it produces. These libs cause no problem but are just a 1MB of junk. META-INF\lib\maven-*.jar,plexus*,classworlds*. This could be caused by hardcoded "org.codehaus.sonar" string in SonarPluginMojo which handles dependecies to copy.

Also I have made some tiny changes to the 101 tutorial custom plugin pom.xml to make everything work:

diff --git a/plugins/tutorial/java-custom-rules-template/pom.xml b/plugins/tutorial/java-custom-rules-template/pom.xml
index
469f4d7..4b2c474 100644
--- a/plugins/tutorial/java-custom-rules-template/pom.xml
+++ b/plugins/tutorial/java-custom-rules-template/pom.xml
@@ -9,16 +9,23 @@
   
<packaging>sonar-plugin</packaging>
 
   <properties>
-    <sonar.plugin.api.version>4.5.7</
sonar.plugin.api.version>
-    <java.plugin.version>3.13.1</java.plugin.version>
+    <sonar.plugin.api.version>6.0</
sonar.plugin.api.version>
+    <java.plugin.version>4.1</java.plugin.version>
   </
properties>
 
   
<name>Java Custom Rules - Template</name>
   <description>Empty template for custom rules</
description>
 
   
<dependencies>
+  
     
<dependency>
-      <groupId>org.codehaus.sonar</groupId>
+      <groupId>com.google.guava</
groupId>
+      <artifactId>guava</artifactId>
+      <version>19.0</
version>
+    </dependency>
+  
+    <dependency>
+      <groupId>org.sonarsource.sonarqube</
groupId>
       
<artifactId>sonar-plugin-api</artifactId>
       <version>${sonar.plugin.api.version}</
version>
       
<scope>provided</scope>
@@ -36,18 +43,6 @@
       <groupId>org.sonarsource.java</
groupId>
       
<artifactId>java-frontend</artifactId>
       <version>${java.plugin.version}</
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>
-      </
exclusions>
     
</dependency>
 
     <dependency>
@@ -81,6 +76,12 @@
       <version>0.9.30</
version>
       
<scope>test</scope>
     </
dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</
artifactId>
+      <version>1.6.2</version>
+      <scope>test</
scope>
+    </dependency>
   </
dependencies>
 
   
<build>
@@ -88,10 +89,11 @@
       
<plugin>
         
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
         <artifactId>sonar-packaging-maven-plugin</
artifactId>
-        <version>1.15</version>
+        <version>1.17</
version>
         
<extensions>true</extensions>
         <configuration>
           <pluginClass>org.sonar.template.java.JavaCustomRulesPlugin</
pluginClass>
+          <sonarLintSupported>true</sonarLintSupported>
         </
configuration>
       
</plugin>

Julien HENRY

unread,
Aug 24, 2016, 8:02:53 AM8/24/16
to petr....@wallstreetsystems.com, SonarLint, Petr Janata
Thanks for the feedback. As I said documentation is not updated. We will add @SonarLintSide annotation directly on CheckRegistrar in a future release of the Java plugin so that it make things simpler for other people writing custom Java rules plugins.

++

Julien

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages