Skip to content

sonar.cxx.file.suffixes

Günter Wirth edited this page Jun 22, 2021 · 12 revisions

The analsis parameter defines a list of suffixes of CXX files to analyze.

The reading in of source files (indexing) is a prerequisite for the subsequent reading in and visualisation of reports of external tools. The programming language sensor is often also called squid sensor.

In SonarQube, each file extension must be uniquely assigned to one programming language. When operating several C/C++ plugins in parallel, this must be taken into account during configuration. To avoid problems on a SonarQube Server with multiple C++ plugins, the CXX programming language sensor is disabled by default.

sonar-project.properties sample:

# default: the cxx plugin language sensor is disabled
sonar.cxx.file.suffixes=-

This configuration parameter must therefore be set explicitly to use the CXX programming language sensor. The recommended settings are:

programming language recomended file suffixes
C++ .cc,.cpp,.cxx,.c++,.hh,.hpp,.hxx,.h++,.ipp
C .c,.h
CXX (v1.x) .cxx,.cpp,.cc,.c,.hxx,.hpp,.hh,.h

Sample to be cxx plugin version 1.x compatible (sonar-project.properties):

# mandatory parameter: files to be handled by the cxx plugin
sonar.cxx.file.suffixes=.cxx,.cpp,.cc,.c,.hxx,.hpp,.hh,.h

In the SonarQube UI, enter the file suffixes into the fields one by one.

Scan Source Code

The SonarCFamily for C/C++ is using the analysis parameter sonar.c.file.suffixes for C, sonar.cpp.file.suffixes for C++ and sonar.objc.file.suffixes for Objective-C. If you don't want to analyze C/C++/Objective-C files with the SonarCFamily plugin, then prevent them from being analyzed by setting the following properties:

sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

Understanding the scanner .LOG file

The listing below shows an example of the contents of a scanner .LOG file and describes the specific steps. In order to get all required information, the debug information should be switched on during scanning.

Look for the entry sonar.lang.patterns.cxx in the .LOG file. This should be a comma-separated list with one entry in the form .xxx => **/*.xxx for each file extension.

15 DEBUG: Available languages:
16 DEBUG:   * CXX => "cxx"
17 DEBUG: Declared extensions of language CXX were converted to sonar.lang.patterns.cxx : **/*.cxx,**/*.cpp,**/*.cc,**/*.c,**/*.hxx,**/*.hpp,**/*.hh,**/*.h

If the configuration is correct, all files with the corresponding file extensions are then assigned to the programming language cxx in the step Indexing files.

19 INFO: Indexing files...
20 INFO: Project configuration:
21 DEBUG: 'src/component1.hh' indexed with language 'cxx'
22 DEBUG: 'src/component1.cc' indexed with language 'cxx'
23 DEBUG: 'src/main.cc' indexed with language 'cxx'
24 INFO: 3 files indexed

If a file extension is assigned to more than one language (or plugin), you will get an error message like below:

30 ERROR: Language of file 'sample.cpp' can not be decided as the file matches patterns of both sonar.lang.patterns.cxx : ... and sonar.lang.patterns.cpp : ...
Clone this wiki locally