Installation & Start
- Download the .zip file.
- Unzip in a local directory (for example: C:\Temp\Sonar)
- Go in the \bin directory and select the subdirectory corresponding to your operating system (for example: C:\Temp\Sonar\bin\windows-x86-32)
- Double-click on StartSonar.
Configuration
- Open http://localhost:9000
- Login as administrator (login: admin, password: admin)
- Click on Configuration
- Select Sonar way with Findbugs as default
Usage
The following code sample is available on Github, in the Sonar-Example directory:public class Sonar { public static class A { public void print() { System.out.println("Hello Word !"); } } public static void main(String[] args) throws IOException { printMessage(null); } public static void printMessage(A a) { // Not testing for nullity a.print(); } }
<dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar</artifactId> <version>3.1.1</version> <type>pom</type> </dependency>
- Run the sonar:sonar maven goal on the project.
- Go back to http://localhost:9000
- Click on Home.
- Select Sonar-Example. Notice the errors and warnings reported by Sonar.
- Click on Critical.
- Click on the Sonar link (with a text icon)
Sonar has detected the suspicious null method call. This is a tiny example of what Sonar can do for you. You can configure it to use FindBugs and PMD too. Sonar is also an excellent opportunity to learn about your coding errors. It improves your style.
No comments:
Post a Comment