Unable to add rules and implement the issues on the same

643 views
Skip to first unread message

shruthisa...@gmail.com

unread,
Sep 14, 2015, 5:30:05 AM9/14/15
to SonarQube
Hi,

I have a requirement of adding new rules into the SonarQube and implement it in my source code and raise issues for the same. I am following the procedure in the below link:

I have also downloaded the sample plugin from the below link and gone through the steps;

But from the plugin i downloaded, I see the rules coded in path\plugins\java-custom-rules\src\main\java\org\sonar\samples\java are not shown in the Rules tab.
Also, the issues for these particular rules are not shown in the dashboard for the project.

Here is the Snapshot of issues of the same project:


As seen in the above snapshot, all these issues are existing ones and not the ones we coded. 

Is there any other way to add rules or am I following the correct procedure. There is no clear documentation about this anywhere.
If there is any other method other than this can anyone please let me know. Or if any changes to be made in the above step please let me know.

Also, I am able to create rules in UI. But not able to add to JAVA coding guidelines.
 I have followed the below link for this,
Is there any procedure to link these rules with the code?

Can anyone help me with this issue?

Thanks,
Shruthi

Michael Gumowski

unread,
Sep 14, 2015, 6:00:05 AM9/14/15
to shruthisa...@gmail.com, SonarQube
Hello Shruthi,

Not sure to understand your issue. According to the screenshot you provided, I supposed that you used the sample java custom-rule plugin, and analyzed the sample project.
What version of SQ and java plugin are you using?

Did you actually activated any of the custom rules before running the analysis (they are in the "Connexis" repository)?

You should have first activated them:


Which would have created the following issues:



Now, are you sure you correctly registered your rule in your registrar?

Regards,


Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/07f6726a-4b68-4f97-a162-66cab99f1eba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shruthi Sathyanarayana

unread,
Sep 14, 2015, 6:06:56 AM9/14/15
to SonarQube
Hello Michael,

Yes you are right. I used simple java custom-rule plugin. In that folder there are many rules like Avoid Annotation,  Avoid using methods etc. So my question is, if i search for issues of this project in the dashboard, the above mentioned rules are not displaying even if there are existing issues in the source code. How can I place those rules so that, it will show up as an issue in the dashboard. Please help me.

Thanks, 
Shruthi
 

Shruthi Sathyanarayana

unread,
Sep 14, 2015, 6:10:40 AM9/14/15
to SonarQube
Hi Micheal,

When i try to search for "Connexis" repository, it is saying as no match found. How do I add this "Connexis" into the repository. Is there any procedure for that.

Michael Gumowski

unread,
Sep 14, 2015, 7:29:33 AM9/14/15
to Shruthi Sathyanarayana, SonarQube
Please provide your java environment version, as well as the SonarQube and java plugin versions.

Just to be sure... Let me know if I'm wrong in the procedure I assume you followed.

You have:

