hygieia / hygieia-codequality-sonar-collector

Hygieia Collector for Sonar versions 5.x to 8.x

Home Page:https://github.com/Hygieia/Hygieia/blob/gh-pages/pages/hygieia/collectors/build/sonar.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Due to changes in the priorities, this project is currently not being supported. The project is archived as of 6/1/2023 and will be available in a read-only state. Please note, since archival, the project is not maintained or reviewed

Hygieia Collector to collect static code analysis data from Sonar

Build Status Quality Gate Status Total alerts Language grade: Java Maven Central License Gitter Chat

Configure the Sonar Collector to display and analyze information (related to code quality) on the Hygieia Dashboard, from SonarQube (formerly known as Sonar). Hygieia uses Spring Boot to package the collector as an executable JAR file with dependencies.

Table of Contents

Setup Instructions

To configure the Sonar Collector, execute the following steps:

  • Step 1 - Artifact Preparation:

    Please review the two options in Step 1 to find the best fit for you.

    Option 1 - Download the artifact:

    You can download the SNAPSHOTs from the SNAPSHOT directory here or from the maven central repository here.

    Option 2 - Build locally:

    To configure the Sonar Collector, git clone the sonar collector repo. Then, execute the following steps:

    To package the sonar collector source code into an executable JAR file, run the maven build from the \hygieia-codequality-sonar-collector directory of your source code installation:

    mvn install

    The output file [collector name].jar is generated in the hygieia-codequality-sonar-collector\target folder.

    Once you have chosen an option in Step 1, please proceed:

  • Step 2: Set Parameters in the Application Properties File

    Set the configurable parameters in the application.properties file to connect to the Dashboard MongoDB database instance, including properties required by the Sonar Collector. To configure the parameters, refer to the application properties section.

    For more information about the server configuration, see the Spring Boot documentation.

  • Step 3: Deploy the Executable File

    To run the [collector name].jar file, change directory to 'hygieia-codequality-sonar-collector\target' and then execute the following command from the command prompt:

    java -jar [collector name].jar --spring.config.name=sonar --spring.config.location=[path to application.properties file]

Sample Application Properties File

The sample application.properties file lists parameters with sample values to configure the Sonar Collector. Set the parameters based on your environment setup.

		# Database Name
		dbname=dashboarddb

		# Database HostName - default is localhost
		dbhost=10.0.1.1

		# Database Port - default is 27017
		dbport=27017

		# MongoDB replicaset
		dbreplicaset=[false if you are not using MongoDB replicaset]
		dbhostport=[host1:port1,host2:port2,host3:port3]

		# Database Username - default is blank
		dbusername=dashboarduser

		# Database Password - default is blank
		dbpassword=dbpassword

		# Collector schedule (required)
		sonar.cron=0 0/5 * * * *

		# Sonar server(s) (required) - Can provide multiple
		sonar.servers[0]=http://sonar.company.com
		
		# Sonar version, match array index to the server. If not set, will default to version prior to 6.3.
		sonar.versions[0]=6.31
		
		# Sonar Metrics - Required. 
		#Sonar versions lesser than 6.3
		
		# Sonar tokens to connect to authenticated url 
		sonar.tokens[0]=<api token>
		sonar.metrics[0]=ncloc,line_coverage,violations,critical_violations,major_violations,blocker_violations,violations_density,sqale_index,test_success_density,test_failures,test_errors,tests
		
		# For Sonar version 6.3 and above
		sonar.metrics[0]=ncloc,violations,new_vulnerabilities,critical_violations,major_violations,blocker_violations,tests,test_success_density,test_errors,test_failures,coverage,line_coverage,sqale_index,alert_status,quality_gate_details
		
		# Sonar login credentials
		# Format: username1,username2,username3,etc.
		sonar.usernames= 
		# Format: password1,password2,password3,etc.
                sonar.passwords=

Run collector with Docker

You can install Hygieia by using a docker image from docker hub. This section gives detailed instructions on how to download and run with Docker.

  • Step 1: Download

    Navigate to the docker hub location of your collector here and download the latest image (most recent version is preferred). Tags can also be used, if needed.

  • Step 2: Run with Docker

    Docker run -e SKIP_PROPERTIES_BUILDER=true -v properties_location:/hygieia/config image_name

    • -e SKIP_PROPERTIES_BUILDER=true
      indicates whether you want to supply a properties file for the java application. If false/omitted, the script will build a properties file with default values
    • -v properties_location:/hygieia/config
      if you want to use your own properties file that located outside of docker container, supply the path here.
      • Example: -v /Home/User/Document/application.properties:/hygieia/config

About

Hygieia Collector for Sonar versions 5.x to 8.x

https://github.com/Hygieia/Hygieia/blob/gh-pages/pages/hygieia/collectors/build/sonar.md

License:Apache License 2.0


Languages

Language:Java 98.3%Language:Shell 1.3%Language:Dockerfile 0.3%