SonarOpenCommunity / sonar-cxx

SonarQube C++ Community plugin (cxx plugin): This plugin adds C++ support to SonarQube with the focus on integration of existing C++ tools.
GNU Lesser General Public License v3.0
988 stars 364 forks source link

C plugin usage #1251

Closed guwirth closed 5 years ago

guwirth commented 6 years ago

Hi,

There is a new C plugin as part of our repository available for some time.

Latest snapshot versions are available here: https://ci.appveyor.com/project/SonarOpenCommunity/sonar-cxx/branch/master/artifacts

Regards,

guwirth commented 6 years ago

@jmecosta is the plugin on your side in productive use?

Wondering how this is working in

jmecosta commented 6 years ago

@guwirth when implementing the feature i started using it but after upgrading to last version of SQ i had to disable it since the server was not starting. So i will need to look at this sometime soon.

the idea is that you need to adjust the extensions in a way they dont clash.

i will try to get this working before the next release

guwirth commented 6 years ago

@jmecosta thanks for your answer. I'm wondering how header files (.h, .hpp) are handled if they are assigned to c and cxx plugin. because they are assigned to both plugins then.

Any experience?

jmecosta commented 6 years ago

basically you will have 2 different profiles that you need to maintain. the key here is to decide what is c and what is c++ since they cannot be defined in both plugins.

i was doing

c -> .c, .h c++ -> .cpp .hpp

after that it should work as normally with no duplicated issues i think. the rules we just copied the profiled from c++ but thats is really not good and needs to be worked on

jmecosta commented 6 years ago

looks good in a clean installation

image

the only thing i need to do is to put in sonar properties sonar.cxx.suffixes.headers=.hxx,.hpp,.hh sonar.cxx.suffixes.sources=.cxx,.cpp,.cc

guwirth commented 6 years ago

@jmecosta but in real world .c and .cpp are both using .h files (and often the same)

jmecosta commented 6 years ago

I dont think there is a problem with that, since there is no duplication

guwirth commented 6 years ago

@jmecosta think you are right. For issues there are no duplicates.

In general I see the following use cases now:

  1. Someone want to use the c plugin or the cxx plugin only: This case should be the easiest and work as of today. For the c plugin the setting sonar.cxx.cFilesPatterns should not be available and per default active.

  2. Someone want to use the cxx plugin only to compile .c and .cpp files. Both should be compiled and handled as a C++ compiler is doing it: sonar.cxx.cFilesPatterns should not be used.

  3. Someone want to use the cxx plugin only to compile .c and .cpp files. .c files should be handled as C compiler is doing it and .cpp files should be handled as a C++ compiler is doing it: sonar.cxx.cFilesPatterns should be used.

On long run we should be able to remove sonar.cxx.cFilesPatterns because case 3 could be handled by c plugin.

jmecosta commented 6 years ago

ok makes sense. so we should still remove cFilesPatterns from the c plugin already? since it does not make sense to keep it?

guwirth commented 6 years ago

Proposal is to remove c plugin and integrate functionality in cxx plugin. Commercial plugin shows that one plugin can support more than one language.

jmecosta commented 6 years ago

Interesting, is this something new? I tought one jar could provide only one plugin, since it the pom you need to specify the plugin class.

If the mingle all stuff into a class does it not make the all stuff more complex and more complex to maintain? That is if you can't have a dedicated class there for it

On Sun, 21 Jan 2018, 14:40 Günter Wirth, notifications@github.com wrote:

Proposal is to remove c plugin and integrate functionality in cxx plugin. Commercial plugin shows that one plugin can support more than one language.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-359245411, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyMsHS_0KwVQiusmaOymwAsLtfwtIks5tMzAhgaJpZM4P5W-0 .

guwirth commented 6 years ago

@jmecosta as far as I know the commercial plugin is only one JAR containing / supporting the languages C, C++ and Objective-C.

guwirth commented 6 years ago

@jmecosta

since it the pom you need to specify the plugin class.

Where is this in the POM?

...complex and more complex to maintain?

Not sure but today we have to maintain two plugins. Grammar behind is anyway the same it's only to show issues and metrics under different languages?