- A SQ platform up and running (which version?)
- The java plugin installed (obviously... but with which version?)
- The java custom rules plugin installed (java-custom-rules-1.0-SNAPSHOT.jar build from the sample project: https://github.com/SonarSource/sonar-examples/tree/master/plugins/java-custom-rules) in your SQ extensions directory (sonarqube\extensions\plugins)
- You correctly restarted your SQ platform after the installation of the custom rules plugin.

Now:
- You didn't changed anything yet in the java custom rules plugin and you just want to check the rules.
- You can't find any repository called "Connexis" in the list of repositories, so you can't activate the custom rules.

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

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

Shruthi Sathyanarayana

unread,
Sep 14, 2015, 8:34:25 AM9/14/15
to SonarQube
Hi Michael,

Thank you for your reply. I have SQ version 5.1.2 and Java plug-in version 3.0. 
But I haven't installed java-custom-rules-1.0-SNAPSHOT.jar. Is there any particular procedure to follow for this step? As this repository called "Connexis" is not in my list. It will be helpful to me if you tell the procedure to me step by step. 

Thanks,
Shruthi

Michael Gumowski

unread,
Sep 14, 2015, 8:45:30 AM9/14/15
to Shruthi Sathyanarayana, SonarQube
Hi,

As you can (and should have) read in the documentation, you need at least version 3.1 of the java plugin in order to use custom rules (http://docs.sonarqube.org/display/DEV/Custom+Rules+for+Java). Your current configuration is therefore not compatible.

Now, without installing the custom rules, how do you want to access these rules? Please follow (and search) the documentation: http://docs.sonarqube.org/display/DEV/Writing+Custom+Rules+using+Java

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

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

Shruthi Sathyanarayana

unread,
Sep 15, 2015, 1:22:00 AM9/15/15
to SonarQube
Hi Micheal,

I have updated the sonar-java-plugin 3.0 to sonar-java-plugin 3.5. I restarted the server and and Analyzed the sample project provided in the website. But still I see that no rules have appeared as issues on the dashboard.  After updating the java plugin, is there any other step I need to follow?  In the below link:
I din't understand the point 
  • Put a dependency on the jar of the language plugin for which you are writing custom rules.
There is no clear procedure mentioned anywhere. Or maybe the answer is there only but I am not able to find it. I am new to SQ. So, please bear with me and please help me.
Thank you for your help in advance.

Shruthi

Michel Pawlak

unread,
Sep 15, 2015, 4:54:54 AM9/15/15
to SonarQube
Shruthi.

You need to :

0) write your custom plugin, test it, "mvn clean install" it
1) stop your SQ server,
2) make sure that all your jars (including your custom jars) are in SONAR_INSTALL_DIR/extensions/plugins
3) make sure that you don't have 2 versions of the same jar in SONAR_INSTALL_DIR/extensions/plugins
4) delete SONAR_INSTALL_DIR/data/es (just to make sure that you avoid some issues)
5) restart your SQ server
6) check that nothing suspect appears in your SONAR_INSTALL_DIR/logs/sonar.log 
7) log in as admin
8) modify quality profiles in order to add your custom checks to your active profile (if any)
9) modify your dashboard to add the widgets you want to add (if any)
10) check your browser's error console for errors (if you added widgets)
11) then (and only then) run an analysis
12) check that nothing suspect appears in your SONAR_INSTALL_DIR/logs/sonar.log 
13) reload the web page
14) check your browser's error console for errors (if you added widgets that may have been updated by the analysis)

Have you followed all theses steps ?

Concerning the point "put a dependency on the jar" it's a configuration option of the sonar-plugin maven packaging plugin. It's not mandatory, but it allows you to stop server startup if a plugin dependency is missing (read the documentation, it's really well documented)

Michel

Shruthi Sathyanarayana

unread,
Sep 15, 2015, 5:05:58 AM9/15/15
to SonarQube
Hi Michel,

Thank you so much for the steps.
But I have one doubt here. In point no. 2 you have mentioned "custom jars". I understand I need to add all the java-custom-rules in a jar. How to do that? Can you please help me?

Thanks,
Shruthi

Michel Pawlak

unread,
Sep 15, 2015, 5:29:04 AM9/15/15
to SonarQube
Well, no I can't. 

Read the documentation prior to coding : http://docs.sonarqube.org/display/DEV/Coding+a+Plugin everything is explained there.

Michel

Shruthi Sathyanarayana

unread,
Sep 21, 2015, 1:09:42 AM9/21/15
to SonarQube
Hello,

I have followed the above steps and placed the jar in SONAR_HOME\extensions\plugins. I restarted SQ server and found the 3 rules in "My Java Rules" repository. Please see the below screenshot:

Now, when i try to run an analysis, I am getting the following error,
07:27:29.812 INFO  - Quality profile for java: Sonar way
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 6.397s
Final Memory: 11M/65M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: org.sonar.plugins.java.api.CheckRegistrar$RegistrarContext.reg
isterClassesForRepository(Ljava/lang/String;Ljava/lang/Iterable;)V
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with t
he -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

Please see the below screenshot :

Can anyone please tell me what went wrong?

Thanks in advance.
Shruthi.

Michael Gumowski

unread,
Sep 21, 2015, 2:38:48 AM9/21/15
to Shruthi Sathyanarayana, SonarQube
Can you please execute sonar runer with the -X option and provide the full execution trace.

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

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

Shruthi Sathyanarayana

unread,
Sep 21, 2015, 2:51:41 AM9/21/15
to SonarQube
Hi Michael,

Here is the full trace of execution.

 key batch-org.sonarqube:java-sonar-runner-simple
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 10.940s
Final Memory: 10M/64M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:91)
        at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
        at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
        at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102
)
        at org.sonar.runner.api.Runner.execute(Runner.java:100)
        at org.sonar.runner.Main.executeTask(Main.java:70)
        at org.sonar.runner.Main.execute(Main.java:59)
        at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.NoSuchMethodError: org.sonar.plugins.java.api.CheckRegistra
