Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c++ community can't extract msbuild warnings for SonarQube #1184

Closed
VallotLuc opened this issue Jul 4, 2017 · 7 comments
Closed

c++ community can't extract msbuild warnings for SonarQube #1184

VallotLuc opened this issue Jul 4, 2017 · 7 comments
Assignees
Labels
Milestone

Comments

@VallotLuc
Copy link

Hi,

I want export warning from c++ msbuild.log file to sonarqube, using c++ community plugin,
after exporting, sonarqube has no result except duplications informations

I'm using this process

SonarQube.Scanner.MSBuild.exe begin /k:"LV" /n:"LV" /v:"1.0" /s:"C:\Program Files (x86)\Jenkins\workspace\sonarqube.analysis.xml" /d:sonar.cxx.compiler.regex="^.>(?.)((?[0-9]+)):\x20warning\x20(C\d\d\d\d):(?.*)$"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /t:Clean,Build /p:PlatformToolset=v140 /p:Configuration=Release;WarningLevel=3 /p:RunCodeAnalysis=True;CodeAnalysisRuleSet=AllRules.ruleset;verbosity=normal /filelogger /fileLoggerParameters:Verbosity=detailed;Encoding=UTF-8
SonarQube.Scanner.MSBuild.exe end

the end process display this
INFO: Sensor CxxCompilerSensor [cxx]
INFO: Searching reports by relative path with basedir 'C:\Program Files (x86)\Jenkins\workspace\Test_C' and search prop 'sonar.cxx.compiler.reportPath'
INFO: Scanner found '1' report files
INFO: Parser will parse '1' report files
INFO: Processing report 'C:\Program Files (x86)\Jenkins\workspace\Test_C\msbuild.log'
INFO: Scanner 'Visual C++' initialized with report 'C:\Program Files (x86)\Jenkins\workspace\Test_C\msbuild.log', CharSet= 'UTF-8'
INFO: Parsing 'Visual C++' format (UTF-8)
INFO: Using pattern : '^.>(?.)((?[0-9]+)):\x20warning\x20(C\d\d\d\d):(?.*)$'
INFO: C++ compiler Warnings processed = 0
INFO: Sensor CxxCompilerSensor [cxx] (done) | time=359ms

as you can see, no warnings are processed, but why ? , the msbuild.log contain many

I'm using c++ plugin 0.9.7 and all rules are activated

msbuild.log and qonarqube.analysis.xml in this zipfile
SonarQube.Analysis.zip

Can you help me ?

Best regards

Luc

@guwirth
Copy link
Collaborator

guwirth commented Jul 4, 2017

@VallotLuc some questions:

Regards,

@guwirth guwirth added this to the 0.9.7 milestone Jul 4, 2017
@VallotLuc
Copy link
Author

Hi guwirth,

SQ : 6.4
SQ.Scanner.MSBuild : 3.0.0.629
MsBuild : 14.0.25420.1

thanks for the link, the problem is solved
the reason was the regex expression (I do not use the good one)

One related question :
what is the right syntax to record the regex expression inside the SonarQube.Analysis.xml file ?

regards

Luc

@guwirth
Copy link
Collaborator

guwirth commented Jul 5, 2017

@VallotLuc
Copy link
Author

Thanks Günter,
but last problem was: the exact syntax for the regex value in the xml file
(for example, ^(.)((\d+))\x20:\x20warning\x20(C\d+):(.)$ , how to code this ?
If I wrote " ^(.
)((\d+))\x20*:\x20warning\x20(C\d+):(.*)$ ", this can't be read

thanks

Luc

@Bertk
Copy link
Contributor

Bertk commented Jul 6, 2017

Please read discussion #616. There you find a sample properties file for visual studio 'SonarQube.StaticAnalysis.props'. Here I use

<SQCompilerRegEx>^(.*)\((\d+)\)\x20*:\x20warning\x20(C\d+):\x20(.*)\x20\[$(SQProjectFile)\]$</SQCompilerRegEx>

and a message shows the regular expression:

<Target Name = "SQEnvCheck" AfterTargets="Build">
<Message Text="sonar.cxx.compiler.regex      = $(SQCompilerRegEx)"/>
</Target>

@VallotLuc
Copy link
Author

thanks for the syntax,

I have a related question

my msbuild.log file contain duplicates warning lines (same file, same line , same warning-code),
but they are not exactly duplicated, the file path speeling is not the same
(for example, I can find
c:\program files (x86)\jenkins\workspace\test_c\calcul\Types.h
and
c:\program files (x86)\jenkins\workspace\test_c\fichiercommunrglt../calcul/Types.h
the same file named differently)

is it possible to force Msbuild to generate the same value, or is it possible to write a script to replace the path by a normalized one ?

regards

Luc

@Bertk
Copy link
Contributor

Bertk commented Jul 11, 2017

I think the second path is not correct and the plug-in does not handle the relative path starting with '..\' correctly.
A separator '/' or '\' is missing at the end of the project root folder. This should be added if the path starts with '..\'
Hint: Better solution is to replace all '\' with '/' anyway.

So this issue has to be solved in the C++ community plug-in.

The usage of "../calcul/Types.h" is a bad practice and shall be avoided anyway.
Please read the rule cxx:UseCorrectInclude #include directive shall not use relative path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants