Sonar on AWS
Contents
About
Sonar (originally an acronym for SOund Navigation And Ranging) is a technique that uses sound propagation (usually underwater, as in submarine navigation) to navigate, communicate with or detect objects on or under the surface of the water, such as other vessels.
Sonar is an open source software quality platform. Sonar uses various static code analysis tools such as Checkstyle, PMD, FindBugs to extract software metrics, which then can be used to improve software quality. It runs as a stand-alone web server that new code can be pushed to via a Maven command. It also stores a history of previous builds in an in-memory or MySQL database.
Features
- All projects at a glance
- Drill down to source code
- Coding rules
- Unit tests
- Standard metrics
- Time machine (i.e. history)
- Maven ready
- Easy
- Leverage existing components
- Plugins
- Security
- Single source of truth for rules
- Exporable to local IDEs
Details
| AWS Region | Sydney |
| Instance Name | sonar |
| Instance ID | i-c82837f2 |
| Instance Type | m1.micro |
| Public DNS | ec2-54-253-27-220.ap-southeast-2.compute.amazonaws.com |
| Security Group | sonar (all 22, 8080, 9000 and 9092) |
| Key Pair |
sonar-key (sonar-private.ppk)
|
| Key Pair Passphrase | |
| Sonar Database |
MySQL DB (ec2-54-253-27-220.ap-southeast-2.compute.amazonaws.com:3036) / In-memory H2
sonar / sonar / root /
|
| Sonar Dashboard |
username: admin
password: admin |
| Stop/Start Sonar |
/etc/init.d/sonar stop
/etc/init.d/sonar start
|
| Sonar Logs | /opt/sonar/logs/ |
| Sonar Conf | /opt/sonar/conf/sonar.properties |
ec2-54-253-27-220.ap-southeast-2.compute.amazonaws.com
Installing
- Spin up an EC2 instance on AWS
- Make sure to link a security group and give port/ip access on it. (9000 and 9002 would suffice or give ALL)
- Connect to the Instance using putty and issue the following commands:
Maven
Sonar maven plugin operates as a very light bootstrap mechanism whose only responsibility is to download all the business logic to the Sonar web server and execute it.
A Sonar web server embeds a Maven repository which exposes to the Maven plugin all the business logic. Below is a simple diagram to better understand the mechanism : (http://www.sonarsource.org/we-had-a-dream-mvn-sonarsonar/)
Follow these steps to push code to the remote Sonar server:
- Open a command prompt
- Navigate to the project folder containing a pom.xml (e.g. c:\workspace\phoenix-source\finance-service)
- Execute the following Maven goal: (When running the h2 database)
Maven Configuration for My SQL Database
This settings should be done on the settings.xml make sure maven uses this file or include it in the path as follows,
When running on the MySql database execute the following maven goal :
Issues and Solutions
- On Enabling all rules on sonar server and executing the maven goal sonar:sonar there is a build failure as follows,
Reason: You cannot turn on all the rules as some of them require some settings to be working.
The following rules need to be disabled in sonar server,
- Avoid too deep inheritenace tree
- Header
- Regexp
- Regexp Header
- Regexp Multiline
- Regexp SingleLine
- Regexp SingleLine Java
- XPath rule template
MySQL
Instructions for installing a local MySQL database for Sonar.
Edit conf/sonar.properties to configure database - ( /opt/sonar/conf/sonar.properties )
Uncomment MySql settings and comment in memory db settings
Some useful commands on linux
ps aux | grep mysql
ps aux | grep sonar
ps aux | grep sonar

Comments
Post a Comment