guwirth commented 6 years ago

@jmecosta as you can see it's one plugin containing several languages: image

jmecosta commented 6 years ago

Interesting how they handle the metrics per language. Maybe it's all the same for them. The idea of the C plugin was that we could have different metrics per language. If we can still have them then I don't see why we can't just merge everything

On Thu, 25 Jan 2018, 23:05 Günter Wirth, notifications@github.com wrote:

@jmecosta https://github.com/jmecosta as you can see it's one plugin containing several languages: [image: image] https://user-images.githubusercontent.com/6077367/35412177-a2188cf2-021b-11e8-8c56-23760dd70459.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-360600241, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyE54050VdFrMmh8Nxe0SDZXIPyyMks5tOOyCgaJpZM4P5W-0 .

guwirth commented 6 years ago

@jmecosta structure is like this

C / C++ / Objective-C

C++ (Community)

jmecosta commented 6 years ago

That's for profile definition a plugin can have as many as he wants.

The problem was always you could only define a plugin per jar. But if that's not the case anymore then merging those together makes sense. The split was only to allow this

On Fri, 2 Feb 2018, 17:15 Günter Wirth, notifications@github.com wrote:

@jmecosta https://github.com/jmecosta structure is like this

C / C++ / Objective-C

  • Language
    • C++
      • key: cpp:nnnnn (e.g. cpp:S3805)
    • C
      • key: c:nnnnn (e.g. c:S3805)
    • Objective-C
      • key: objc:nnnnn (e.g. objc:PPBadIncludeForm)

C++ (Community)

  • Language
    • c++
      • key: cxx:nnnnn (e.g. cxx:UseCorrectInclude)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-362599990, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyOy3Sv6YW1cbVad_igl8VGc2a9m0ks5tQxq7gaJpZM4P5W-0 .

guwirth commented 6 years ago

@jmecosta for my understanding it is like this:

jmecosta commented 6 years ago

yes, but how do you workaround this:

https://github.com/SonarOpenCommunity/sonar-cxx/blob/f10e60b0c9a965608ede2be4ed70f5c9d6080f25/sonar-cxx-plugin/pom.xml#L21

my understanding was that this was needed to defined the plugin, so we have 2 plugins inside the jar. will it work? if it does then all good, but i have tried this scenario

guwirth commented 6 years ago

@jmecosta the commercial plugin is called SonarCFamilyand have C, C++ and Objective-C language inside. This seems to be the trick?

jmecosta commented 6 years ago

Three jars inside one jar? Can that be the trick

On Sat, 3 Feb 2018, 22:03 Günter Wirth, notifications@github.com wrote:

@jmecosta https://github.com/jmecosta the commercial plugin is called SonarCFamilyand have C, C++ and Objective-C language inside. This seems to be the trick?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-362849938, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyN5ZpGsF9v2wfMfs3b-kx4cy8lcQks5tRLudgaJpZM4P5W-0 .

guwirth commented 6 years ago

@jmecosta as you can see it's one plugin containing several languages: image

jmecosta commented 6 years ago

Ok so basically is how it was earlier? So the plugin consumes any file of type c, c++, etc.

So I suppose that is the way to go.

On Sun, 4 Feb 2018, 11:21 Günter Wirth, notifications@github.com wrote:

@jmecosta https://github.com/jmecosta as you can see it's one plugin containing several languages: [image: image] https://user-images.githubusercontent.com/6077367/35412177-a2188cf2-021b-11e8-8c56-23760dd70459.png

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-362892985, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyMczSixOKoGAWsoEis-VupMwtgV_ks5tRXaugaJpZM4P5W-0 .

guwirth commented 6 years ago

@jmecosta think your original use case was to split C and C++ issue and metrics and handle it as two languages? There was no other reason, or?

jmecosta commented 6 years ago

Yes that's was the idea.

On Tue, 6 Feb 2018, 22:25 Günter Wirth, notifications@github.com wrote:

@jmecosta https://github.com/jmecosta think your original use case was to split C and C++ issue and metrics and handle it as two languages? There was no other reason, or?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-363553843, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyLHi6bFmxe7vnnGrYBvRB8hk-9nhks5tSLUmgaJpZM4P5W-0 .

1FiniUm commented 6 years ago

Hi, I use the c plug-in 1.0.0 in production with SonarQube Version 7.1, I have a problem with the configuration property : sonar.c.cppcheck.reportPath It seems not working as I don't see the Cppcheck sensor in the sonar Scanner log, and the cppcheck issues in SonarQube

guwirth commented 6 years ago

Hi @1FiniUm,

with version 1.0 we added #1420 checking some preconditions before running a sensor. (see code: https://github.com/SonarOpenCommunity/sonar-cxx/blob/master/cxx-sensors/src/main/java/org/sonar/cxx/sensors/cppcheck/CxxCppCheckSensor.java#L59)

My first guess is that no cppcheck rules are activated in your profile?

Regards,

1FiniUm commented 6 years ago

@guwirth thx for your help, I launched the runner in debug and you are right :

11:00:46.915 DEBUG: 'C (Community) CppCheckSensor' skipped because there is no related rule activated in the quality profile

The default sonar profile (Sonar way 674 rules) is used and all the cppcheck rules seems activated. Maybe I miss something in the profile configuration to enable cppcheck rules?

1FiniUm commented 6 years ago

@guwirth It's fixed now, you were right, I created a new profile and all is good now. Thx, for your help 😃

spashx commented 6 years ago

Hi,

We have a fresh new SonarQube 6.7.4 LTS version installed with the commercial C/C++ plugin installed (sonar-cfamily-plugin-5.1.0.10083.jar).

When copying the community plugins and restarting Sonar, we have this issue: java.lang.IllegalArgumentException: There is already a quality profile with name 'Sonar way' for language 'c' If the sonar-c-plugin-1.1.0.jar is removed from the folder, Sonar is working again. It looks like the community plugin tries to use/generates the same profile name as the commercial C/C++ plugin for the c langage, which is now read only, as stated in the SonarQube documentation: https://docs.sonarqube.org/display/SONARQUBE67/Release+6.5+Upgrade+Notes

Is there a way to modify the default profile name of the c community plugin, like it is already for the C++ (seen as "C++ (Community)") ? Thanks.

ivangalkin commented 6 years ago

Hi @spashx,

please se #1433, especially comments made by @guwirth

Am 28.06.2018 um 16:17 schrieb spashx notifications@github.com:

Hi,

We have a fresh new SonarQube 6.7.4 LTS version installed with the commercial C/C++ plugin installed (sonar-cfamily-plugin-5.1.0.10083.jar).

When copying the community plugins and restarting Sonar, we have this issue: java.lang.IllegalArgumentException: There is already a quality profile with name 'Sonar way' for language 'c' If the sonar-c-plugin-1.1.0.jar is removed from the folder, Sonar is working again. It looks like the community plugin tries to use/generates the same profile name as the commercial C/C++ plugin for the c langage, which is now read only, as stated in the SonarQube documentation: https://docs.sonarqube.org/display/SONARQUBE67/Release+6.5+Upgrade+Notes

Is there a way to modify the default profile name of the c community plugin, like it is already for the C++ (seen as "C++ (Community)") ? Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

guwirth commented 6 years ago

@1FiniUm see also #1345

By the way: what advantage do you see by using the c plugin? You can do the same by using the cxx plugin and set https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Supported-configuration-properties#sonarcxxcfilespatterns.

spashx commented 6 years ago

@guwirth not sure to understand 100%, you mean the cxx plugin with c file patterns setup will behave exactly like the c one ?

ivangalkin commented 6 years ago

@spashx at this moment, the [almost*] only advantage of the c-plugin is the mapping of ".c" extensions to the distinguished C-Language. If you use both C++ and C plugin you can differentiate between C-Language and C++-Language. E.g. [NC]LOC are counted separately, you can filter either for C or for C++ issues etc.

