I need to run Sonar analysis on Java file before committing code to svn. Is there any mechanism to ensure that code having sonar issues doesn't gets checked into svn unless all sonar issues get resolved.
Sonar analysis prior to code check in
2.6k views Asked by Sam At
2
There are 2 answers
0
On
It can be done if the SVN supports hooks or alike.
For example, Git allows writing hooks for the commits/push/receive[server side] ;
- First download sonarscanner
- Create a git pre-push hook on the developer's machine to run sonarscanner
run sonarscanner and you will see the result on the stdout.
if sonar-scanner | grep '[ ]+[0-9]* blocker$' then
exit 1
else
exit 0
fi
Using this you can decide whether to accept or not the checkin (if there are blockers etc.)
The short answer is that you can't. The long answer is that you can come close.
Take a look at http://www.sonarlint.org/, for in-IDE code scanning. Then have a look at pull request analysis which should flag new issues. It's then up to the human reviewer to accept or reject the PR.