Thursday, February 1, 2018

How to Quickly Get Started with Sonar - DZone Agile

How to Quickly Get Started with Sonar
by Ajitesh Kumar  · Sep. 15, 14 · Agile Zone
See how three solutions work together to help your teams have the tools they need to deliver
quality software quickly. Brought to you in partnership with CA Technologies.
This article represents steps required to quickly get up and running with Sonar and keep it handy for your
personal Java/.NET/PHP etc related projects. Please feel free to comment/suggest if I missed to mention
one or more important points. Also, sorry for the typos.
Following are the key points described later in this article:
Sonar setup instructions
Configure HelloWorld Project for Code Analysis
Sonar setup instructions
Following are two key aspects of getting Sonar and dependencies installed, configured and setup for usage.
Installation of SonarQube
Installation of Code Analyzer
Installation of SonarQube
Following is instructionset
to get setup with SonarQube:
Go to Sonar community edition page and download.
Unzip the downloaded file
Go to <install_directory>/bin folder. You would find different folders related with OS platforms. As I
have 64 bit Win system, I further went inside “windowsx8664″
folder.
You shall find different shell scripts files. For my win platform, I found different *.bat file such as
InstallNTService.bat, StartNTService.bat, StartSonar.bat etc.
Copy the path of this folder which may look like S<install_director>/bin/Windowsx8664
(in case
of my laptop), and append it to “Path” environment variable.
Open a command prompt, type “StartSonar” command and execute. This would start a web server at
default port of 9000.
Open a web browser and access the page, http://localhost:9000. You shall see the page such as that
4/21/2017 How to Quickly Get Started with Sonar DZone
Agile
https://dzone.com/articles/howquicklygetstartedsonar
2/7
shown in the screenshot below. This means that you have been able to successfully start your
SonarQube server. Job, well done! Lets move further to analyze out HelloWorld project. I coded a
HelloWorld Java project using Eclipse IDE.
Sonar comes with an embedded H2 database, by default. For quick setup and testing purpose, you
may live with embedded database. However, for production and real usage, one may want to use
productionread
databases such as MySQL, Oracle etc. For configuration instructions, edit
<install_directory>/conf/sonar.properties to configure the database settings. Templates are
available for every supported database. Just uncomment and configure the template you need and
comment out the lines dedicated to H2 database.
Installation of Code Analyzer
Following is instructionset
to get setup with Code Analyzer (SonarQube Runner). The SonarQube Runner
is recommended as the default launcher to analyze a project with SonarQube.
Goto Installing & configuring Sonar Runner page and download the sonarrunnerdistversionno.
zip file
Unzip the file to appropriate location
Setup the SONAR_RUNNER_HOME environment variable and assign it to SonarRunner
installation directory
Add the <sonarrunner_install_directory>/bin directory to your path.
Check the basic installation by opening a new shell and executing the command sonarrunner
h
(on
Windows platform the command is sonarrunner.
bat h).
If above get executed, you are all set to analyze your first project with SonarQube runner.
Analysis of HelloWorld Java Project
Create a configuration file in the root directory of the project, namely, sonarproject.
properties
You may choose to copy and paste the code given on this page, Analyzing with SonarQube Runner, in
sonarproject.
properties file. For setup purpose, just change the value of sonar.projectName to the
project name you created.
4/21/2017 How to Quickly Get Started with Sonar DZone
Agile
https://dzone.com/articles/howquicklygetstartedsonar
3/7
Open a command prompt, and go to project root folder.
Execute “sonarrunner”
command to run the analysis. You would see the analysis run.
Goto the browser and access the page, http://localhost:9000
You would find your project listed under “PROJECTS”. Click on your project listing and you would
land up on the project dashboard.
That is it!




No comments:

Post a Comment

Recent Post

Databricks Delta table merge Example

here's some sample code that demonstrates a merge operation on a Delta table using PySpark:   from pyspark.sql import SparkSession # cre...