Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarqube: Missing blame information for the following files

I am getting the warning Missing blame information for the following files during analysis by SonarQube.

[INFO] [22:19:57.714] Sensor SCM Sensor [INFO] [22:19:57.715] SCM provider for this project is: git [INFO] [22:19:57.715] 48 files to be analyzed [INFO] [22:19:58.448] 0/48 files analyzed [WARN] [22:19:58.448] Missing blame information for the following files: (snip 48 lines) [WARN] [22:19:58.449] This may lead to missing/broken features in SonarQube [INFO] [22:19:58.449] Sensor SCM Sensor (done) | time=735ms 

I am using SonarQube 5.5, analysis is done by Maven in a Jenkins job, on a multi-module Java project. Git plugin 1.2 is installed.

Manually running git blame in a bash shell, on any of the offending files, gives an expected output.

Related questions I found were all about SVN, my issue is with Git.

How do I get git blame information on Sonarqube?

like image 560
Amedee Van Gasse Avatar asked May 25 '16 08:05

Amedee Van Gasse


People also ask

What is missing blame information in SonarQube?

@ilyas: The missing blame information occurs because SCM annotation is missing (e.g. you did not run git commit on the files changed). If you don't care for the SCM annotations, which is helpful for SonarQube's diff algorithm for determining new code period issues, then you can disable it with sonar. scm.

How do I disable sonar SCM provider?

There's a setting at global and project levels to disable the SCM sensor. It's off by default. Look under Administration > SCM > Disable the SCM Sensor.


2 Answers

The cause was a JGit bug. JGit does not support .gitattributes. I had ident in my .gitattributes. Plain console git checked out the source, applied ident on $Id$ macros, but then JGit ignored that and saw a difference that wasn't committed, where there actually wasn't one.

The friendly people on the SonarQube mailing list helped me out, and suggested debugging with the standalone JGit command line distribution:

chmod +x /where/is/org.eclipse.jgit.pgm-<version>-r.sh /where/is/org.eclipse.jgit.pgm-<version>-r.sh blame -w /path/to/offending/file 

This particular JGit bug has not been solved for over 5 years and I have no hope that it will be solved anytime soon, so I removed the $Id$ macros from all my sources.

This is the (Bash) code I used, to remove all $Id$ macros:

find */src -name "*.java" | xargs -n 1 sed -i '/$Id.*$/d' find */src -name "*.java" | xargs git add git commit -m "Remove $Id$ macros" git push 
like image 110
Amedee Van Gasse Avatar answered Sep 19 '22 11:09

Amedee Van Gasse


I had a similar issue: a file in my project was created during the build process and was not stored in source control. In my case it was api.json.

Within the SonarQube runner build step in Team City I added this file to the exclusions within the additional parameters

-Dsonar.exclusions=**/spec/api.json 

and the error disappeared.

like image 42
John Meyer Avatar answered Sep 19 '22 11:09

John Meyer