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

cppcheck report results not loaded as issues in Sonar: how to troubleshoot #278

Closed
jfallot opened this issue Sep 1, 2014 · 18 comments
Closed
Assignees
Milestone

Comments

@jfallot
Copy link

jfallot commented Sep 1, 2014

Current env:
. Sonar 4.4
. C++ (Community) plugin version 0.9
. Using sonar-runner to run sonar analysis

My problem: although the cppcheck report result is available and the sonar analysis successful (metrics OK), No issues are showing up in Sonar (although there are a lot...).

Checks done:
. Run sonar-runner with -X: not much useful information is dumped about cxx plugin execution
. Numerous tests on cppcheck report path (absolute, relative)

In a previous env:
. Sonar 4.2
. Maven used to launch Sonar analysis
The issues were correctly reported in Sonar.

My Questions:
How can I more deeply debug the C++ plugin when launching the analysis by sonar-runner?
Attach a remote debugger to Sonar server?
What is the right code branch for 0.9 version of the C++ (Community) plugin?

@jmecosta
Copy link
Member

jmecosta commented Sep 1, 2014

You can try to search the issues list, many users have reported cppcheck
problems mostly related with paths that are now relative to source Dir.
Maybe you can get some ideas there. If not, then showing the debug log and
the cppcheck report can help a bit.

If you want to dig into code, clone the main repository and check the
master
On Sep 1, 2014 7:47 PM, "jfallot" [email protected] wrote:

Current env:
. Sonar 4.4
. C++ (Community) plugin version 0.9
. Using sonar-runner to run sonar analysis

My problem: although the cppcheck report result is available and the sonar
analysis successful (metrics OK), No issues are showing up in Sonar
(although there are a lot...).

Checks done:
. Run sonar-runner with -X: not much useful information is dumped about
cxx plugin execution
. Numerous tests on cppcheck report path (absolute, relative)

In a previous env:
. Sonar 4.2
. Maven used to launch Sonar analysis
The issues were correctly reported in Sonar.

My Questions:
How can I more deeply debug the C++ plugin when launching the analysis by
sonar-runner?
Attach a remote debugger to Sonar server?
What is the right code branch for 0.9 version of the C++ (Community)
plugin?


Reply to this email directly or view it on GitHub
#278.

@jmecosta
Copy link
Member

jmecosta commented Sep 1, 2014

@devYonz
Copy link

devYonz commented Sep 6, 2014

I am also faced with a similiar issue but i am using 0.9.1 and tried both sonar 4.4 and Sonar 4.2 to no avail. Execution succeeds but not issues get reported in UI. I am using sonar-runner 2.4

Any help would be appreciated.

@wenns
Copy link
Contributor

wenns commented Sep 6, 2014

You may:

@guwirth
Copy link
Collaborator

guwirth commented Oct 19, 2014

These are mostly path issues

  • path separator: use native one of your OS
  • prefer using absolute paths in report files

@wenns
Copy link
Contributor

wenns commented Oct 25, 2014

@jfallot: Is the issue solved?

@jfallot
Copy link
Author

jfallot commented Oct 28, 2014

@wenns: no, the issue is still there. Following advices posted here, I again tried using either absolute or source-relative paths, using Windows or Unix separator (the platform is Windows), no improvement.
The log, even with debug activated, doesn't mention if the cppcheck report file is found or not.

The next step is to make a try with 0.9.1 from source and debug it, but I have many other priorities on top of that...

@guwirth
Copy link
Collaborator

guwirth commented Nov 1, 2014

@jfallot
Copy link
Author

jfallot commented Nov 7, 2014

@guwirth:

This page is a great initiative, however:

  • There are conflicting information:
    we can read:

"Use always slashes (/) in the configuration file sonar-project.properties as path separator.
Hint: It is also possible to use backslashes but you have to escape it with another backslash (\ => ) which is hard to read."

and later

"For all report files use the native path separator of your operating system for path items. This is backslash () on Microsoft Windows and slash (/) on Linux."

  • Applying the recommendations unfortunately didn't solve my problem. Since the plugin output (even in debug mode) doesn't provide any hint on the way the sonar.cxx.cppcheck.reportPath is interpreted, if the report file is found and how it is analyzed, my only option today is still to debug the plugin on my project.

@guwirth
Copy link
Collaborator

guwirth commented Nov 7, 2014

With report files I mean the xml output of tool like cppcheck and not the setting in the configuration file. How can I make this more clear in the wiki?

@wenns
Copy link
Contributor

wenns commented Dec 13, 2014

Any progress?

@jfallot
Copy link
Author

jfallot commented Dec 30, 2014

Yep, I finally found the time to fix the problem.

When using modules in the sonar-project.properties file, the reportPath becomes relative to each module subdirectory, which isn't convenient when you have one single cppcheck results file for a complete project. Even using "../" to go up in the relative path doesn't work.

Although a reportPath property is defined, the plugIn doesn't emit any warning if no matching report file is not found during analysis. That's only through step by step debugging (I used the latest sources of the master branch) that I have been able to identify this.

The only solution I found is to modify the sources to accept an absolute path in the reportPath property, by changing the getReports method of class CxxReportSensor to this:

 protected List<File> getReports(Settings conf,
      String baseDirPath,
      String reportPathPropertyKey,
      String defaultReportPath) {
    String reportPath = conf.getString(reportPathPropertyKey);
    if (reportPath == null) {
      reportPath = defaultReportPath;
    }
    reportPath = FilenameUtils.normalize(reportPath);

    CxxUtils.LOG.debug("Using pattern '{}' to find reports", reportPath);

    File baseDir = new File(baseDirPath);
    File reportFile = new File(reportPath);

    if(reportFile.isAbsolute()) {
    baseDir = reportFile.getParentFile();
    reportPath=reportFile.getName();
    }

    DirectoryScanner scanner = new DirectoryScanner(baseDir,
            WildcardPattern.create(reportPath));

    return scanner.getIncludedFiles();
  }

I also had to update CxxReportSensor_getReports_Test class to match that change.

I have then been able to complete the analysis and have cppcheck issues reported in Sonar.

What should I do to get that code change integrated?

Thanks,
JF

@guwirth
Copy link
Collaborator

guwirth commented Dec 30, 2014

Thx for your analysis. Could you provide a pull request for review and test please.

@jmecosta
Copy link
Member

hi,

i think you are looking for this #252
the idea of this pull request is to support multi module configuration. you can give it a try

jfallot pushed a commit to jfallot/sonar-cxx that referenced this issue Dec 30, 2014
@jfallot
Copy link
Author

jfallot commented Dec 30, 2014

Hello,

I just created a pull request to submit the changes I was referring to above, and just added a ref to #252.
I hope I did well (I am completly new to Git)

@guwirth guwirth modified the milestone: M 0.9.3 Jan 5, 2015
@hikoust
Copy link

hikoust commented Jan 12, 2015

Hi,

Can you please share the modified CxxReportSensor class file or share Git location ? I am using Cxx scan in Sonar and facing the same issue. I dont have required environment to compile sonar source code.

Thanks,
Kaushik

jfallot added a commit to jfallot/sonar-cxx that referenced this issue Jan 12, 2015
Changes reintroduced following the reverts done for SonarOpenCommunity#244
jfallot added a commit to jfallot/sonar-cxx that referenced this issue Jan 12, 2015
@guwirth
Copy link
Collaborator

guwirth commented Apr 20, 2015

@jfallot could you test that please with 0.9.3-RC1

@jmecosta
Copy link
Member

@guwirth -> close -> release -> re-open if does not work

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

No branches or pull requests

6 participants