(*the set of rules for the squid sensor is slightly different for c and c++ languages, but it's not that important IMHO.)

The disadvantage of having both plugins enabled is the fact, that you have to maintain both rulesets separately for C and C++ (although de-facto the rules are absolutely the same).

If the appearance of C in the web UI in not important for you, you just can use the mentioned parameter sonar.cxx.cFilesPatterns in the cxx plugin.

spashx commented 6 years ago

@guwirth ok thanks for clarification.

Coming back to initial requirement, in SonarQube 5.6.6 we were using both commercial and community C plugin because the community one has features like integration of external tools outputs like Valgrind, RATS,etc.. that the commercial edition does not provide. With the latest update of the community C plugins, it is no more possible. Perhaps the best approach could be to rename the community C profile to ensure no naming conflict with the built in profile for C of the SonarSource C/C++ plugin.

eg: "C++ (Community)" for cxx and "C (Community)" for c. This way it is possible to use both C plugins at the same time and avoid C/C++ mixup in the UI.

spashx commented 6 years ago

Hi, I'm coming back about the issue of begin unable to deploy the C Community plugin into a SonarQube instance already having the C++ Commercial plugin. This still happens with release V1.1.0 and SQ 6.7.5.

The C community plugin will fail to load because it duplicates the C / Sonar Way default profile name of the C++ Commercial plugin. This does not happen with the C++ Community plugin.

I know that I could only install the C++ Community to make C Community analysis, but in this case we are not able to distinguish language analysis in the UI.

Looking to the V1.1.0 release, I see that it already includes a fix for that (merge of pull request #1433), but it simply does'nt work with the C community plugin.

If I modify the default-profile.xml file of sonar-c-plugin-1.1.0.jar and rename the default language "c" to "C (Community)" as defined into CLanguage.java, the plugin will load, and the language shown as "C (Community)". But in this case, the default profile for C of the Commercial plugin will then disappear from the profiles list. I assume this is not the proper way to dot it since in the sonar-cxx-plugin-1.1.0.jar's default-profile.xml the language is set to "c++" and not "C++ (Community)". Is this a typo into default-profile.xml files that should contain same strings for languages as the hardcoded ones into CLanguage.java/CppLanguage.java or should something be changed elsewhere ?

Thank you.

jmecosta commented 6 years ago

Can you create pull request? Hard to test if not having a instance with the payed plugin

On Fri, 14 Sep 2018, 15:06 spashx, notifications@github.com wrote:

Hi, I'm coming back about the issue of begin unable to deploy the C Community plugin into a SonarQube instance already having the C++ Commercial plugin. This still happens with release V1.1.0 and SQ 6.7.5.

The C community plugin will fail to load because it duplicates the C / Sonar Way default profile name of the C++ Commercial plugin. This does not happen with the C++ Community plugin.

I know that I could only install the C++ Community to make C Community analysis, but in this case we are not able to distinguish language analysis in the UI.

Looking to the V1.1.0 release, I see that it already includes a fix for that (merge https://github.com/SonarOpenCommunity/sonar-cxx/commit/afbee7b0fb8812d13c72d7cac51558ecd7f854c6#diff-c592d668c90e5a99fbebdfacd3a09a96of pull request #1433 https://github.com/SonarOpenCommunity/sonar-cxx/pull/1433), but it simply does'nt work with the C community plugin.

  • the C++ Community really appears in sonar as C++ (Community) as expected
  • the C Community is unable to load because of duplication.

If I modify the default-profile.xml file of sonar-c-plugin-1.1.0.jar and rename the default language "c" to "C (Community)" as defined into CLanguage.java, the plugin will load, and the language shown as "C (Community)" but I assume this is not the proper way to dot it since in the sonar-cxx-plugin-1.1.0.jar's default-profile.xml the language is set to "c++" and not "C++ (Community)". Is this a typo into default-profile.xml files that should contain same strings for languages as the hardcoded ones into CLanguage.java/CppLanguage.java or do I miss something else ?

Thank you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarOpenCommunity/sonar-cxx/issues/1251#issuecomment-421338353, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_jyGM_I2AmtaoaOaJnOxVIAXME81Vfks5ua5vigaJpZM4P5W-0 .

guwirth commented 5 years ago

Duplicate, see #1400