r$RegistrarContext.registerClassesForRepository(Ljava/lang/String;Ljava/lang/Ite
rable;)V
        at org.sonar.samples.java.MyJavaFileCheckRegistrar.register(MyJavaFileCh
eckRegistrar.java:22)
        at org.sonar.java.SonarComponents.<init>(SonarComponents.java:76)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at org.picocontainer.injectors.AbstractInjector.newInstance(AbstractInje
ctor.java:145)
        at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInje
ctor.java:342)
        at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDepende
ncyGuard.observe(AbstractInjector.java:270)
        at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(
ConstructorInjector.java:364)
        at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter
.getComponentInstance(AbstractInjectionFactory.java:56)
        at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(Abs
tractBehavior.java:64)
        at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:9
1)
        at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContain
er.java:698)
        at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContai
ner.java:646)
        at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContai
ner.java:631)
        at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstanc
e(BasicComponentParameter.java:118)
        at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(Com
ponentParameter.java:136)
        at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleM
emberInjector.java:78)
        at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getPa
rameterArguments(ConstructorInjector.java:309)
        at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInje
ctor.java:335)
        at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDepende
ncyGuard.observe(AbstractInjector.java:270)
        at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(
ConstructorInjector.java:364)
        at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter
.getComponentInstance(AbstractInjectionFactory.java:56)
        at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(Abs
tractBehavior.java:64)
        at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:9
1)
        at org.picocontainer.DefaultPicoContainer.getLocalInstance(DefaultPicoCo
ntainer.java:605)
        at org.picocontainer.DefaultPicoContainer.getComponents(DefaultPicoConta
iner.java:586)
        at org.sonar.api.platform.ComponentContainer.getComponentsByType(Compone
ntContainer.java:217)
        at org.sonar.batch.bootstrap.BatchExtensionDictionnary.completeBatchExte
nsions(BatchExtensionDictionnary.java:119)
        at org.sonar.batch.bootstrap.BatchExtensionDictionnary.getExtensions(Bat
chExtensionDictionnary.java:113)
        at org.sonar.batch.bootstrap.BatchExtensionDictionnary.getFilteredExtens
ions(BatchExtensionDictionnary.java:91)
        at org.sonar.batch.bootstrap.BatchExtensionDictionnary.select(BatchExten
sionDictionnary.java:68)
        at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:4
7)
        at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseMode
PhaseExecutor.java:120)
        at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanConta
iner.java:264)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
        at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.j
ava:235)
        at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScan
Container.java:230)
        at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanCon
tainer.java:220)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
        at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57)
        at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
        at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.ja
va:135)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
        at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer
.java:158)
        at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
        at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java
:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:87)
        ... 9 more

Thanks,
Shruthi

Michael Gumowski

unread,
Sep 21, 2015, 3:50:01 AM9/21/15
to Shruthi Sathyanarayana, SonarQube
It seems that you are using two different versions of the java plugin, resulting with conflict between current and old API. I guess the version installed

Please verify that the version of the java plugin installed in your "SONAR_HOME\extensions\plugins" folder is the same as the one used in the dependency of your custom plugin (see pom.xml dependency of org.sonarsource.java.sonar-java-plugin). From what I have previously read, you should have for both the 3.5 version.

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

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

Shruthi Sathyanarayana

unread,
Sep 22, 2015, 12:56:04 AM9/22/15
to SonarQube
Hi Michael,

It is working fine now. Thank you so much for your support:)

Shruthi.

shruti namdeo

unread,
Dec 11, 2015, 7:15:37 AM12/11/15
to SonarQube
Hi Micheal and Shruthi,

I am also facing this xact same issue.I am using java plugin 3.6.jar and sonarqube ver 5.2.

Please tell me how can i see rules on this version 

Br,
Shruti

pio...@gmail.com

unread,
Dec 11, 2015, 7:46:56 AM12/11/15
to SonarQube
Hi,

I am also facing the same issue. I've tried different alternatives but not able to solve the issue. The last I tried was to change the default H2 Database to a Postgres Database but still no issues are been reported on the web interface and they are not inserted in the database either.

Any help whould be appreciated.

srinivas...@gmail.com

unread,
Jun 15, 2017, 1:16:36 PM6/15/17
to SonarQube
Hi Michel,

How to write a custom rule and create a jar install it in sonarqube.

Can u explain the steps because the URLs which you mentioned in the discussion is not available.

Thanks

G. Ann Campbell

unread,
Jun 15, 2017, 2:01:38 PM6/15/17
to SonarQube, srinivas...@gmail.com
Hi,



Ann

P.S. This thread is rather old. It would have been better to start a new one. :-)
Reply all
Reply to author
Forward
0 new messages