
{"id":1627,"date":"2015-05-04T10:30:41","date_gmt":"2015-05-04T10:30:41","guid":{"rendered":"http:\/\/www.codergears.com\/Blog\/?p=1627"},"modified":"2016-05-17T15:59:57","modified_gmt":"2016-05-17T15:59:57","slug":"cc-sonarqube-plugin-based-on-clang-is-out","status":"publish","type":"post","link":"https:\/\/codergears.com\/Blog\/?p=1627","title":{"rendered":"C\/C++ SonarQube plugin based on Clang"},"content":{"rendered":"<p>The big challenge to develop a sonarqube plugin for C\/C++ is to use the good parser, producing a parser for such a grammar is much harder. \u00a0What makes C++ really hard is certain rules relating to declarations\/definitions, name lookup (consider argument-dependent name lookup) implicit conversion rules, and of course the resolution of templates.<!--more--><\/p>\n<p style=\"color: #111111;\"><span style=\"color: #555555;\">It\u2019s proven now that Clang is a mature compiler For C and C++ like GCC and Microsoft compilers, but what makes it special is the fact that it\u2019s not just a compiler. It\u2019s also an infrastructure to build tools. Thanks to its\u00a0library based architecture: which makes the reuse and the integration of the provided functionality more flexible\u00a0and easier to integrate into other projects. Thus, Clang\u00a0\u00a0is the good candidate to develop a C\/C++ sonar plug in.<\/span><\/p>\n<p style=\"color: #111111;\">The <a href=\"http:\/\/cppdepend.com\/sonarplugin\">C\/C++ SonarQube plugin<\/a> based on Clang and CppDepend is\u00a0free for open source contributors and for universities.<\/p>\n<p style=\"color: #111111;\"><strong>Plugin Features<\/strong><\/p>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">Standard metrics:<\/span>\u00a0<\/span><\/span>\n<p style=\"color: #555555;\">There are many ways to measure a code base. The most common way is to count the number of lines of code. This metric gives a rough estimation of the effort that had been put in to develop the code base. It also allows you obtain a quality level agreement by pinpointing fat methods and classes.<\/p>\n<p style=\"color: #555555;\">The plugin counts the number of lines of code. It also comes with other standard code metrics. Some of them are related to your code organization (the number of classes or namespaces, the number of methods declared in a class&#8230;), some of them are related to the code quality (complexity, percentage of comments, issues,&#8230;).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar11.png\" alt=\"\" width=\"613\" height=\"489\" \/><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">Code duplication:<\/span>\u00a0The duplications are detected by the CPD tool embedded in sonarqube.<img loading=\"lazy\" decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar13.png\" alt=\"\" width=\"620\" height=\"143\" \/><\/span><\/li>\n<\/ul>\n<\/div>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">Coverage:<\/span>\u00a0The plugin load the coverage result from Cobertura and Microsoft Visual Studio XML result files.<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar12.png\" alt=\"\" \/><\/p>\n<\/div>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">CppDepend metrics:<\/span>\u00a0the plugin provides some useful design metrics like\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/cppdepend.com\/sonarplugin.aspx#AfferentCoupling\">Afferent coupling (Ca)<\/a>,<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.cppdepend.com\/metrics#EfferentCoupling\">Efferent coupling (Ce)<\/a>,\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.cppdepend.com\/metrics#RelationalCohesion\">Relational Cohesion(H)<\/a>,\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.cppdepend.com\/metrics#Instability\">Instability (I)<\/a>,\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.cppdepend.com\/metrics#Abstractness\">Abstractness (A)<\/a>,\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.cppdepend.com\/metrics#DitFromMainSeq\">Distance from main sequence (D)<\/a>. These metrics could be added to the dashbord using the Custom Metrics Widgets<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar1.png\" alt=\"\" width=\"652\" height=\"142\" \/><\/p>\n<\/div>\n<p>And the metrics are available from the Design category:<\/p>\n<p><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar2.png\" alt=\"\" \/><\/p>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">CppDpeend rules repository:<\/span>\u00a0After defining the sonar.cppdepend.cdproj in the sonar.properties file, the cppdepend rules repository will be added to the sonar rules.<\/span><img loading=\"lazy\" decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar9.png\" alt=\"\" width=\"605\" height=\"115\" \/><\/li>\n<\/ul>\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">cppcheck rules repository:<\/span>\u00a0cppcheck is a powerful tool to detect C\/C++ issues, it&#8217;s embeded in CppDepend and all the cppcheck rules are added to the sonar rules. <\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar9.png\" alt=\"\" width=\"642\" height=\"122\" \/><\/p>\n<\/div>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">CppDepend Widgets:<\/span>\u00a0The CppDepend sonar plugin provides some useful widgets to explore the CppDepend results:<\/span>\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">Class Metrics widget:<\/span>\u00a0CppDepend calculate many interesting class metrics related to their design and implementation. Some of these metrics could be discovered by this widget.\u00a0<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar5.png\" alt=\"\" \/><\/p>\n<\/div>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li><span style=\"font-weight: 600;\">CQLinq queries widget:<\/span><span style=\"font-style: inherit; font-weight: inherit;\">\u00a0CQLinq is a powerful feature to create easily coding rules. To explore the results of the CQLinq queries, you have to create a CQLinq group named &#8220;Sonar Queries&#8221; in your jdproj file and add to it your queries:<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar7.png\" alt=\"\" \/><\/p>\n<\/div>\n<p>And add the Queries Widget in your sonar dashboard:<\/p>\n<div class=\"rightfloated block70\"><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar3.png\" alt=\"\" \/><\/div>\n<div class=\"rightfloated block70\">\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li><span style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: 600;\">CppDepend report widget:<\/span>\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: inherit; font-style: inherit;\"><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar15.png\" alt=\"\" \/><\/span><\/p>\n<\/div>\n<div class=\"rightfloated block70\">\n<p><span style=\"font-weight: inherit; font-style: inherit;\">With CppDepend you can customize your report as described\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.cppdepend.com\/Doc_CI_Report\">here<\/a>. To make this report accessible from sonar you have to pass these two arguments to SonarRunnerForCppDepend:<\/span><\/p>\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">sonar.cppdepend.deploymentPath: Directory path where the cppdepend report will be copied.<\/span><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">sonar.cppdepend.deploymentUrl: URL of the directory where the cppdepend report is copied.<\/span><\/li>\n<\/ul>\n<ul style=\"font-weight: inherit; font-style: inherit;\">\n<li><span style=\"font-weight: 600;\">Abstractness vs Instability widget:<\/span><span style=\"font-style: inherit; font-weight: inherit;\">\u00a0The Abstractness vs Instability diagram is very useful to detect the lack of abstractness in the most used projects. You can refer\u00a0<\/span><a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/www.hanselman.com\/blog\/ExitingTheZoneOfPainStaticAnalysisWithNDepend.aspx\">here<\/a><span style=\"font-style: inherit; font-weight: inherit;\">\u00a0for more details about this diagram. As it is described before for the CppDepend report widget, you have to define sonar.cppdepend.deploymentPath and sonar.cppdepend.deploymentUrl arguments.\u00a0<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/img\/sonar16.png\" alt=\"\" \/><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The big challenge to develop a sonarqube plugin for C\/C++ is to use the good parser, producing a parser for such a grammar is much harder. \u00a0What makes C++ really hard is certain rules relating to declarations\/definitions, name lookup (consider argument-dependent name lookup) implicit conversion rules, and of course the resolution of templates.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1627","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1627"}],"version-history":[{"count":17,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1627\/revisions"}],"predecessor-version":[{"id":1668,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1627\/revisions\/1668"}],"wp:attachment":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}