Friday 15 July 2016

SonarQube4.0 with MS-SQL

Step by Step approach


Introduction to SonarQube

SonarQube is an open platform to manage code quality.

We are concentrating on Version 4.0, therefore
Download the SonarQube 4.0 and Sonar runner under related tools from the mentioned below URL
Unzip after download complete.
It requires JDK >6 to be installed.

Here, we have used SonarQube 4.0, Sonar-Runner 2.3 and JDK 7.

Steps to start scanning

           Open environment variable                                                                                    




         Create environment variables





  •     CLASSPATH                                                                                                              






  •  JAVA_HOME
  • SONAR_RUNNER_HOME
                                           


    1.       Update environment variable

    •         Path

    a

    MS-SQL requisites 

    Create empty database with name Sonar
    Create new login for SONAR to use the Database

    Create UserMapping  for Sonar database as db_owner


    Grant status

    After creation of Login, Verify the jdbc driver in SonarQube 4.0 unzip in the below mentioned path




    1.       Open sonarqube-4.0 > conf folder and open sonar (properties file)

    By default , sonar uses H2 database

    Note:- # in conf file means comment. Remove # to change (uncomment) the configuration.

    Open conf file ,  change username and password to sonar
    sonar.jdbc.username=sonar
    sonar.jdbc.password=sonar

    Go to MS-SQL section and change the connection URL and driverClassName

    #----- Microsoft SQLServer
    # The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details on http://jtds.sourceforge.net
    sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/Sonar;instance=SQLEXPRESS;SelectMethod=Cursor
    sonar.jdbc.driverClassName: net.sourceforge.jtds.jdbc.Driver
    sonar.jdbc.validationQuery: select 1

    Open sonar-runner x.x > conf > sonar-runner (properties file)
    Change the 
    #----- Microsoft SQLServer 
    sonar.jdbc.url= jdbc:jtds:sqlserver://localhost/Sonar;instance=SQLEXPRESS;SelectMethod=Cursor
    sonar.jdbc.driverClassName: net.sourceforge.jtds.jdbc.Driver

    #----- Global database settings
    sonar.jdbc.username= sonar
    sonar.jdbc.password= sonar

    After, database settings 
    Open command prompt (cmd) , move to the directory of sonar and execute startsonar.bat file




    After successful start you’ll get below shown screen

    Open browser and type URL http://localhost:9000/ 



    This shows the sonar is installed and running successfully. Next, download the file from below mentioned URL
    https://raw.githubusercontent.com/SonarSource/sonar-examples/master/projects/languages/java/sonar-runner/java-sonar-runner-simple/sonar-project.properties 

    But, during saving this doc. save it as .properties not as, txt 

    Go to, browser and login with default user credentials usn and pwd as admin. 
    Click settings
    Click update center
    Select available plugin and search for C# and download it.
    Copy the file and paste it to the folder \sonarqube-4.0\extensions\plugins.
    Logout and again Login from browser.
    The new plugin will present in the installed plugins.

    Copy the sonar-project.properties file and paste into the solution folder which requires to test code quality.
    Open the file. It requires some changes
    By default, the properties file will be having 



    Since we are using C# language set 
    sonar. Language = cs

    Open Command prompt. Change directory to the project location i.e., where the sonar-project.properties is located.
    Type sonar-runner.bat

    It starts processing of each and every code of line based on the rules insisted in database dbo.rules table.

    After successful execution , prompts as below shown image



    The step by step approach for using Sonar Qube 4.0 for .Net application with MS-SQL was documented for the current project quality maintenance.

    Please, guide me if something you feel is not right in the Post.