Sonar Java Custom Template Technical Debt Annotation

183 views
Skip to first unread message

martinc...@gmail.com

unread,
Jun 9, 2016, 4:53:26 PM6/9/16
to SonarQube
Hello everybody,

I created a custom java rule based on the 101 Tutorial "java-custom-rules-template". I'm trying to add the technical debt information with 

@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.ARCHITECTURE_CHANGEABILITY)

@SqaleConstantRemediation("10min")


But the UI doesn't show the information. 

Is there anything else I should do to make it work? If I add the custom rules from the sonar-example-plugin-java-custom-rules the UI actually shows the technical debt for each rule. I've tried comparing the projects but I don't see a difference that could be the root of the problem.


Thanks!

Michael Gumowski

unread,
Jun 10, 2016, 12:26:29 PM6/10/16
to martinc...@gmail.com, SonarQube
Hey Martin,

If you only rely on what is discussed in the tutorial, SQALE metadata provided using annotations won't be taken into account when your rules are loaded.
In order to handle these extra metadata (sub-characteristics and remediation time), you have two approaches:
  • The recommended approach is to place the metadata in an extra, dedicated file, in whatever format you want to use (CSV, JSON, XML, properties, ...) and load them when creating the rule definitions. This approach is used by the Java Analyzer. It is however not yet documented in the tutorial. If you want to see how it is done with the Java Analyzer, just look there: JavaRulesDefinition.java
  • The other approach is to annotate your rule with SQALE annotations, like you did. However, you will have to change the way rules are loaded in the rule definition class (java-custom-rules-template/.../JavaCustomRulesDefinition.java) in order to correctly get the metadata from these annotations. You may want to use the same approach described in the example project (java-custom-rules/.../MyJavaRulesDefinition.java). Unfortunately, with this approach you introduce a dependency on sslr-squid-bridge. This dependency is already part of the template project (as you can see in the pom file), but is currently not used. It will soon be removed from the pom file of the tutorial.
Cheers,

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/5dc27171-a1ed-4c38-94ad-6093f3f78f3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Cabello

unread,
Jun 10, 2016, 12:42:21 PM6/10/16
to Michael Gumowski, SonarQube
Hey! Thanks for the quick reply!

What I ended up doing was 
1.- Placing my custom rule file in the example project
2.- Building the maven project for the example project.
3.- Running sonar with the new .jar created.

I didn’t really like the solution because I wasn’t sure if the problem actually was in the way rules were being loaded. 
This might be a very basic question but, what are the drawbacks of having the dependency on ssl-squid-bridge? I ask this because I believe I will not be able to use the recommended approach.

Thanks, again!
Reply all
Reply to author
Forward
0 new messages