This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 201680

Summary: Add static C/C++ code analysis
Product: cnd Reporter: johngull
Component: -- Other --Assignee: johngull
Status: NEW ---    
Severity: normal CC: Otisburg, ProjectOrc
Priority: P3    
Version: 7.1   
Hardware: All   
OS: Other   
URL: https://github.com/johngull/nb-cppcheck
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: fix of compilation and nb modules warning; some minor clean up

Description johngull 2011-09-06 12:38:41 UTC
Will be great to add static analysis.
For this purposes cppcheck can be used (http://sourceforge.net/projects/cppcheck/).
Comment 1 johngull 2012-02-10 08:07:19 UTC
I had started to make cppcheck plugin by myself and plan to share it.
But i faced with some problems.

For correct work cppcheck needs include pathes. I found that it can be received from NativeProject object, but i can't use.

Can someone show me workaround or any other way to receive include pathes.

Also please hint me how to enumerate required projects and projects from library list.

Thanks.
Comment 2 Vladimir Voskresensky 2012-02-10 08:18:31 UTC
(In reply to comment #1)
> I had started to make cppcheck plugin by myself and plan to share it.
> But i faced with some problems.
> 
> For correct work cppcheck needs include pathes. I found that it can be received
> from NativeProject object, but i can't use.
Why?

> 
> Can someone show me workaround or any other way to receive include pathes.

If you try to get options for header => you need to know source file's options which includes this header. CsmFileInfoQuery.getCompilationUnits will help you.
Include paths you can also get using 
CsmFileInfoQuery.get***IncludePaths

CsmUtilities has methods getCsmFile for different input parameters - one of them should be ok for you.
> 
> Also please hint me how to enumerate required projects and projects from
> library list.
csmFile.getProject().getLibraries() 
CsmProject.isArtificial() allows to understand if it is real project of one of system includes associated projects.
Comment 3 johngull 2012-02-10 08:27:41 UTC
(In reply to comment #2)

Thank you for reply.

> > For correct work cppcheck needs include pathes. I found that it can be received
> > from NativeProject object, but i can't use.
> Why?
   Compiler say that NativeProject can't be used, because my package is not in friend list. Can't say exact message now, but hope you understand.

Sorry if my questions is stupid - Java is unknow world for me :) 

What I really needs is just list of directories, which is puted by user as include directories to project properties.
Comment 4 Vladimir Voskresensky 2012-02-10 09:03:59 UTC
(In reply to comment #3)
> (In reply to comment #2)
> 
> Thank you for reply.
> 
> > > For correct work cppcheck needs include pathes. I found that it can be received
> > > from NativeProject object, but i can't use.
> > Why?
>    Compiler say that NativeProject can't be used, because my package is not in
> friend list. Can't say exact message now, but hope you understand.
You should specify "implementation" dependency for now. Later if all works you can tell me name of your modules and I'll add you to "friends" list.
 
> 
> Sorry if my questions is stupid - Java is unknow world for me :) 
> 
> What I really needs is just list of directories, which is puted by user as
> include directories to project properties.
As I said header files do not have anything in project properties themselves, so you anyway have to jump to source file.
Then CsmFileInfoQuery.get***IncludePaths
gives you a list of paths
Comment 5 johngull 2012-03-11 19:15:16 UTC
Hello,

 I had made simple plugin for using cppcheck in netbeans:
https://github.com/johngull/nb-cppcheck

Will be very thankful for anyone who will try it. Also will be great if someone java specialist will check code.
Comment 6 Vladimir Voskresensky 2012-03-11 20:05:59 UTC
Hi,

Thanks for your activity!
How can I push changes into your repo? Do I need account at github?

Btw, when run without installed cppcheck => exception [1]
when it is installed, I get [2]

[1] java.io.IOException: java.io.IOException: error=2, No such file or directory
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
	at java.lang.ProcessImpl.start(ProcessImpl.java:65)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
Caused: java.io.IOException: Cannot run program "cppcheck" (in directory "/home/vv159170/NetBeansProjects/Quote_2"): java.io.IOException: error=2, No such file or directory
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
	at java.lang.Runtime.exec(Runtime.java:593)
	at java.lang.Runtime.exec(Runtime.java:431)
[catch] at org.johngull.netbeans.cppcheck.CppCheckRunnable.run(CppCheckRunnable.java:66)
	at java.lang.Thread.run(Thread.java:662)

[2] 
java.lang.ArrayIndexOutOfBoundsException: 1
[catch] at org.johngull.netbeans.cppcheck.CppCheckRunnable.run(CppCheckRunnable.java:77)
	at java.lang.Thread.run(Thread.java:662)
Comment 7 Vladimir Voskresensky 2012-03-11 20:09:06 UTC
Created attachment 116564 [details]
fix of compilation and nb modules warning; some minor clean up

some changes to make code compilable in my environment
Comment 8 johngull 2012-03-12 18:00:25 UTC
Hello Vladimir,

 Thank you very much for trying and for patch.

> How can I push changes into your repo? Do I need account at github?
  I guess account is needed for pushing to github.
I had already applied your diff to "dev" branch.

> 
> Btw, when run without installed cppcheck => exception [1]
> when it is installed, I get [2]
   [2] fixed, [1] is just because of not installed cppcheck - made more clear output in such case.


 Can you please check it once again - latest version is on the branch "dev".

Also i see on one windows machine with ~25 opened C++/Qt projects, that process is stuck. But i can't repeat on my linux machine.
As i understand this is smth in CppCheckRunnable class. Can you please look as experienced java coder to the while loop in it.

Thank you.
Comment 9 ProjectOrc 2015-08-27 04:38:03 UTC
This would be great if it was core functionality.

In the same way that NetBeans manages the Makefile and other scripts for C++ development (which can be subsequently built without NetBeans), it would be great if NetBeans would automatically manage a Cppcheck configuration file that could also be used elsewhere outside of NetBeans.