[SOLVED] Exclude symlink from the scanner

  • Version of SonarQube: Enterprise Edition - Version 8.6 (build 39681)
  • Version of SonarScanner: SonarScanner 4.5.0.2216

Hello world,

The project on which I want to launch sonarqube contains symbolic links to files that no longer exist, so I tried to remove them (exclusion) from the scanner via the graphical interface: Project Settings → General Settings → Analysis Scope → Coverage Exclusions, and I indicated the following regex: views/*.

However, when the scanner launches, the files and symbolic links in the views/ folder are still taken into account. I searched the documentation and on this the forum but could not find a solution to this problem.

The command used to run the scanner is as follows:

$ sonar-scanner \
   -Dsonar.projectKey = **** \
   -Dsonar.sources =. \
   -Dsonar.host.url = http://127.0.0.1:9000 \
   -Dsonar.login = ***** 

Hereafter is an excerpt of the scanner logs:

--- snipped --- 

WARN: Too many duplication references on file views/beta_settings/static/mobile/vi/offers.html for block at line 12. Keep only the first 100 references.
INFO: CPD Executor CPD calculation finished (done) | time=4987ms
INFO: Load New Code definition
INFO: Load New Code definition (done) | time=18ms
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 14:57.921s
INFO: Final Memory: 266M/904M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: java.lang.IllegalStateException: Unable to read file /*******/views/neon/index-tablet.html
        at org.sonar.scanner.scan.filesystem.MetadataGenerator.setMetadata(MetadataGenerator.java:69)
        at org.sonar.scanner.scan.filesystem.FileIndexer.lambda$indexFile$0(FileIndexer.java:138)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.checkMetadata(DefaultInputFile.java:91)
        at org.sonar.api.batch.fs.internal.DefaultInputFile.lines(DefaultInputFile.java:218)
        at org.sonar.scanner.report.ComponentsPublisher.publish(ComponentsPublisher.java:67)
        at org.sonar.scanner.report.ReportPublisher.generateReportFile(ReportPublisher.java:163)
        at org.sonar.scanner.report.ReportPublisher.execute(ReportPublisher.java:137)
        at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:366)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
        at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
        at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Unable to read file /*******/views/neon/index-tablet.html
        at org.sonar.scanner.scan.filesystem.CharsetDetector.run(CharsetDetector.java:50)
        at org.sonar.scanner.scan.filesystem.MetadataGenerator.setMetadata(MetadataGenerator.java:56)
        ... 26 more
Caused by: java.nio.file.NoSuchFileException: /*******/views/neon/index-tablet.html
        at java.base/sun.nio.fs.UnixException.translateToIOException(Unknown Source)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(Unknown Source)
        at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(Unknown Source)
        at java.base/java.nio.file.Files.newByteChannel(Unknown Source)
        at java.base/java.nio.file.Files.newByteChannel(Unknown Source)
        at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(Unknown Source)
        at java.base/java.nio.file.Files.newInputStream(Unknown Source)
        at org.sonar.scanner.scan.filesystem.CharsetDetector.readBuffer(CharsetDetector.java:66)
        at org.sonar.scanner.scan.filesystem.CharsetDetector.run(CharsetDetector.java:47)
        ... 27 more
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Hi @rob1, welcome to the SonarSource Community!

I know it’s confusing because it’s the first property that can be changed on that screen in the UI, but I don’t think Coverage exclusions is what you wanted to set. That simply removes a file from being considered as part of the code coverage percentage calculations. Instead you want Source File Exclusions (property name sonar.exclusions) which is down towards the middle of the page if what you want is for the file to be ignored entirely.

Thanks for the reply and the welcome message :slight_smile:

In deed it was the source file exclusions, and my regex which was not correct. I needed to replace views/* by views/** to disable all folders and not only files from the exclusion.

Have a good day,
rob1

1 Like