Category: Importer (takes in SonarQube Instance and outputs cc.json)

The Sonar-Importer generates visualisation data from SonarQube data through an API call to a SonarQube server. This requires that the SonarQube instance is running.

Supported Languages

  • All languages that are supported by SonarQube. A full list can be found here.

Supported Metrics

  • All metrics that are generated by SonarQube. A full list can be found here.

Usage and Parameters

Parameter Description
URL url of sonarqube server
PROJECT_ID sonarqube project id
-h, --help Please locate:
- sonar.host.url (e.g. https://sonar.foo)
- sonar.login (e.g. c123d456)
- sonar.projectKey (e.g. de.foo:bar)
That you use to upload your code to sonar.
Then execute ccsh sonarimport https://sonar.foo de.foo:<br/> bar -u c123d456
-m, --metrics=<metrics> comma-separated list of metrics to import
--merge-modules merges modules in multi-module projects
-nc, --not-compressed save uncompressed output File
-o, --output-file=<outputFile> output File
-u, --user-token=<userToken> user token for connecting to remote sonar instance
Usage: ccsh sonarimport [-h] [--merge-modules] [-nc] [-o=<outputFile>]
                        [-u=<userToken>] [-m=<metrics>]... URL PROJECT_ID

Examples

ccsh sonarimport <url> <projectKey> --user-token=<userToken> --output-file=<fileName> --merge-modules=<Boolean>

If you use SonarQube locally, an example command would look like the following:

ccsh sonarimport "http://localhost:9000/" "CodeCharta" "--user-token=squ_12345" "--output-file=output" "--merge-modules=false"

If a project is piped into the SonarImporter, the results and the piped project are merged. The resulting project has the project name specified for the SonarImporter.

CodeCharta can import project metrics from SonarQube. SonarQube can generate a wide variety of project metrics for a variety of languages. It can be used for a local analysis, or it can be added to the build pipeline. In the following the installation and usage of a local sonar server is described.

Run SonarQube Server locally

From the zip file

see also SonarQube Docs

  1. Download the latest version of SonarQube
  2. Unzip the archive (use the chosen location for the next step)
  3. Start the Sonar Server with C:\sonarqube\bin\windows-x86-xx\StartSonar.bat on Windows or /opt/sonarqube/bin/[OS]/sonar.sh on Linux/MacOS
  4. Open localhost:9000 in your browser and log in with
    • login: admin
    • password: admin

Install SonarScanner

  1. Download the latest version of SonarScanner
  2. Unzip the archive
  3. Add the bin directory to the %PATH%(Windows) or PATH(Linux/MacOS) environment variable

From the Docker image

You can also run SonarQube with Docker, for further information read here.

  1. Download and install Docker Desktop if not already present on your system
  2. Download the latest version of SonarQube Docker Image
  3. Start the Sonar Server with the following command:

    $ docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest

  4. Open localhost:9000 in your browser and log in with
    • login: admin
    • password: admin

Install SonarScanner CLI

Also see for detailed instructions here.

  1. Download the latest version of SonarScanner CLI
  2. Add a sonar-project.properties file to your project’s root directory

Analyze project

After you installed SonarQube do the following steps to analyze your Project:

  1. Click on the plus icon to create a new project
  2. Specify the project key and display name
  3. Click the respective button to generate a token
  4. Specify the main language for the project
  5. Follow the instructions from SonarQube

When using SonarQube version >= 9.5, you need to create a user token. In your account settings select the security settings.

![Generate user token]-(/assets/images/docs/how-to/generate_user_token.png)

For further information read here

Extract project metrics from Sonar Server

To visualize your project metrics created by Sonar use CodeCharta’s sonar importer. to generate a cc.json file.

Beginner’s Guide for using SonarQube

If you are totally new to SonarQube, you are welcome to read more detailed instructions here.

Updated: