user4948798
user4948798

Reputation: 2102

SonarQube Language sonar.lang.patterns error

Our Sonar Build Environment details as follows:

* SonarQube Server Version - 5.6.6 (64-Bit). 
* Sonar Client Build Operating System – Windows-7 (64-Bit). 
* Sonar-scanner- Version - 3.0.3.778.
* sonar-cxx-plugin-0.9.7.jar
* sonar-csharp-plugin Version -5.11.0.1761.
* sonar-objective-c-plugin-0.5.0-SNAPSHOT.jar
* Source Code Language: C# and C++

Our SonarQube server is centralized server, So have installed (cxx-plugin, objective-c-plugin and csharp-plugin)

Current Problem:

When we scan the code, if fails with below error. Since we have multiple language (C# and C++) code, Both the language has to be scanned at a time.

ERROR: Caused by: Language of file 'workspace/HS30/baseclasses/ametex.h' can not be decided as the file matches patterns of both sonar.lang.patterns.c++ : **/*.cxx,**/*.cpp,**/*.cc,**/*.c,**/*.hxx,**/*.hpp,**/*.hh,**/*.h and sonar.lang.patterns.objectivec : **/*.h,**/*.m

sonar.language=cs,c++ (Tried but didn't work)

So kindly help us to resolve the same.

Upvotes: 8

Views: 15415

Answers (3)

mmerle
mmerle

Reputation: 595

I do sonar.lang.patterns.c="" to empty the C extensions, and only keep the C++ ones. You need to know which one you want to keep, for instance sonar.lang.patterns.objectivec="" to remove the objectiveC ones.

Upvotes: 2

DoNuT
DoNuT

Reputation: 487

In theory, the easiest approach would be configuring the patterns so that *.h files are only matched by one language, i.e. by setting the option sonar.lang.patterns.objectivec empty.

Indeed, that would be sacrifice analysis for ObjectiveC, maybe you can rethink your project structure or run two Sonar builds that scan both languages individually?

Upvotes: 0

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22804

This is a question of which language "claims" .h files. Only one language can claim any given file extension and currently you have two languages claiming .h, so the scanner can't figure out which analyzer to give those files to, and gives up.

Specifically, from your error message:

the file matches patterns of both sonar.lang.patterns.c++ : **/*.cxx,**/*.cpp,**/*.cc,**/*.c,**/*.hxx,**/*.hpp,**/*.hh,**/*.h and sonar.lang.patterns.objectivec : **/*.h,**/*.m

You have both cxx and objectivec claiming .h. You must remove the extension from one of those two lists.

Go to (Global) Administration > [Language] > [Language] file suffixes to edit the extensions claimed by each language, and remove .h from one or both languages.

Make sure that you do not leave either of these fields blank. If left blank, the default value (which includes .h) will be used.

Upvotes: 8

Related Questions