Skip to content

sonar.cxx.xslt

Günter Wirth edited this page Jun 15, 2021 · 6 revisions

Overview

The cxx plugin has a built-in XLS transformation. This is especially handy when XML data needs to be converted before being read in with the plugin. It is ensured that the XLST sensor is executed before the report sensors.

Configure cxx plugin

The XSLT processor takes one or more XML source documents (.inputs), plus one XSLT stylesheet (.stylesheet), and processes them to produce one or more output documents (.outputs). The original document is not changed; rather, a new document is created based on the content of an existing one.

parameter description
.stylesheet predefined or external stylesheet for the XSL transformation
.inputs XML data to be converted:
- single file or path with wildchards
- multiple paths may be comma-delimited
- supporting absolute or relative paths
.outputs Filename for output. If * is included as wildchard, * will be replaced by the current filename of .inputs (without file extension). The file path is always taken from .inputs.

Further notes:

  • In order to configure multiple transformations, an index must also be specified. 10 stylesheets with index 1 to 10 are supported. The indices must be consecutive and are executed in ascending order.
  • Paths may be absolute or relative to the project base directory.

The example shows the simplest case, here the file C:\MyProject\input.xml is transformed with C:\MyProject\stylesheet.xlst and the result is saved in C:\MyProject\output.xml.

sonar.cxx.xslt.1.stylesheet=C:/MyProject/stylesheet.xlst
sonar.cxx.xslt.1.inputs=C:/MyProject/input.xml
sonar.cxx.xslt.1.outputs=output.xml

As with Report Paths, wildcards can be used for the .inputs parameter. The .ouputs parameter must then have a * as wildcard, which is replaced with the current input file name (without file extension). In the example the file C:\MyProject\input-001.xml would be transformed to C:\MyProject\output-input-001.xml.

sonar.cxx.xslt.1.stylesheet=C:/MyProject/stylesheet.xlst
sonar.cxx.xslt.1.inputs=C:/MyProject/input-???.xml
sonar.cxx.xslt.1.outputs=output-*.xml

It is also possible to define multiple input paths. .outputs is always only a single entry with wildcard. In the example the files C:\MyProject\A-001.xml and C:\MyProject\BFile.xml would be transformed to C:\MyProject\output-A-001.xml and C:\MyProject\output-BFile.xml.

sonar.cxx.xslt.1.stylesheet=C:/MyProject/stylesheet.xlst
sonar.cxx.xslt.1.inputs=C:/MyProject/A-???.xml,C:/MyProject/B*.xml
sonar.cxx.xslt.1.outputs=output-*.xml

If several transformations are to be performed, they are configured with different indices. The indices must be consecutive and are executed in ascending order. This also allows several transformations to be performed in cascade.

sonar.cxx.xslt.1.stylesheet=stylesheet_1.xlst
sonar.cxx.xslt.1.inputs=...
sonar.cxx.xslt.1.outputs=...
sonar.cxx.xslt.2.stylesheet=stylesheet_2.xlst
sonar.cxx.xslt.2.inputs=...
sonar.cxx.xslt.2.outputs=...

Migrate sonar.cxx.xunit.xsltURL

The example below shows how to migrate an XLS transformation from the cxx plugin 1.3. Previously the file sonar.cxx.xunit.reportPath was read in and if the parameter sonar.cxx.xunit.xsltURL was set, it was transformed into a file with the same name and the file extension .after_xlst. This file was then processed by the sensor:

sonar.cxx.xunit.xsltURL=boosttest-1.x-to-junit-1.0.xsl
sonar.cxx.xunit.reportPath=reports/*test.xml

As of the version 2, the corresponding solution looks like this:

sonar.cxx.xslt.1.stylesheet=boosttest-1.x-to-junit-1.0.xsl
sonar.cxx.xslt.1.inputs=reports/*test.xml
sonar.cxx.xslt.1.outputs=*.after_xlst
sonar.cxx.xunit.reportPath=reports/*test.after_xlst

Predefined XLS transformations

For some file formats the cxx plugin already includes predefined XLS transformations. The predefined XLST are defined without specifying a path under .stylesheet.

.stylesheet description
boosttest-1.x-to-junit-1.0.xsl For transforming Boost.Test reports to read in with sonar.cxx.xunit.reportPaths.
cpptestunit-1.x-to-junit-1.0.xsl For transforming CppTest reports to read in with sonar.cxx.xunit.reportPaths.
cppunit-1.x-to-junit-1.0.xsl For transforming CppUnit reports to read in with sonar.cxx.xunit.reportPaths.
Clone this wiki locally