File being indexed twice

Here is my sonar-project.properties file

sonar.sources=bin/,config/,controllers/,middleware/,services/,models/,mongo/,utils/,Dockerfile,\
Jenkinsfile,Jenkinsfile-dev,swagger.js,server.js,ecosystem-dev.config.js,ecosystem.config.js
sonar.tests=test/
sonar.coverage.exclusions=bin/**/*, config/**/*, models/**/*, mongo/**/*, utils/**/*, Dockerfile,\
Jenkinsfile, Jenkinsfile-dev, swagger.js, server.js, ecosystem-dev.config.js, ecosystem.config.js,\
package.json, sonarcloud/**/*
sonar.cpd.exclusions=bin/**/*, config/**/*, models/**/*, mongo/**/*, utils/**/*, Dockerfile,\
Jenkinsfile, Jenkinsfile-dev, swagger.js, server.js, ecosystem-dev.config.js, ecosystem.config.js,\
package.json, sonarcloud/**/*
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-

I am getting the following error even when I haven’t put the test dir in either of cpd or coverage exclusions


Would love to get an insight into this one.

Hi,

As far as I can tell, what you’ve done should work. The only things that catch my eye are

  • the escaped linebreaks - can you try eliminating them by moving everything to the same line?
  • the trailing / on test/ for sonar.tests. It’s just not needed. Can you drop it?

On an unrelated note, there’s no need to exclude package.json and sonarcloud/**/* from anything; they’re not part of your sources or tests, so they were never included to start with.

If the changes I’ve suggested don’t work, please post the full text of your analysis log.

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hey Ann,

Thanks for the reply. This is the modified properties file

sonar.sources=bin/,config/,controllers/,middleware/,services/,models/,mongo/,utils/,Dockerfile,Jenkinsfile,Jenkinsfile-dev,swagger.js,server.js,ecosystem-dev.config.js,ecosystem.config.js
sonar.tests=test
sonar.coverage.exclusions=bin/**/*, config/**/*, models/**/*, mongo/**/*, utils/**/*, Dockerfile, Jenkinsfile, Jenkinsfile-dev, swagger.js, server.js, ecosystem-dev.config.js, ecosystem.config.js
sonar.cpd.exclusions=bin/**/*, config/**/*, models/**/*, mongo/**/*, utils/**/*, Dockerfile, Jenkinsfile, Jenkinsfile-dev, swagger.js, server.js, ecosystem-dev.config.js, ecosystem.config.js
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-

I have attached the analysis log. Look forward to hearing from you.
analysis_log_sonar.txt (4.5 MB)

Hi,

Where/how are you providing these properties to analysis?

There are thousands of lines about files in /opt/applications, which does not appear in your sonar.sources list.

I see this at the top of the file:

15:41:56.946 INFO: Scanner configuration file: /root/.sonar/sonar-scanner-5.0.1.3006-linux/conf/sonar-scanner.properties
15:41:56.957 INFO: Project root configuration file: /opt/application/sonar-project.properties

Is /opt/applicaiton/sonar-project.properties the file you expected to be used?

 
Ann

Hey Ann,

Yes. The properties are provided in that file. I have shared the relevant part of that file here.

Hi,

The relevant part? Can you share the whole file? Because something’s odd here.

 
Ann

Hey Ann,

Here is the properties file in full,

sonar.organization=xxx
sonar.projectKey=xxx
sonar.host.url=xxx
sonar.sourceEncoding=UTF-8
sonar.sources=bin/,config/,controllers/,middleware/,services/,models/,mongo/,utils/,Dockerfile,Jenkinsfile,Jenkinsfile-dev,swagger.js,server.js,ecosystem-dev.config.js,ecosystem.config.js
sonar.tests=test
sonar.coverage.exclusions=bin/**/*, config/**/*, models/**/*, mongo/**/*, utils/**/*, Dockerfile, Jenkinsfile, Jenkinsfile-dev, swagger.js, server.js, ecosystem-dev.config.js, ecosystem.config.js
sonar.cpd.exclusions=bin/**/*, config/**/*, models/**/*, mongo/**/*, utils/**/*, Dockerfile, Jenkinsfile, Jenkinsfile-dev, swagger.js, server.js, ecosystem-dev.config.js, ecosystem.config.js
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-

Hi,

Can you add sonar.scanner.dumpToFile=[path to file] (docs) to a run and provide the output, please?

 
Thx,
Ann

Hey Ann,

Does this dump the scanner output to a file? We’re running the sonar analysis in a Jenkins job and all the files created during the run cannot be accessed as far as I know.

Hi,

Yes, it creates a file at the specified path. Can you turn off workspace cleanup for one run?

 
Ann

Hey Ann,

We need to do some additional configs to access files during the run. In the meantime, I am curious regarding the log I provided. Is it missing out some info?

Hi,

As I said, in the log you provided there are thousands of lines about files under /opt/application, files under /root and other files that shouldn’t be considered at all, based on the properties you’ve provided.

That’s why I want to see what properties the scanner ends up with.

 
Ann

Hey Ann,

I get it now. A clarification from my end ,opt/application is the working directory of this project. So all of the project’s files are in there. sonar-scanner is downloaded in root.

Hi,

15:42:23.316 INFO: 29003 files ignored because of scm ignore settings

There’s a log line for each one of those ignored files. :sweat_smile:

Removing them makes it easier to see that you do have files in the log that correspond to your sonar.sources definition.

And you also have ~29k files that don’t seem to correspond to it. Which makes me suspicious about the sonar.sources value analysis is actually getting. It defaults to ., which looks like what’s going on here.

I’m eager to see that analysis dump…

 
Ann

analysis.txt (2.8 KB)
Hey Ann,
Here is the dump file

Hi,

Here we go:

sonar.sources=.

Now the question is where that’s coming from. The docs explain the hierarchy so you have an idea where to look.

 
HTH,
Ann

Hey @ganncamp ,

We had an additional sonar.sources=. parameter in our sonar-scanner command. I have removed it and the issue of error due to indexing is eliminated. However, the code is not being analyzed. I have raised it on the forum, Code not being analysed. I request you or any of the team member to take a look. Thanks.

1 Like