How to debug when sonar-scanner finds 0 files?

(Sagar Wanaselja) #1
  • which versions are you using?
    The free version 7.7
  • what are you trying to achieve
    Set up my first project and a scanner for it

How to debug when sonar-scanner finds 0 files?

I’m new to SonarQube. I’m using the free version 7.7. I tried to set up a demo sonar-scanner run on some pre-existing source files, and my problem is that the scanner is finding 0 files. But there are plenty of .js files in my directory hierarchy. I’m using sonar-project.properties with settings for both sonar.projectBaseDir and sonar.sources. On the SonarQube server I’ve set the project’s Analysis Scope for Source File Inclusions of *.js. The SonarQube server Overview for my project reports all of my analysis run attempts, but it reports “This project is empty”.

I’m not seeing any way to debug this problem. The debug -X option on sonar-scanner doesn’t report which hierarchy of directories it is trying. What to try next?

This might be related to the popular “This project is empty” thread. Although in my case I have never had a non-empty project.

Here’s some interesting output from the sonar-scanner client command line:

12:00:03.651 INFO: Indexing files…
12:00:03.651 INFO: Project configuration:
12:00:03.652 INFO: Included sources: *.js
12:00:03.666 DEBUG: readpipe [git, --version],/usr/bin
12:00:03.671 DEBUG: readpipe may return ‘git version 2.17.1’
12:00:03.671 DEBUG: remaining output:

12:00:03.671 DEBUG: readpipe [git, config, --system, --edit],/usr/bin
12:00:03.674 DEBUG: readpipe may return ‘/etc/gitconfig’
12:00:03.674 DEBUG: remaining output:

12:00:03.712 DEBUG: 0 non excluded files in this Git repository
12:00:03.764 INFO: 0 files indexed
12:00:03.764 INFO: 0 files ignored because of inclusion/exclusion patterns
12:00:03.764 INFO: 0 files ignored because of scm ignore settings
12:00:03.765 INFO: ------------- Run sensors on module my_project

12:00:04.902 INFO: Calculating CPD for 0 files

(Sagar Wanaselja) #2

Also: 14:16:25.589 DEBUG: ‘SonarJS’ skipped because there is no related file in current project

(Sagar Wanaselja) #3

I ended up making a fresh new directory and copying some sample .js files over to it. sonar-scanner ran happily on these files, reporting things as expected. This implies that some file or other metadata in my original existing directory was making sonar-scanner drop any consideration of those valid files WITHOUT WARNING. Are you aware of anything that could do that? Maybe a pom.xml or workspace.xml ?

(Felipe Zorzo) #4

Hi!

I can’t explain why (maybe I just didn’t search the docs enough), but by experience I can say that the correct pattern is **/*.js :wink:

INFO: Indexing files...
INFO: Project configuration:
INFO:   Included sources: *.js
INFO: 0 files indexed
INFO: Indexing files...
INFO: Project configuration:
INFO:   Included sources: **/*.js
INFO: 68 files indexed

EDIT: just for the sake of completeness, ** means “zero or more directories”.

(btw, I would remove this parameter unless you have a very good reason to use it)

(Sagar Wanaselja) #5

Thank you! Yes, **/*.js seems to work. Another thing I had to do was, for the project, disable the SCM sensor. It was assuming an SCM system that actually isn’t present, and as a result somehow it was also causing files to be ignored.

(G Ann Campbell) #6

Hi guys,

It looks like you’ve got this working, but I thought I’d mention (particularly since avoiding SCM integration had an impact) that files in your .gitignore are automatically excluded. We added this feature-not-a-bug a couple versions ago. You can turn that behavior off by passing sonar.scm.exclusions.disabled=true to your analysis.

If you don’t think this is the issue @wanaselja and you want to continue to pursue this, then it would be helpful to see your analysis properties and command line.

 
HTH,
Ann

(Sagar Wanaselja) #7

Hi Ann,
Thanks for the extra clue. As an experiment, I re-enabled the SCM Sensor in the server-side project, and instead I added sonar.scm.exclusions.disabled=true to my client-side sonar-project.properties. That worked, there were plenty of files analyzed.

This is not an ongoing problem for me at this time, but in case you were curious, my sonar-project.properties is:

sonar.projectKey=core_aura_x1
sonar.projectName=core_aura_x1
sonar.projectVersion=1.0
sonar.sources=ui-global-components/components/one
sonar.sourceEncoding=UTF-8
sonar.scm.exclusions.disabled=true

(Sagar Wanaselja) #8

Nothing special on the command line. Just:
sonar-scanner -X

(Sagar Wanaselja) #9

Another point: There is no .gitignore. The source code being experimentally scanned doesn’t use git, it uses P4.